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

Method Prepare

coderd/rbac/authz.go:486–509  ·  view source on GitHub ↗

Prepare will partially execute the rego policy leaving the object fields unknown (except for the type). This will vastly speed up performance if batch authorization on the same type of objects is needed.

(ctx context.Context, subject Subject, action policy.Action, objectType string)

Source from the content-addressed store, hash-verified

484// Prepare will partially execute the rego policy leaving the object fields unknown (except for the type).
485// This will vastly speed up performance if batch authorization on the same type of objects is needed.
486func (a RegoAuthorizer) Prepare(ctx context.Context, subject Subject, action policy.Action, objectType string) (PreparedAuthorized, error) {
487 start := time.Now()
488 ctx, span := tracing.StartSpan(ctx,
489 trace.WithTimestamp(start),
490 rbacTraceAttributes(subject, action, objectType),
491 )
492 defer span.End()
493
494 prepared, err := a.newPartialAuthorizer(ctx, subject, action, objectType)
495 if err != nil {
496 err = correctCancelError(err)
497 return nil, xerrors.Errorf("new partial authorizer: %w", err)
498 }
499
500 // Add attributes of the Prepare results. This will help understand the
501 // complexity of the roles and how it affects the time taken.
502 span.SetAttributes(
503 attribute.Int("num_queries", len(prepared.preparedQueries)),
504 attribute.Bool("always_true", prepared.alwaysTrue),
505 )
506
507 a.prepareHist.Observe(time.Since(start).Seconds())
508 return prepared, nil
509}
510
511// PartialAuthorizer is a prepared authorizer with the subject, action, and
512// resource type fields already filled in. This speeds up authorization

Callers

nothing calls this directly

Calls 6

newPartialAuthorizerMethod · 0.95
StartSpanFunction · 0.92
rbacTraceAttributesFunction · 0.85
correctCancelErrorFunction · 0.85
IntMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected