forked from raystack/frontier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: logs activity of shield entities (#37)
- Loading branch information
1 parent
81b8706
commit 2e11f66
Showing
56 changed files
with
1,354 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package activity | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/goto/salt/audit" | ||
) | ||
|
||
type Repository interface { | ||
Insert(ctx context.Context, log *audit.Log) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package activity | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrInvalidUUID = errors.New("invalid syntax of uuid") | ||
ErrInvalidData = errors.New("invalid log data") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package activity | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/goto/salt/audit" | ||
"github.com/goto/shield/config" | ||
"github.com/mitchellh/mapstructure" | ||
) | ||
|
||
type Service struct { | ||
repository Repository | ||
} | ||
|
||
func NewService(repository Repository) *Service { | ||
return &Service{ | ||
repository: repository, | ||
} | ||
} | ||
|
||
func (s Service) Log(ctx context.Context, action string, actor string, data any) error { | ||
if data == nil { | ||
return ErrInvalidData | ||
} | ||
|
||
var logDataMap map[string]interface{} | ||
if err := mapstructure.Decode(data, &logDataMap); err != nil { | ||
return err | ||
} | ||
|
||
metadata := map[string]string{ | ||
"app_name": "shield", | ||
"app_version": config.Version, | ||
} | ||
|
||
log := &audit.Log{ | ||
Timestamp: time.Now(), | ||
Action: action, | ||
Data: logDataMap, | ||
Actor: actor, | ||
Metadata: metadata, | ||
} | ||
|
||
return s.repository.Insert(ctx, log) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.