-
Notifications
You must be signed in to change notification settings - Fork 42
feat(ENG-13683): add Maven credential helper #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| domains, | ||
| download, | ||
| entitlements, | ||
| exec_, | ||
| help_, | ||
| list_, | ||
| login, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright 2026 Cloudsmith Ltd | ||
| """``cloudsmith credential-helper shell-init`` — print shell init for shims. | ||
|
|
||
| Add ``eval "$(cloudsmith credential-helper shell-init)"`` to your shell rc file | ||
| to put the Cloudsmith shims directory ahead of the real package-manager | ||
| binaries on ``$PATH``. | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| import click | ||
|
|
||
| from ....credential_helpers.maven.config import shims_dir | ||
|
|
||
| _COMMENT = "# Put Cloudsmith package-manager shims ahead of the real binaries" | ||
|
|
||
| _POSIX_STATEMENT = 'export PATH="{path}:$PATH"' | ||
|
|
||
| _STATEMENTS = { | ||
| "bash": _POSIX_STATEMENT, | ||
| "zsh": _POSIX_STATEMENT, | ||
| "fish": 'fish_add_path "{path}"', | ||
| } | ||
|
|
||
|
|
||
| def detect_shell(): | ||
| """Best-effort shell detection from ``$SHELL``, defaulting to bash.""" | ||
| name = os.path.basename(os.environ.get("SHELL", "")) | ||
| return name if name in _STATEMENTS else "bash" | ||
|
|
||
|
|
||
| @click.command(name="shell-init") | ||
| @click.option( | ||
| "--shell", | ||
| "shell_name", | ||
| type=click.Choice(sorted(_STATEMENTS)), | ||
| default=None, | ||
| help="Target shell. Auto-detected from $SHELL when omitted.", | ||
| ) | ||
| def shell_init(shell_name): | ||
| """Print shell init that puts the Cloudsmith shims dir first on PATH. | ||
|
|
||
| Examples: | ||
|
|
||
| \b | ||
| # bash / zsh | ||
| $ eval "$(cloudsmith credential-helper shell-init)" | ||
|
|
||
| \b | ||
| # fish | ||
| $ cloudsmith credential-helper shell-init --shell fish | source | ||
| """ | ||
| statement = _STATEMENTS[shell_name or detect_shell()] | ||
| click.echo(_COMMENT) | ||
| click.echo(statement.format(path=shims_dir())) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright 2026 Cloudsmith Ltd | ||
| """CLI/Commands - Run a command with Cloudsmith credentials provisioned.""" | ||
|
|
||
| import sys | ||
|
|
||
| import click | ||
|
|
||
| from ...credential_helpers.maven import runner | ||
| from ..decorators import common_api_auth_options, resolve_credentials | ||
| from .main import main | ||
|
|
||
|
|
||
| @main.command(name="exec", context_settings={"ignore_unknown_options": True}) | ||
| @click.argument("command", nargs=-1, type=click.UNPROCESSED, required=True) | ||
| @common_api_auth_options | ||
| @resolve_credentials | ||
| @click.pass_context | ||
| def exec_(ctx, opts, command): | ||
| """Run a package-manager command authenticated against Cloudsmith. | ||
|
|
||
| Wraps the command so it resolves dependencies from your Cloudsmith | ||
| repository, with credentials injected for that run and removed afterwards. | ||
| This is the machinery the ``mvn`` shim uses, callable directly in CI | ||
| without touching ``PATH``. | ||
|
|
||
| Maven runs use a generated ``settings.xml``; your ``~/.m2/settings.xml`` | ||
| is not consulted. The repository comes from ``credential-helper install | ||
| maven``. The package manager is detected from the command, so just put it | ||
| after ``--``: | ||
|
|
||
| \b | ||
| $ cloudsmith exec -- mvn clean install | ||
| """ | ||
| sys.exit(runner.run(list(command), credential=opts.credential)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fable find - might be worth doublechecking docs vs execution |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detect_shellfalls back to bash, so on Windows (where$SHELLis unset)shell-initprints POSIXexport PATH=...that neither cmd nor PowerShell can eval - even though the launcher machinery happily writes anmvn.cmdshim there. If Windows isn't meant to be supported yet, it'd be better forshell-initto say so explicitly than to print a statement that can't work; otherwise apowershellentry in_STATEMENTSwould close the gap.