Commit 665d848
refactor(no-ticket): pass resolved credentials through credential-helper plumbing (#336)
* refactor(no-ticket): pass resolved credentials through credential-helper plumbing
The credential-helper plumbing flattened opts.credential into loose
api_key/auth_type strings, threaded the pair through every signature,
then rebuilt a CredentialResult (with a fabricated source_name) just to
hand it to initialise_api. The getattr fallback guarding auth_type could
never fire: it is a declared dataclass field with a default.
Pass the CredentialResult itself instead. The object carries its own
auth scheme end to end, so a bearer credential's custom-domain lookup
now goes out as Authorization: Bearer rather than being re-derived at
the bottom of the stack.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(no-ticket): clear stale X-Api-Key when switching to a bearer credential
initialise_api() resets config.headers on every call but never clears
config.api_key, which Configuration.set_default() makes sticky across
calls. Re-initialising with a bearer credential therefore left a
previously configured X-Api-Key in place, so subsequent requests carried
both auth headers.
This is reachable via the SSO login path: the initialise_api decorator
sets X-Api-Key from credentials.ini, then refresh_api_config_after_auth()
re-initialises with the bearer token. The API could then authenticate as
the pre-login identity while the CLI reported a successful login.
The bearer test previously called unset_api_key() to work around this; it
now seeds a stale key and asserts it is cleared.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(no-ticket): guard custom-domain discovery on a usable key and dry-run
Two defects in the Docker credential-helper install path:
CredentialResult is a plain dataclass, so `if not credential` and
`if org and credential` are true for a credential carrying an empty
api_key — the guards they replaced (`if not api_key`) were not
re-established. Both now check credential.api_key, so a blank credential
no longer reaches an unauthenticated custom-domains lookup.
Auto-discovery also ran before the dry_run short-circuit, so
`install docker --dry-run` issued a live API call and overwrote the
on-disk domain cache despite promising to make no changes. Discovery is
now skipped under dry_run and reported as such in the planned actions.
Also hoists the function-local is_cloudsmith_domain imports to module
level and gives the without-credential test the httpretty and config-path
isolation its neighbours use, so it can no longer pass by falling through
to a live 401.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent ca3819c commit 665d848
8 files changed
Lines changed: 192 additions & 71 deletions
File tree
- cloudsmith_cli
- cli
- commands/credential_helper
- tests/commands
- core/api
- credential_helpers
- docker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | 142 | | |
149 | 143 | | |
150 | 144 | | |
| |||
153 | 147 | | |
154 | 148 | | |
155 | 149 | | |
156 | | - | |
157 | | - | |
| 150 | + | |
158 | 151 | | |
159 | 152 | | |
160 | 153 | | |
| |||
Lines changed: 87 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
160 | | - | |
| 162 | + | |
161 | 163 | | |
| 164 | + | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
| |||
281 | 284 | | |
282 | 285 | | |
283 | 286 | | |
284 | | - | |
| 287 | + | |
| 288 | + | |
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
| |||
300 | 304 | | |
301 | 305 | | |
302 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
303 | 344 | | |
304 | 345 | | |
305 | 346 | | |
| |||
401 | 442 | | |
402 | 443 | | |
403 | 444 | | |
404 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
405 | 449 | | |
406 | 450 | | |
407 | 451 | | |
| |||
507 | 551 | | |
508 | 552 | | |
509 | 553 | | |
510 | | - | |
511 | | - | |
512 | 554 | | |
513 | 555 | | |
514 | 556 | | |
| |||
522 | 564 | | |
523 | 565 | | |
524 | 566 | | |
525 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
526 | 571 | | |
527 | 572 | | |
528 | 573 | | |
529 | 574 | | |
530 | 575 | | |
531 | 576 | | |
532 | 577 | | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
533 | 614 | | |
534 | 615 | | |
535 | 616 | | |
| |||
Lines changed: 79 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
333 | 334 | | |
334 | 335 | | |
335 | 336 | | |
336 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
337 | 340 | | |
338 | 341 | | |
339 | 342 | | |
| |||
347 | 350 | | |
348 | 351 | | |
349 | 352 | | |
| 353 | + | |
| 354 | + | |
350 | 355 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
355 | 363 | | |
356 | 364 | | |
357 | | - | |
| 365 | + | |
358 | 366 | | |
359 | 367 | | |
360 | 368 | | |
361 | 369 | | |
362 | 370 | | |
| 371 | + | |
363 | 372 | | |
364 | 373 | | |
365 | 374 | | |
| |||
371 | 380 | | |
372 | 381 | | |
373 | 382 | | |
374 | | - | |
| 383 | + | |
375 | 384 | | |
376 | 385 | | |
377 | 386 | | |
378 | 387 | | |
379 | 388 | | |
380 | 389 | | |
381 | | - | |
| 390 | + | |
382 | 391 | | |
383 | 392 | | |
384 | 393 | | |
| |||
388 | 397 | | |
389 | 398 | | |
390 | 399 | | |
391 | | - | |
392 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
393 | 408 | | |
394 | 409 | | |
395 | | - | |
| 410 | + | |
396 | 411 | | |
397 | 412 | | |
398 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
399 | 434 | | |
400 | 435 | | |
401 | 436 | | |
| |||
405 | 440 | | |
406 | 441 | | |
407 | 442 | | |
408 | | - | |
| 443 | + | |
409 | 444 | | |
410 | 445 | | |
411 | 446 | | |
| |||
464 | 499 | | |
465 | 500 | | |
466 | 501 | | |
467 | | - | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
468 | 507 | | |
469 | 508 | | |
470 | 509 | | |
| |||
512 | 551 | | |
513 | 552 | | |
514 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
515 | 581 | | |
516 | 582 | | |
517 | 583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
0 commit comments