Documentation
¶
Overview ¶
Package roles manages global roles and global environments: the Access API's /api/v1/roles and /api/v1/environments (issue #77, decision 0013). The built-in roles and environments (model.BuiltinGlobalRoles, accessapi.BuiltinEnvironments) are not stored; this package merges them with the stored custom ones, and it is how the permission evaluator reads a global role (Role, then model.RoleActions).
Role ¶
access module, core layer: the roles service. The roles and environments handlers in access/adapters/http build a Service over the configured store and the artifacts module's repositories, and call it. The package imports the standard library, the kernel, core/model and core/port, and artifacts/api for the repository configurations that name an environment.
Inputs ¶
- Service: a Store (the access ports with their unit of work), which the metadata store satisfies; the artifacts module's Repositories over the same unit of work; the global environment limit.
- Environment names, and roles in model form.
Outputs ¶
- Global environments and custom roles, and the stored changes to the predefined roles, in the project store; environment names rewritten in roles, project assignments and repository configurations by a rename.
- ErrInvalid, ErrBuiltin, ErrNotFound, ErrConflict and ErrInUse, whose text the Access API returns as it is; store errors come back wrapped with "roles: ".
Invariants ¶
- A rename updates roles, project assignments and repository configurations in one transaction: the repository updates take the context of the Store's transaction, so they join it and roll back with it (decision 0013).
- DEV and PROD, and the ADMIN role, never change; an environment a repository or a global role still names is not deleted.
- Environment names are compared without regard to case, across global and project environments.
References ¶
- Decision 0013: docs/research/decisions/0013-projects-and-environments.md.
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md (modules reach each other through api packages; module stores).
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 282 (core/roles) and line 1035 (the package mapping row).
- Plan: docs/implementation/plan.md#p4-identity-and-authorization and #p9d-modular-monolith-migration, epic ACC (https://github.com/weaveplatform/artifactweave/issues/940).
- https://github.com/weaveplatform/artifactweave/issues/77
- https://github.com/weaveplatform/artifactweave/issues/1065
Status ¶
Implemented P4: global roles and environments (pull request 93), editable built-in roles (pull request 103) and the environment and role limits (pull request 470). Moved here in P9d, where Service takes Store and rewrites repository configurations through the artifacts module's API.
Testing ¶
- roles_test.go: TestUnitEnvironments, TestUnitRoles, TestUnitCustomRoleLimit and TestUnitGlobalEnvironmentLimit.
- fault_test.go: TestUnitStoreFailures (each store failure an operation can meet, the repository calls among them) and TestUnitRenameEnvironmentRollsBackRepositoryUpdates (a failed second repository update leaves the environment, the role, the assignment and both repositories as they were).
The tests run on the metadata store's in-memory store, with a stand-in for the artifacts module's repositories (repositories_test.go).
Index ¶
- Constants
- Variables
- type Service
- func (s Service) CreateEnvironment(ctx context.Context, name string) error
- func (s Service) CreateRole(ctx context.Context, r model.Role) error
- func (s Service) DeleteEnvironment(ctx context.Context, name string) error
- func (s Service) DeleteRole(ctx context.Context, name string) error
- func (s Service) Environments(ctx context.Context) ([]string, error)
- func (s Service) RenameEnvironment(ctx context.Context, name, to string) error
- func (s Service) Role(ctx context.Context, name string) (model.Role, error)
- func (s Service) Roles(ctx context.Context) ([]model.Role, error)
- func (s Service) UpdateRole(ctx context.Context, name string, r model.Role) error
- type Store
Constants ¶
const DefaultGlobalEnvironmentLimit = 10
DefaultGlobalEnvironmentLimit is how many global environments may exist, DEV and PROD among them, when nothing else is configured: Access's environments.global-limit (supported Access configurations; createglobalenvironment, "By default, Artifactory supports up to 10 global environments").
Variables ¶
var ( // ErrInvalid reports a request the API refuses as malformed. ErrInvalid = errors.New("invalid") // ErrBuiltin reports a change to a built-in role or environment. ErrBuiltin = errors.New("built in") // ErrNotFound reports a role or environment that does not exist. ErrNotFound = errors.New("not found") // ErrConflict reports a name that is already taken. ErrConflict = errors.New("already exists") // ErrInUse reports an environment that repositories still belong to. ErrInUse = errors.New("in use") )
Errors the handlers map to statuses. The Access API returns their text verbatim, so package prefixes would change existing response messages.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// Store holds the roles, environments and project assignments. Every
// change runs in one Tx of Store, and the calls it makes join it through
// the context.
Store Store
// Repositories lists and updates repository configurations. Its calls
// take the context of Store's transaction, so it must be the artifacts
// module's binding over the same unit of work: a rename's repository
// updates then commit or roll back with the roles and assignments it
// renames (decision 0013).
Repositories artifactsapi.Repositories
// GlobalLimit caps the global environments, DEV and PROD included;
// zero means DefaultGlobalEnvironmentLimit.
GlobalLimit int
}
Service reads and writes global roles and environments in Store, and the environment names of repository configurations through Repositories.
func (Service) CreateEnvironment ¶
CreateEnvironment adds a global environment, while fewer than the limit exist.
func (Service) CreateRole ¶
CreateRole adds a CUSTOM_GLOBAL role.
func (Service) DeleteEnvironment ¶
DeleteEnvironment removes a global environment that no repository or global role names.
func (Service) DeleteRole ¶
DeleteRole removes a custom global role and every project membership's assignment of it.
func (Service) Environments ¶
Environments returns the global environment names: DEV and PROD, then the stored ones by name.
func (Service) RenameEnvironment ¶
RenameEnvironment renames a global environment and every repository and role that names it.
func (Service) Role ¶
Role returns the global role called name: a built-in one with any stored change to its actions and environments, or a custom one.
func (Service) Roles ¶
Roles returns the built-in global roles, with any stored changes to the predefined ones, then the custom ones by name.
func (Service) UpdateRole ¶
UpdateRole replaces the global role called name with r. A custom role changes its description, actions and environments; a PREDEFINED one only its actions and environments, stored over the built-in defaults. No role is renamed or changes type, and the ADMIN role does not change at all.
type Store ¶
Store is what the roles service reads and writes: the access module's stores, the project store among them, which holds the stored global roles and environments and the project assignments, and their unit of work (port.Store's Tx). The application passes its composite store, which satisfies it. Store holds no repository store: repository configurations belong to the artifacts module, which the service reaches only through Service.Repositories.