MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Dispatch

Method Dispatch

app/controlplane/pkg/biz/auditor.go:54–89  ·  view source on GitHub ↗

Dispatch logs an entry to the audit log asynchronously. The actor is resolved from the request context (user, API token or system); the generation and publishing is delegated to the shared auditor.Dispatcher.

(ctx context.Context, entry auditor.LogEntry, orgID *uuid.UUID)

Source from the content-addressed store, hash-verified

52// from the request context (user, API token or system); the generation and
53// publishing is delegated to the shared auditor.Dispatcher.
54func (uc *AuditorUseCase) Dispatch(ctx context.Context, entry auditor.LogEntry, orgID *uuid.UUID) {
55 ctx, span := otelx.Start(ctx, auditorTracer, "AuditorUseCase.Dispatch")
56 defer span.End()
57
58 // dynamically load user information from the context
59 var opts []auditor.GeneratorOption
60 var gotActor bool
61
62 // Determine actor from context
63 switch {
64 case entities.CurrentUser(ctx) != nil:
65 user := entities.CurrentUser(ctx)
66 parsedUUID, _ := uuid.Parse(user.ID)
67 fullName := strings.TrimSpace(fmt.Sprintf("%s %s", user.FirstName, user.LastName))
68 opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, parsedUUID, user.Email, fullName))
69 gotActor = true
70 case entities.CurrentAPIToken(ctx) != nil:
71 apiToken := entities.CurrentAPIToken(ctx)
72 parsedUUID, _ := uuid.Parse(apiToken.ID)
73 opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, parsedUUID, "", apiToken.Name))
74 gotActor = true
75 default:
76 opts = append(opts, auditor.WithActor(auditor.ActorTypeSystem, uuid.Nil, "", ""))
77 }
78
79 if !gotActor && entry.RequiresActor() {
80 uc.log.Warn("failed to get actor information, required by the audit log entry")
81 return
82 }
83
84 if orgID != nil {
85 opts = append(opts, auditor.WithOrgID(*orgID))
86 }
87
88 uc.dispatcher.Dispatch(entry, opts...)
89}

Callers 15

CreateMethod · 0.45
dispatchContractEventMethod · 0.45
DeleteMethod · 0.45
CreateMethod · 0.45
CreateMethod · 0.45
UpdateMethod · 0.45
DeleteMethod · 0.45
CreateMethod · 0.45

Calls 7

StartFunction · 0.92
CurrentUserFunction · 0.92
WithActorFunction · 0.92
CurrentAPITokenFunction · 0.92
WithOrgIDFunction · 0.92
ParseMethod · 0.80
RequiresActorMethod · 0.65

Tested by

no test coverage detected