MCPcopy Index your code
hub / github.com/coder/coder / requireOrgID

Function requireOrgID

coderd/audit/request.go:389–402  ·  view source on GitHub ↗

requireOrgID will either panic (in unit tests) or log an error (in production) if the given resource requires an organization ID and the provided ID is nil.

(ctx context.Context, id uuid.UUID, log slog.Logger)

Source from the content-addressed store, hash-verified

387// requireOrgID will either panic (in unit tests) or log an error (in production)
388// if the given resource requires an organization ID and the provided ID is nil.
389func requireOrgID[T Auditable](ctx context.Context, id uuid.UUID, log slog.Logger) uuid.UUID {
390 if ResourceRequiresOrgID[T]() && id == uuid.Nil {
391 var tgt T
392 resourceName := fmt.Sprintf("%T", tgt)
393 if flag.Lookup("test.v") != nil {
394 // In unit tests we panic to fail the tests
395 panic(fmt.Sprintf("missing required organization ID for resource %q", resourceName))
396 }
397 log.Error(ctx, "missing required organization ID for resource in audit log",
398 slog.F("resource", resourceName),
399 )
400 }
401 return id
402}
403
404// InitRequestWithCancel returns a commit function with a boolean arg.
405// If the arg is false, future calls to commit() will not create an audit log

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected