Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
43
backend/sdk/cliproxy/auth/persist_policy.go
Normal file
43
backend/sdk/cliproxy/auth/persist_policy.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package auth
|
||||
|
||||
import "context"
|
||||
|
||||
type skipPersistContextKey struct{}
|
||||
type deferAPIKeyModelAliasRebuildContextKey struct{}
|
||||
|
||||
// WithSkipPersist returns a derived context that disables persistence for Manager Update/Register calls.
|
||||
// It is intended for code paths that are reacting to file watcher events, where the file on disk is
|
||||
// already the source of truth and persisting again would create a write-back loop.
|
||||
func WithSkipPersist(ctx context.Context) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, skipPersistContextKey{}, true)
|
||||
}
|
||||
|
||||
func shouldSkipPersist(ctx context.Context) bool {
|
||||
if ctx == nil {
|
||||
return false
|
||||
}
|
||||
v := ctx.Value(skipPersistContextKey{})
|
||||
enabled, ok := v.(bool)
|
||||
return ok && enabled
|
||||
}
|
||||
|
||||
// WithDeferredAPIKeyModelAliasRebuild returns a derived context that defers API-key model alias table rebuilds.
|
||||
// Callers that use this for a batch of Register/Update/Remove operations must call RefreshAPIKeyModelAlias once.
|
||||
func WithDeferredAPIKeyModelAliasRebuild(ctx context.Context) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, deferAPIKeyModelAliasRebuildContextKey{}, true)
|
||||
}
|
||||
|
||||
func shouldDeferAPIKeyModelAliasRebuild(ctx context.Context) bool {
|
||||
if ctx == nil {
|
||||
return false
|
||||
}
|
||||
v := ctx.Value(deferAPIKeyModelAliasRebuildContextKey{})
|
||||
enabled, ok := v.(bool)
|
||||
return ok && enabled
|
||||
}
|
||||
Loading…
Reference in a new issue