|
3 | 3 | import functools |
4 | 4 |
|
5 | 5 | import click |
| 6 | +from click.core import ParameterSource |
6 | 7 |
|
7 | 8 | from cloudsmith_cli.cli import validators |
8 | 9 |
|
@@ -116,6 +117,7 @@ def wrapper(ctx, *args, **kwargs): |
116 | 117 |
|
117 | 118 | opts.load_config_file(path=config_file, profile=profile) |
118 | 119 | opts.load_creds_file(path=creds_file, profile=profile) |
| 120 | + opts.api_key_from_file = opts.api_key |
119 | 121 | kwargs["opts"] = opts |
120 | 122 | return ctx.invoke(f, *args, **kwargs) |
121 | 123 |
|
@@ -226,6 +228,20 @@ def wrapper(ctx, *args, **kwargs): |
226 | 228 | # pylint: disable=missing-docstring |
227 | 229 | opts = config.get_or_create_options(ctx) |
228 | 230 | api_key = kwargs.pop("api_key") |
| 231 | + |
| 232 | + source = ctx.get_parameter_source("api_key") |
| 233 | + api_key_nonempty = api_key and api_key.strip() |
| 234 | + if source == ParameterSource.COMMANDLINE and api_key_nonempty: |
| 235 | + opts.api_key_from_flag = api_key |
| 236 | + opts.api_key_from_env = None |
| 237 | + elif source == ParameterSource.ENVIRONMENT and api_key_nonempty: |
| 238 | + opts.api_key_from_flag = None |
| 239 | + opts.api_key_from_env = api_key |
| 240 | + else: |
| 241 | + opts.api_key_from_flag = None |
| 242 | + opts.api_key_from_env = None |
| 243 | + |
| 244 | + # Keep opts.api_key populated for any code that still reads it directly. |
229 | 245 | if api_key: |
230 | 246 | opts.api_key = api_key |
231 | 247 | kwargs["opts"] = opts |
@@ -302,7 +318,9 @@ def wrapper(ctx, *args, **kwargs): |
302 | 318 |
|
303 | 319 | context = CredentialContext( |
304 | 320 | session=opts.session, |
305 | | - api_key=opts.api_key, |
| 321 | + api_key_from_flag=opts.api_key_from_flag, |
| 322 | + api_key_from_env=opts.api_key_from_env, |
| 323 | + api_key_from_file=opts.api_key_from_file, |
306 | 324 | api_host=opts.api_host or "https://api.cloudsmith.io", |
307 | 325 | creds_file_path=ctx.meta.get("creds_file"), |
308 | 326 | profile=ctx.meta.get("profile"), |
|
0 commit comments