Skip to content

Commit

Permalink
Merge pull request #16 from bjd2385/ENG-135
Browse files Browse the repository at this point in the history
ENG-135: Specify token in config
  • Loading branch information
emmeowzing authored Feb 20, 2023
2 parents c5103a4 + 91d0d0d commit c779ac6
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ By default, this tool sends your configuration to [https://gitlab.com](https://g

GitLab Lint API now [requires authorization](https://gitlab.com/gitlab-org/gitlab/-/issues/321290).

1. [Create Access Token](https://gitlab.com/-/profile/personal_access_tokens) with `api` scope.
1. [Create an access token](https://gitlab.com/-/profile/personal_access_tokens) with `api` scope.
2. Set access token value as a `GITLAB_TOKEN` or `GITLABCI_LINT_TOKEN` environment variable.
3. Ensure Python version available is 3.8 or later.

@@ -57,6 +57,7 @@ No configuration file is required for use. However, if you'd rather specify sett
quiet = false
base-url = "https://gitlab.com"
configs = [ ".gitlab-ci.yml" ]
token = "$GITLAB_TOKEN"
```

## Development
1 change: 1 addition & 0 deletions examples/gitlabci-lint-conf/.gitlabci-lint-defaults.toml
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@
quiet = false
base-url = https://gitlab.com
configs = [ .gitlab-ci.yml ]
token = "$GITLAB_TOKEN"
12 changes: 8 additions & 4 deletions src/gitlabci_lint/validate.py
Original file line number Diff line number Diff line change
@@ -187,10 +187,6 @@ def cli() -> None:

args = parser.parse_args()

if not ((token := os.getenv('GITLABCI_LINT_TOKEN')) or (token := os.getenv('GITLAB_TOKEN'))):
errprint('ERROR: Neither \'GITLABCI_LINT_TOKEN\' nor \'GITLAB_TOKEN\' set.')
sys.exit(1)

# If a gitlabci-lint config was specified via CLI, override the default search locations.
hook_config_file_CLI = args.gitlabci_lint_config
if hook_config_file_CLI:
@@ -207,6 +203,7 @@ def cli() -> None:
json.loads(filesystem_config[default_config_section].get('configs', str(default_configs)))
)
)
token_CONF = os.path.expandvars(filesystem_config[default_config_section].get('configs', None))

quiet_CLI = args.quiet
base_url_CLI = args.base_url
@@ -223,6 +220,13 @@ def cli() -> None:
# multiple flags and defaults.
configs = ['.gitlab-ci.yml']

token: Optional[str]
if token_CONF:
token = os.path.expandvars(token_CONF)
elif not ((token := os.getenv('GITLABCI_LINT_TOKEN')) or (token := os.getenv('GITLAB_TOKEN'))):
errprint('ERROR: Neither \'GITLABCI_LINT_TOKEN\' nor \'GITLAB_TOKEN\' set.')
sys.exit(1)

if (exitCode := validateCiConfig(token, base_url, configs, quiet)) != os.EX_OK:
sys.exit(exitCode)

0 comments on commit c779ac6

Please sign in to comment.