handle event container created in audit service

This commit is contained in:
David Christofas
2022-06-09 12:23:34 +02:00
parent 0f61afb596
commit ee184a046f
5 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
Enhancement: Add audit events for created containers
Handle the event `ContainerCreated` in the audit service.
https://github.com/owncloud/ocis/pull/3941

View File

@@ -61,6 +61,8 @@ func StartAuditLogger(ctx context.Context, ch <-chan interface{}, log log.Logger
auditEvent = types.LinkAccessed(ev)
case events.LinkAccessFailed:
auditEvent = types.LinkAccessFailed(ev)
case events.ContainerCreated:
auditEvent = types.ContainerCreated(ev)
case events.FileUploaded:
auditEvent = types.FileUploaded(ev)
case events.FileDownloaded:

View File

@@ -21,6 +21,7 @@ const (
ActionLinkAccessed = "public_link_accessed"
// Files
ActionContainerCreated = "container_create"
ActionFileCreated = "file_create"
ActionFileRead = "file_read"
ActionFileTrashed = "file_delete"
@@ -55,7 +56,7 @@ func MessageShareCreated(sharer, item, grantee string) string {
// MessageLinkCreated returns the human readable string that describes the action
func MessageLinkCreated(sharer, item, shareid string) string {
return fmt.Sprintf("user '%s' created a public to file '%s' with id '%s'", sharer, item, shareid)
return fmt.Sprintf("user '%s' created a public link to file '%s' with id '%s'", sharer, item, shareid)
}
// MessageShareUpdated returns the human readable string that describes the action
@@ -93,6 +94,11 @@ func MessageLinkAccessed(linkid string, success bool) string {
return fmt.Sprintf("link '%s' was accessed. Success: %v", linkid, success)
}
// MessageContainerCreated returns the human readable string that describes the action
func MessageContainerCreated(item string) string {
return fmt.Sprintf("Folder '%s' was created", item)
}
// MessageFileCreated returns the human readable string that describes the action
func MessageFileCreated(item string) string {
return fmt.Sprintf("File '%s' was created", item)

View File

@@ -232,6 +232,15 @@ func FilesAuditEvent(base AuditEvent, itemid, owner, path string) AuditEventFile
}
}
// ContainerCreated converts a ContainerCreated event to an AuditEventContainerCreated
func ContainerCreated(ev events.ContainerCreated) AuditEventContainerCreated {
iid, path, uid := extractFileDetails(ev.Ref, ev.Executant)
base := BasicAuditEvent(uid, "", MessageContainerCreated(iid), ActionContainerCreated)
return AuditEventContainerCreated{
AuditEventFiles: FilesAuditEvent(base, iid, uid, path),
}
}
// FileUploaded converts a FileUploaded event to an AuditEventFileCreated
func FileUploaded(ev events.FileUploaded) AuditEventFileCreated {
iid, path, uid := extractFileDetails(ev.Ref, ev.Owner)

View File

@@ -96,6 +96,11 @@ type AuditEventFiles struct {
FileID string // The newly created files identifier.
}
// AuditEventContainerCreated is the event logged when a container is created
type AuditEventContainerCreated struct {
AuditEventFiles
}
// AuditEventFileCreated is the event logged when a file is created
type AuditEventFileCreated struct {
AuditEventFiles