From 53dcd93818894afe146e1136380fada33c878312 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 19 Jun 2023 07:29:04 +0200 Subject: [PATCH] add storage id to audit log for spaces Signed-off-by: Christian Richter --- .../unreleased/add-storage-id-to-audit-log.md | 6 +++++ services/audit/pkg/types/helpers.go | 8 ++++++ .../pkg/types/{constants.go => messages.go} | 26 ++++++++++++------- 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 changelog/unreleased/add-storage-id-to-audit-log.md create mode 100644 services/audit/pkg/types/helpers.go rename services/audit/pkg/types/{constants.go => messages.go} (89%) diff --git a/changelog/unreleased/add-storage-id-to-audit-log.md b/changelog/unreleased/add-storage-id-to-audit-log.md new file mode 100644 index 000000000..dd9eb887a --- /dev/null +++ b/changelog/unreleased/add-storage-id-to-audit-log.md @@ -0,0 +1,6 @@ +Enhancement: We added the storage id to the audit log for spaces + +We added the storage id to the audit log for spaces + +https://github.com/owncloud/ocis/pull/6548 +https://github.com/owncloud/ocis/issues/3753 \ No newline at end of file diff --git a/services/audit/pkg/types/helpers.go b/services/audit/pkg/types/helpers.go new file mode 100644 index 000000000..f1aad6383 --- /dev/null +++ b/services/audit/pkg/types/helpers.go @@ -0,0 +1,8 @@ +package types + +import "strings" + +func SplitId(id string) (string, string) { + ids := strings.Split(id, "$") + return ids[0], ids[1] +} diff --git a/services/audit/pkg/types/constants.go b/services/audit/pkg/types/messages.go similarity index 89% rename from services/audit/pkg/types/constants.go rename to services/audit/pkg/types/messages.go index e41f53ba6..8ef8e3fe7 100644 --- a/services/audit/pkg/types/constants.go +++ b/services/audit/pkg/types/messages.go @@ -139,43 +139,51 @@ func MessageFileVersionRestored(executant, item, version string) string { // MessageSpaceCreated returns the human readable string that describes the action func MessageSpaceCreated(executant, spaceID, name string) string { - return fmt.Sprintf("user '%s' created a space '%s' with name '%s'", executant, spaceID, name) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' created a space '%s' with name '%s' (storage: '%s')", executant, spaceID, name, storagId) } // MessageSpaceRenamed returns the human readable string that describes the action func MessageSpaceRenamed(executant, spaceID, name string) string { - return fmt.Sprintf("user '%s' renamed space '%s' to '%s'", executant, spaceID, name) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' renamed space '%s' to '%s' (storage: '%s')", executant, spaceID, name, storagId) } // MessageSpaceDisabled returns the human readable string that describes the action func MessageSpaceDisabled(executant, spaceID string) string { - return fmt.Sprintf("user '%s' disabled the space '%s'", executant, spaceID) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' disabled the space '%s' (storage: '%s')", executant, spaceID, storagId) } // MessageSpaceEnabled returns the human readable string that describes the action func MessageSpaceEnabled(executant, spaceID string) string { - return fmt.Sprintf("user '%s' (re-) enabled the space '%s'", executant, spaceID) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' (re-) enabled the space '%s' (storage: '%s')", executant, spaceID, storagId) } // MessageSpaceDeleted returns the human readable string that describes the action func MessageSpaceDeleted(executant, spaceID string) string { - return fmt.Sprintf("user '%s' deleted the space '%s'", executant, spaceID) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' deleted the space '%s' (storage: '%s')", executant, spaceID, storagId) } // MessageSpaceShared returns the human readable string that describes the action func MessageSpaceShared(executant, spaceID, grantee string) string { - return fmt.Sprintf("user '%s' shared the space '%s' with '%s'", executant, spaceID, grantee) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' shared the space '%s' with '%s' (storage: '%s')", executant, spaceID, grantee, storagId) } // MessageSpaceUnshared returns the human readable string that describes the action func MessageSpaceUnshared(executant, spaceID, grantee string) string { - return fmt.Sprintf("user '%s' unshared the space '%s' with '%s'", executant, spaceID, grantee) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' unshared the space '%s' with '%s' (storage: '%s')", executant, spaceID, grantee, storagId) } // MessageSpaceUpdated returns the human readable string that describes the action func MessageSpaceUpdated(executant, spaceID, name string, quota uint64, opaque map[string]string) string { - return fmt.Sprintf("user '%s' updated space '%s'. name: '%s', quota: '%d', opaque: '%s'", - executant, spaceID, name, quota, opaque) + storagId, spaceID := SplitId(spaceID) + return fmt.Sprintf("user '%s' updated space '%s'. name: '%s', quota: '%d', opaque: '%s' (storage: '%s')", + executant, spaceID, name, quota, opaque, storagId) } // MessageUserCreated returns the human readable string that describes the action