Skip to content

Commit c2cfac0

Browse files
implemented referer into client audit log metadata
1 parent a4fa7d9 commit c2cfac0

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type AuditLog struct {
141141
type AuditLogMetadata struct {
142142
Hostname string
143143
Hostuser string
144-
Extra map[string]string
144+
Referer string
145145
}
146146

147147
func (a AuditLogMetadata) String() string {

client/testui/client.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/jinzhu/copier"
1717
"github.com/toeirei/keymaster/client"
1818
"github.com/toeirei/keymaster/tags"
19-
"github.com/toeirei/keymaster/ui/tui/util"
2019
"github.com/toeirei/keymaster/util/slicest"
2120
)
2221

@@ -40,11 +39,7 @@ var _ client.Client = (*Client)(nil)
4039

4140
// --- utils ---
4241

43-
func (c *Client) writeAuditLog(
44-
action string,
45-
details string,
46-
extraMetadata *map[string]string,
47-
) error {
42+
func (c *Client) writeAuditLog(action string, details string) error {
4843
hostname, err := os.Hostname()
4944
if err != nil {
5045
return err
@@ -63,7 +58,7 @@ func (c *Client) writeAuditLog(
6358
client.AuditLogMetadata{
6459
hostname,
6560
osuser.Username,
66-
util.DerefOrZeroValue(extraMetadata),
61+
"testui",
6762
},
6863

6964
action,
@@ -137,7 +132,7 @@ func (c *Client) CreatePublicKey(ctx context.Context, key string, comment string
137132
publicKey := client.PublicKey{Id: c.publicKeyIdCounter, Algorithm: algorithm, Data: data, Comment: comment, Tags: tags}
138133
c.publicKeys[publicKey.Id] = publicKey
139134

140-
c.writeAuditLog("public_key.create", fmt.Sprintf("%#v", publicKey), nil)
135+
c.writeAuditLog("public_key.create", fmt.Sprintf("%#v", publicKey))
141136
return publicKey, nil
142137
}
143138

@@ -192,7 +187,7 @@ func (c *Client) UpdateLink(ctx context.Context, id client.LinkId, accountId cli
192187
link.ExpiresAt = expiresAt
193188
c.links[id] = link
194189

195-
c.writeAuditLog("link.update", fmt.Sprintf("%#v", link), nil)
190+
c.writeAuditLog("link.update", fmt.Sprintf("%#v", link))
196191
return link, nil
197192
}
198193
return client.Link{}, fmt.Errorf("account with id %v not found", id)
@@ -204,7 +199,7 @@ func (c *Client) UpdatePublicKey(ctx context.Context, id client.PublicKeyId, com
204199
publicKey.Tags = tags
205200
c.publicKeys[id] = publicKey
206201

207-
c.writeAuditLog("public_key.update", fmt.Sprintf("%#v", publicKey), nil)
202+
c.writeAuditLog("public_key.update", fmt.Sprintf("%#v", publicKey))
208203
return publicKey, nil
209204
}
210205
return client.PublicKey{}, fmt.Errorf("public key with id %v not found", id)
@@ -219,7 +214,7 @@ func (c *Client) DeletePublicKeys(ctx context.Context, ids ...client.PublicKeyId
219214

220215
for _, id := range ids {
221216
delete(c.publicKeys, id)
222-
c.writeAuditLog("public_key.delete", fmt.Sprintf("%#v", id), nil)
217+
c.writeAuditLog("public_key.delete", fmt.Sprintf("%#v", id))
223218
}
224219

225220
return nil
@@ -232,7 +227,7 @@ func (c *Client) CreateAccount(ctx context.Context, username string, host string
232227
account := client.Account{Id: c.accountIdCounter, Username: username, Host: host, Port: port, DeployMethod: deploymentMethod, DeploySecret: deploymentSecret, DeployCache: ""}
233228
c.accounts[account.Id] = account
234229

235-
c.writeAuditLog("account.create", fmt.Sprintf("%#v", account), nil)
230+
c.writeAuditLog("account.create", fmt.Sprintf("%#v", account))
236231
return account, nil
237232
}
238233

@@ -280,7 +275,7 @@ func (c *Client) UpdateAccount(ctx context.Context, id client.AccountId, usernam
280275
account.DeploySecret = deploymentSecret
281276
c.accounts[id] = account
282277

283-
c.writeAuditLog("account.update", fmt.Sprintf("%#v", account), nil)
278+
c.writeAuditLog("account.update", fmt.Sprintf("%#v", account))
284279
return account, nil
285280
}
286281
return client.Account{}, fmt.Errorf("account with id %v not found", id)
@@ -295,7 +290,7 @@ func (c *Client) DeleteAccounts(ctx context.Context, ids ...client.AccountId) er
295290

296291
for _, id := range ids {
297292
delete(c.accounts, id)
298-
c.writeAuditLog("account.delete", fmt.Sprintf("%#v", id), nil)
293+
c.writeAuditLog("account.delete", fmt.Sprintf("%#v", id))
299294
}
300295

301296
return nil
@@ -317,7 +312,7 @@ func (c *Client) CreateLink(ctx context.Context, accountId client.AccountId, tag
317312
link := client.Link{Id: c.linkIdCounter, AccountId: accountId, TagMatcher: tagMatcher, ExpiresAt: expiresAt}
318313
c.links[link.Id] = link
319314

320-
c.writeAuditLog("link.create", fmt.Sprintf("%#v", link), nil)
315+
c.writeAuditLog("link.create", fmt.Sprintf("%#v", link))
321316
return link, nil
322317
}
323318

@@ -365,7 +360,7 @@ func (c *Client) DeleteLinks(ctx context.Context, ids ...client.LinkId) error {
365360

366361
for _, id := range ids {
367362
delete(c.links, id)
368-
c.writeAuditLog("link.delete", fmt.Sprintf("%#v", id), nil)
363+
c.writeAuditLog("link.delete", fmt.Sprintf("%#v", id))
369364
}
370365

371366
return nil
@@ -472,7 +467,7 @@ func (c *Client) DeployAccounts(ctx context.Context, accountIds ...client.Accoun
472467
// simulate deploying data to remote
473468
c.remoteStates[account.Id] = c.accountDeployCache(account, deployDatas[i])
474469

475-
c.writeAuditLog("account.deploy", fmt.Sprintf("%#v", account), nil)
470+
c.writeAuditLog("account.deploy", fmt.Sprintf("%#v", account))
476471

477472
// update accounts deploy cache
478473
_account := c.accounts[account.Id]
@@ -599,7 +594,7 @@ func (c *Client) VerifyAccounts(ctx context.Context, accountIds ...client.Accoun
599594
verifyProgress.Accounts[account.Id].Status = "finished"
600595
}
601596

602-
c.writeAuditLog("account.verify", fmt.Sprintf("%#v", account), nil)
597+
c.writeAuditLog("account.verify", fmt.Sprintf("%#v", account))
603598

604599
verifyProgress.Accounts[account.Id].Progress = 1
605600
verifyProgressChan <- verifyProgress

0 commit comments

Comments
 (0)