| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -282,6 +282,16 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser: | |||
| 282 | 282 | help=("GitLab CI job token [env var: CI_JOB_TOKEN]"), | |
| 283 | 283 | required=False, | |
| 284 | 284 | ) | |
| 285 | + parser.add_argument( | ||
| 286 | + "--skip-login", | ||
| 287 | + help=( | ||
| 288 | + "Skip initial authenticated API call to the current user endpoint. " | ||
| 289 | + "This may be useful when invoking the CLI in scripts. " | ||
| 290 | + "[env var: GITLAB_SKIP_LOGIN]" | ||
| 291 | + ), | ||
| 292 | + action="store_true", | ||
| 293 | + default=os.getenv("GITLAB_SKIP_LOGIN"), | ||
| 294 | + ) | ||
| 285 | 295 | return parser | |
| 286 | 296 | ||
| 287 | 297 | ||
@@ -368,6 +378,7 @@ def main() -> None: | |||
| 368 | 378 | debug = args.debug | |
| 369 | 379 | gitlab_resource = args.gitlab_resource | |
| 370 | 380 | resource_action = args.resource_action | |
| 381 | + skip_login = args.skip_login | ||
| 371 | 382 | ||
| 372 | 383 | args_dict = vars(args) | |
| 373 | 384 | # Remove CLI behavior-related args | |
@@ -390,6 +401,7 @@ def main() -> None: | |||
| 390 | 401 | "private_token", | |
| 391 | 402 | "oauth_token", | |
| 392 | 403 | "job_token", | |
| 404 | + "skip_login", | ||
| 393 | 405 | ): | |
| 394 | 406 | args_dict.pop(item) | |
| 395 | 407 | args_dict = {k: _parse_value(v) for k, v in args_dict.items() if v is not None} | |
@@ -398,7 +410,7 @@ def main() -> None: | |||
| 398 | 410 | gl = gitlab.Gitlab.merge_config(vars(options), gitlab_id, config_files) | |
| 399 | 411 | if debug: | |
| 400 | 412 | gl.enable_debug() | |
| 401 | - if gl.private_token or gl.oauth_token: | ||
| 413 | + if not skip_login and (gl.private_token or gl.oauth_token): | ||
| 402 | 414 | gl.auth() | |
| 403 | 415 | except Exception as e: | |
| 404 | 416 | die(str(e)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,17 @@ def resp_get_project(): | |||
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | + @pytest.fixture | ||
| 39 | + def resp_current_user(): | ||
| 40 | + return { | ||
| 41 | + "method": responses.GET, | ||
| 42 | + "url": f"{DEFAULT_URL}/api/v4/user", | ||
| 43 | + "json": {"username": "name", "id": 1}, | ||
| 44 | + "content_type": "application/json", | ||
| 45 | + "status": 200, | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + | ||
| 38 | 49 | @pytest.fixture | |
| 39 | 50 | def resp_delete_registry_tags_in_bulk(): | |
| 40 | 51 | return { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,6 +90,22 @@ def test_uses_ci_job_token(monkeypatch, script_runner, resp_get_project): | |||
| 90 | 90 | assert ret.success | |
| 91 | 91 | ||
| 92 | 92 | ||
| 93 | + @pytest.mark.script_launch_mode("inprocess") | ||
| 94 | + @responses.activate | ||
| 95 | + def test_does_not_auth_on_skip_login( | ||
| 96 | + monkeypatch, script_runner, resp_get_project, resp_current_user | ||
| 97 | + ): | ||
| 98 | + monkeypatch.setenv("GITLAB_PRIVATE_TOKEN", PRIVATE_TOKEN) | ||
| 99 | + monkeypatch.setattr(config, "_DEFAULT_FILES", []) | ||
| 100 | + | ||
| 101 | + resp_user = responses.add(**resp_current_user) | ||
| 102 | + resp_project = responses.add(**resp_get_project) | ||
| 103 | + ret = script_runner.run(["gitlab", "--skip-login", "project", "get", "--id", "1"]) | ||
| 104 | + assert ret.success | ||
| 105 | + assert resp_user.call_count == 0 | ||
| 106 | + assert resp_project.call_count == 1 | ||
| 107 | + | ||
| 108 | + | ||
| 93 | 109 | @pytest.mark.script_launch_mode("inprocess") | |
| 94 | 110 | @responses.activate | |
| 95 | 111 | def test_private_token_overrides_job_token( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments