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)
| 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. |
| 486 | func (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 |
nothing calls this directly
no test coverage detected