Commit 3a69982
authored
Extract _resolve_profile to simplify config file loading (#1333)
## Summary
Follow-up to #1325 (default_profile support). Applies the same
refactoring we did in the Go SDK to improve readability and error
messages.
**Before:** `_known_file_config_loader` used two booleans
(`has_explicit_profile`, `has_default_profile_setting`) to track where
the profile came from. The interaction between them encoded a three-way
state (explicit, from settings, legacy fallback) that required careful
reading to verify correctness. `__settings__` handling was scattered
across three locations in the method.
**Now:** A `_resolve_profile` static method handles all resolution logic
and returns `(profile, is_fallback)`. The loader no longer needs to know
about `__settings__` internals. The two booleans collapse into a single
`is_fallback` flag.
### Changes
- Extract `_resolve_profile(requested_profile, ini_file)` as a static
method that resolves the profile name through three sources: explicit,
`[__settings__].default_profile`, or `[DEFAULT]` fallback.
- Simplify `_known_file_config_loader` to use the resolved result. No
more `has_explicit_profile` / `has_default_profile_setting` booleans.
- Improve error messages: using `__settings__` as a profile name (either
explicitly or via `default_profile`) now returns `"__settings__ is a
reserved section name and cannot be used as a profile"` instead of the
generic `"has no __settings__ profile configured"`.
- Fix flaky SCIM pagination integration test: the raw `GET
/scim/v2/Groups` was fetching the full result set just to read
`totalResults`, causing read timeouts on large workspaces. Now passes
`count=1` since SCIM always returns `totalResults` regardless of page
size.
- Fix pre-existing formatting issues in 3 test files (`test_auth.py`,
`test_config.py`, `test_core.py`) so the CI fmt check passes.
### Why this matters
The three sources for a profile name (explicit, settings-based, legacy
fallback) produce two distinct behaviors:
1. **Explicit and settings-based** both require the profile to exist
(error if missing) and record the active profile on `cfg.profile`.
2. **Legacy fallback** silently returns if `[DEFAULT]` doesn't exist
(unconfigured machine) and doesn't set `cfg.profile`.
A single `is_fallback` boolean captures this distinction. The previous
two-boolean approach worked correctly but required tracing through their
interactions to confirm that.
## Test plan
- All 8 existing `test_default_profile.py` tests pass (updated 2 tests
to match the improved error messages).
- No behavioral changes except the error message text for reserved
section name usage.
This pull request was AI-assisted by Isaac.1 parent c141f1c commit 3a69982
4 files changed
Lines changed: 49 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
716 | 716 | | |
717 | 717 | | |
718 | 718 | | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
719 | 750 | | |
720 | 751 | | |
721 | 752 | | |
| |||
730 | 761 | | |
731 | 762 | | |
732 | 763 | | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | 764 | | |
737 | 765 | | |
738 | 766 | | |
739 | 767 | | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
752 | 772 | | |
753 | | - | |
754 | 773 | | |
755 | 774 | | |
756 | 775 | | |
757 | 776 | | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
758 | 780 | | |
759 | 781 | | |
760 | 782 | | |
| |||
763 | 785 | | |
764 | 786 | | |
765 | 787 | | |
766 | | - | |
| 788 | + | |
767 | 789 | | |
768 | 790 | | |
769 | 791 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
64 | | - | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
0 commit comments