Identity: adds ServiceIdentityForSingleNamespace helper (#113161)

This commit is contained in:
Charandas
2025-11-01 11:51:25 -07:00
committed by GitHub
parent 83e3b1fac7
commit c98259f74a
+15
View File
@@ -74,6 +74,21 @@ func newInternalIdentity(name string, namespace string, orgID int64, opts ...Ide
return staticRequester
}
// WithServiceIdentityForSingleNamespace sets an identity representing the service itself in provided namespace and store it in context.
// This is useful for background tasks that has to communicate with other services in the same namespace. It also returns a Requester with
// static permissions so it can be used in legacy code paths.
func WithServiceIdentityForSingleNamespace(ctx context.Context, namespace string, opts ...IdentityOpts) (context.Context, Requester) {
r := newInternalIdentity(serviceName, namespace, 1, opts...)
return WithRequester(ctx, r), r
}
// WithServiceIdentityForSingleNamespaceContext sets an identity representing the service itself in context, restricted to a namespace.
// Use when using a middleware that signs tokens with the same restriction.
func WithServiceIdentityForSingleNamespaceContext(ctx context.Context, namespace string, opts ...IdentityOpts) context.Context {
ctx, _ = WithServiceIdentityForSingleNamespace(ctx, namespace, opts...)
return ctx
}
// WithServiceIdentity sets an identity representing the service itself in provided org and store it in context.
// This is useful for background tasks that has to communicate with unfied storage. It also returns a Requester with
// static permissions so it can be used in legacy code paths.