CLI: Add audit logs to cluster management commands

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-10-20 14:49:25 +02:00
parent 252aff2a6b
commit c5b5feee47
7 changed files with 127 additions and 0 deletions

View File

@@ -8,7 +8,11 @@ import (
"net/url"
"strings"
"github.com/urfave/cli/v2"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/service/cluster"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/http/header"
)
@@ -53,3 +57,23 @@ func obtainClientCredentialsViaRegister(portalURL, joinToken, nodeName string) (
}
return id, secret, nil
}
// clusterAuditWho builds the leading audit log segments for CLI commands.
func clusterAuditWho(ctx *cli.Context, conf *config.Config) []string {
actor := clean.Log(conf.NodeName())
if actor == "" {
actor = clean.Log(conf.SiteUrl())
}
if actor == "" {
actor = "cli"
}
context := "cli"
if ctx != nil && ctx.Command != nil {
if full := strings.TrimSpace(ctx.Command.FullName()); full != "" {
context = "cli " + full
}
}
return []string{actor, context}
}