Commit 291777c1 authored by Adrian DC's avatar Adrian DC
Browse files

feat(cli, gitlab): implement CI job token and public authentications

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 3f211bd4
Loading
Loading
Loading
Loading
Loading
+1 −0
Changes for README.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ positional arguments:

environment variables
  GITLAB_TOKEN                      # GitLab API token environment variable
  CI_JOB_TOKEN                      # GitLab CI job token environment variable (CI only)
```

<!-- readme-help-stop -->
+1 −0
Changes for src/cli/entrypoint.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ class Entrypoint:
        gitlab = GitLabFeature(
            gitlab_url,
            environments.value('gitlab_token'),
            environments.value('ci_job_token'),
            options.dry_run,
        )
        print(f'{Colors.BOLD} - GitLab host: '
+5 −0
Changes for src/cli/main.py: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -37,6 +37,11 @@ def main() -> None:
        Bundle.ENV_GITLAB_TOKEN,
        'GitLab API token environment variable',
    )
    environments.add(
        'ci_job_token',
        Bundle.ENV_CI_JOB_TOKEN,
        'GitLab CI job token environment variable (CI only)',
    )

    # Arguments creation
    parser: ArgumentParser = ArgumentParser(
+17 −2
Changes for src/features/gitlab.py: 17 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -28,10 +28,25 @@ class GitLabFeature:
    __gitlab: Gitlab

    # Constructor
    def __init__(self, url: str, token: str, dry_run: bool = False) -> None:
    def __init__(
        self,
        url: str,
        private_token: str,
        job_token: str,
        dry_run: bool = False,
    ) -> None:

        # Initialize members
        self.__dry_run = dry_run
        self.__gitlab = Gitlab(url, private_token=token)

        # Create GitLab client
        if private_token:
            self.__gitlab = Gitlab(url, private_token=private_token)
            self.__gitlab.auth()
        elif job_token:
            self.__gitlab = Gitlab(url, job_token=job_token)
        else:
            self.__gitlab = Gitlab(url)

    # Group
    def group(self, criteria: str) -> Group:
+1 −0
Changes for src/package/bundle.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ class Bundle:
    RELEASE_FIRST_TIMESTAMP: int = 1579337311

    # Environment
    ENV_CI_JOB_TOKEN: str = 'CI_JOB_TOKEN'
    ENV_DEBUG_UPDATES_DAILY: str = 'DEBUG_UPDATES_DAILY'
    ENV_DEBUG_UPDATES_DISABLE: str = 'DEBUG_UPDATES_DISABLE'
    ENV_DEBUG_UPDATES_FAKE: str = 'DEBUG_UPDATES_FAKE'