guard module¶
The guard module.
- class confirm.gitlab_guard.guard.Guard(url, token, namespace, fix, *, project_id=None, token_group=None, token_expiry_days=None)¶
The main GitLab Guard class which does all the heavy load.
- Parameters:
url (str) – The GitLab URL
token (str) – The GitLab token
namespace (str) – The GitLab namespace
fix (bool) – Fix violations automatically
project_id (str) – The project ID whose token variable is updated on rotation
token_group (str) – Group ID/path owning the token; when set, the token is rotated
token_expiry_days (int) – The lifetime (in days) of the rotated token
- init_defaults()¶
Initialise the default configuration, retreived from the defaults.yml contained in the GitLab Guard Python module.
- init_overrides()¶
Retreive the project overrides from the project’s
.gitlab-guard.ymlfile.The
.gitlab-guard.ymlis looked up in the default branch on the root level of the project’s repository. It must be a valid YAML file.
- init_projects()¶
Retreive all unarchived GitLab projects, sorted by their path in an ascending order.
- rotate_token()¶
Rotate the group access token used for authentication, and store the new token in the project’s
GLG_GITLAB_TOKENCI/CD variable.The token is rotated via the group access token
selfendpoint of the group given bytoken_group. GitLab revokes the old token immediately upon rotation, thus the newly issued token is used to update the CI/CD variable.- Raises:
RotationError – When the token couldn’t be rotated or stored
- run()¶
Run the GitLab Guard.
- Raises:
InitError – When an error during the initialisation occurs
RotationError – When the token rotation failed
- verify_overrides(overrides)¶
Verify the overrides.
- Parameters:
overrides (dict) – The overrides
- Raises:
OverrideError – When validation failed
- verify_projects()¶
Verify all projects.
- Raises:
UpdateError – When there was a GitLab error
- verify_protected_branches(project)¶
Verify the protected branches of a project.
- Parameters:
project (gitlab.v4.objects.projects.Project) – The project
- verify_protected_tags(project)¶
Verify the protected tags of a project.
- Parameters:
project (gitlab.v4.objects.projects.Project) – The project
- verify_settings(project)¶
Verify the project settings.
- Parameters:
project (gitlab.v4.objects.projects.Project) – The project