improve audit logs (#2242)

* improve audit logs
unified-ui
Enver Biševac 2024-07-18 12:15:31 +00:00 committed by Harness
parent dfb69afade
commit da44afe021
6 changed files with 26 additions and 7 deletions

View File

@ -103,7 +103,7 @@ func (c *Controller) UpdateDefaultBranch(
err = c.auditService.Log(ctx,
session.Principal,
audit.NewResource(audit.ResourceTypeRepository, repo.Identifier),
audit.NewResource(audit.ResourceTypeRepositorySettings, repo.Identifier),
audit.ActionUpdated,
paths.Parent(repo.Path),
audit.WithOldObject(audit.RepositoryObject{

View File

@ -118,7 +118,7 @@ func (c *Controller) RuleCreate(ctx context.Context,
err = c.auditService.Log(ctx,
session.Principal,
audit.NewResource(audit.ResourceTypeBranchRule, r.Identifier),
audit.NewResource(audit.ResourceTypeBranchRule, r.Identifier, audit.RepoName, repo.Identifier),
audit.ActionCreated,
paths.Parent(repo.Path),
audit.WithNewObject(r),

View File

@ -49,7 +49,7 @@ func (c *Controller) RuleDelete(ctx context.Context,
err = c.auditService.Log(ctx,
session.Principal,
audit.NewResource(audit.ResourceTypeBranchRule, r.Identifier),
audit.NewResource(audit.ResourceTypeBranchRule, r.Identifier, audit.RepoName, repo.Identifier),
audit.ActionDeleted,
paths.Parent(repo.Path),
audit.WithOldObject(r),

View File

@ -140,7 +140,7 @@ func (c *Controller) RuleUpdate(ctx context.Context,
err = c.auditService.Log(ctx,
session.Principal,
audit.NewResource(audit.ResourceTypeBranchRule, r.Identifier),
audit.NewResource(audit.ResourceTypeBranchRule, r.Identifier, audit.RepoName, repo.Identifier),
audit.ActionUpdated,
paths.Parent(repo.Path),
audit.WithOldObject(oldRule),

View File

@ -73,7 +73,7 @@ func (c *Controller) Update(ctx context.Context,
err = c.auditService.Log(ctx,
session.Principal,
audit.NewResource(audit.ResourceTypeRepository, repo.Identifier),
audit.NewResource(audit.ResourceTypeRepositorySettings, repo.Identifier),
audit.ActionUpdated,
paths.Parent(repo.Path),
audit.WithOldObject(repoClone),

View File

@ -30,6 +30,10 @@ var (
ErrSpacePathIsRequired = errors.New("space path is required")
)
const (
RepoName = "repoName"
)
type Action string
const (
@ -69,13 +73,20 @@ func (a ResourceType) Validate() error {
type Resource struct {
Type ResourceType
Identifier string
Data map[string]string
}
func NewResource(rtype ResourceType, identifier string) Resource {
return Resource{
func NewResource(rtype ResourceType, identifier string, keyValues ...string) Resource {
r := Resource{
Type: rtype,
Identifier: identifier,
Data: make(map[string]string, len(keyValues)),
}
for i := 0; i < len(keyValues); i += 2 {
k, v := keyValues[i], keyValues[i+1]
r.Data[k] = v
}
return r
}
func (r Resource) Validate() error {
@ -88,6 +99,14 @@ func (r Resource) Validate() error {
return nil
}
func (r Resource) DataAsSlice() []string {
slice := make([]string, 0, len(r.Data)*2)
for k, v := range r.Data {
slice = append(slice, k, v)
}
return slice
}
type DiffObject struct {
OldObject any
NewObject any