{"modulePath":"github.com/chainloop-dev/chainloop","version":"v1.141.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package usercontext\n\n## Functions\n\n```go\nfunc BlockIfCASBackendNotValid(uc biz.CASBackendReader) middleware.Middleware\n```\nBlockIfCASBackendNotValid checks that the current organization has a valid CAS Backend configured If the CAS Backend is not valid it will block the request\n\n```go\nfunc CheckUserHasAccess(allowList *conf.AllowList, userUC biz.UserOrgFinder) middleware.Middleware\n```\nMiddleware that checks that the user has access to the current route Note that the source of truth is in the end the property set in the DB The value in the allowlist conf setting is used as a starting point to populate the property in the DB\n\n```go\nfunc CurrentAuthzSubject(ctx context.Context) string\n```\n\n```go\nfunc Prometheus() middleware.Middleware\n```\nThis package contains a set of wrappers that take grpc.UnaryInterceptors and translate them into Kratos middlewares. The reason for having these kind of wrappers is so we can sort them in the context of the rest of middlewares. Otherwise, plain grpc interceptors will be added after the chain of middlewares [https://github.com/go-kratos/kratos/blob/f8b97f675b32dfad02edae12d83053c720720b5b/transport/grpc/server.go#L166](https://github.com/go-kratos/kratos/blob/f8b97f675b32dfad02edae12d83053c720720b5b/transport/grpc/server.go#L166)\n\n```go\nfunc ValidateCASBackend(uc biz.CASBackendReader) middleware.Middleware\n```\nValidateCASBackend checks that the current organization has a valid CAS Backend configured If the last validation happened more than validationTimeOffset ago it will re-run the validation This middleware does not block the request if the CAS Backend is not valid\n\n```go\nfunc WithAPITokenUsageUpdater(apiTokenUC *biz.APITokenUseCase, logger *log.Helper) middleware.Middleware\n```\n\n```go\nfunc WithAttestationContextFromAPIToken(apiTokenUC *biz.APITokenUseCase, orgUC *biz.OrganizationUseCase, logger *log.Helper) middleware.Middleware\n```\nWithAttestationContextFromAPIToken injects the API-Token, organization + robot account to the context\n\n```go\nfunc WithAttestationContextFromFederatedInfo(orgUC *biz.OrganizationUseCase, logger *log.Helper) middleware.Middleware\n```\n\n```go\nfunc WithAttestationContextFromRobotAccount(robotAccountUseCase *biz.RobotAccountUseCase, orgUseCase *biz.OrganizationUseCase, logger *log.Helper) middleware.Middleware\n```\nWithAttestationContextFromRobotAccount Middleware that injects the current user to the context\n\n```go\nfunc WithAttestationContextFromUser(userUC *biz.UserUseCase, orgUC *biz.OrganizationUseCase, logger *log.Helper) middleware.Middleware\n```\nWithAttestationContextFromUser injects the current user + organization to the context during the attestation process it leverages the existing middlewares to set the current user and organization but with a skipping behavior since that's the one required by the attMiddleware multi-selector\n\n```go\nfunc WithAuthzSubject(ctx context.Context, subject string) context.Context\n```\nStore the authorization subject\n\n```go\nfunc WithCurrentAPITokenAndOrgMiddleware(apiTokenUC *biz.APITokenUseCase, orgUC *biz.OrganizationUseCase, logger *log.Helper) middleware.Middleware\n```\nMiddleware that injects the API-Token + organization to the context\n\n```go\nfunc WithCurrentMembershipsMiddleware(membershipUC biz.MembershipsRBAC, membershipsCache cache.Cache[*entities.Membership]) middleware.Middleware\n```\n\n```go\nfunc WithCurrentOrganizationMiddleware(userUseCase biz.UserOrgFinder, orgUC *biz.OrganizationUseCase, logger *log.Helper) middleware.Middleware\n```\n\n```go\nfunc WithCurrentUserMiddleware(userUseCase biz.UserOrgFinder, logger *log.Helper) middleware.Middleware\n```\nWithCurrentUserMiddleware injects the current user + organization to the context\n\n```go\nfunc WithOperationAuthorizationMiddleware(conf *conf.OperationAuthorizationProvider, logger *log.Helper) middleware.Middleware\n```\nWithOperationAuthorizationMiddleware forwards specific operations to an external authorization. If the external call fails, the request is denied.\n\n```go\nfunc WithRobotAccount(ctx context.Context, acc *RobotAccount) context.Context\n```\nSet the current robot account in the context\n\n```go\nfunc WithSuspensionMiddleware() middleware.Middleware\n```\nWithSuspensionMiddleware blocks all requests when the current organization is suspended. If there is no org in context (e.g. status endpoints), the request passes through.\n\n## Types\n\n```go\ntype RequestWithRawContract interface {\n\tGetRawContract() []byte\n}\n```\n\n```go\ntype ResourceBase struct {\n\tMetadata struct {\n\t\tOrganization string `json:\"organization\"`\n\t} `json:\"metadata\"`\n}\n```\n\n```go\ntype RobotAccount struct {\n\tID, WorkflowID, OrgID, ProviderKey string\n}\n```\n\n```go\nfunc CurrentRobotAccount(ctx context.Context) *RobotAccount\n```\n\n","path":"github.com/chainloop-dev/chainloop/app/controlplane/internal/usercontext","name":"usercontext","synopsis":"","isRedistributable":true}
