Restore oauth_token backward compatibility for collection token auth#16500
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughAdds legacy ChangesOAuth Token Backward Compatibility
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
awx_collection/plugins/module_utils/controller_api.py (1)
301-302: 💤 Low valueConsider using starred unpacking for list concatenation.
The current concatenation works correctly, but starred unpacking is more idiomatic in modern Python.
♻️ Optional refactor
- for honorred_setting in list(self.short_params) + ['oauth_token']: + for honorred_setting in [*self.short_params, 'oauth_token']:🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@awx_collection/plugins/module_utils/controller_api.py` around lines 301 - 302, Replace the list concatenation in the for loop with starred unpacking: change the iteration from for honorred_setting in list(self.short_params) + ['oauth_token'] to for honorred_setting in [*self.short_params, 'oauth_token'] so it uses idiomatic unpacking of self.short_params plus the 'oauth_token' element.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@awx_collection/plugins/module_utils/controller_api.py`:
- Around line 301-302: Replace the list concatenation in the for loop with
starred unpacking: change the iteration from for honorred_setting in
list(self.short_params) + ['oauth_token'] to for honorred_setting in
[*self.short_params, 'oauth_token'] so it uses idiomatic unpacking of
self.short_params plus the 'oauth_token' element.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 93d9b2bd-136f-4008-8987-fd91c732a89a
📒 Files selected for processing (3)
awx_collection/plugins/doc_fragments/auth_plugin.pyawx_collection/plugins/module_utils/controller_api.pyawx_collection/test/awx/test_token_auth.py
0f960eb to
2af94c7
Compare
The aap_token rename (c8981e3) restored module-level token auth but left two interfaces from earlier collection releases broken: - The lookup (controller_api) and inventory (controller) plugins previously declared an oauth_token option. Add oauth_token as an alias of aap_token in the auth_plugin doc fragment and in AUTH_ARGSPEC so query(..., oauth_token=...) and inventory YAML keys keep working. - tower_cli.cfg-style config files used an oauth_token key under [general]; it was silently ignored after the rename, quietly degrading auth. load_config() now also reads the legacy oauth_token key and maps it to aap_token, with the new aap_token key winning when both are present. aap_token remains the canonical attribute used by _parse_aap_token() and the Bearer header logic. Also make the test helper compatible with ansible-core 2.21+, which requires a serialization profile alongside _ANSIBLE_ARGS, and extend the tests to cover the oauth_token alias and legacy config file key. No changelog fragment added: awx_collection has no changelogs/ directory on devel. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com>
The oauth_token alias was added to aap_token in AUTH_ARGSPEC but not to the module doc fragment, failing the validate-modules sanity check (undocumented argument alias). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com>
ae8cd3c to
7207bcb
Compare
|
SUMMARY
Follow-up to #16498. The
aap_tokenrename restored module-level token auth, but two interfaces from earlier collection releases remained broken:Lookup/inventory plugin option
oauth_token— earlier collection releases declared an option literally namedoauth_token(its only spelling) in theauth_plugindoc fragment, used by thecontroller_apilookup (query(..., oauth_token=...)) and thecontrollerinventory plugin (oauth_token:key in inventory YAML). The renamed option only carried thecontroller_oauthtoken/tower_oauthtokenaliases, so existing lookup/inventory usage failed with an invalid-option error.oauth_tokenis now an alias ofaap_tokenin the doc fragment.Legacy
oauth_tokenkey in tower_cli.cfg-style config files —short_paramspreviously mapped theoauth_tokenini key under[general]; after the rename it was silently ignored, quietly degrading auth (the same failure mode Make aap_token functional for collection token auth #16498 fixed).load_config()now also reads the legacyoauth_tokenkey and maps it toaap_token, with the newaap_tokenkey winning when both are present.aap_tokenremains the canonical attribute consumed by_parse_aap_token()and the Bearer-header logic.Note on scope:
oauth_tokenis also added to theaap_tokenaliases inAUTH_ARGSPEC(and documented in the moduleauthdoc fragment). Unlike the two items above this is not a restoration — modules historically usedcontroller_oauthtoken/tower_oauthtoken(both already aliased) — it just keeps the module and plugin option surfaces consistent. Happy to drop that hunk if reviewers prefer the strictly-compat scope.Also makes the test helper compatible with ansible-core 2.21+, which requires a serialization profile alongside
_ANSIBLE_ARGS— without this, the tests added in #16498 fail on 2.21.No changelog fragment:
awx_collection/changelogs/does not exist on devel.ISSUE TYPE
COMPONENT NAME
AWX VERSION
devel
ADDITIONAL INFORMATION
Behavior verified against the pre-rename collection sources (
awx_collection/plugins/doc_fragments/auth_plugin.pydeclaredoauth_token;module_utils/controller_api.pyhad'oauth_token': 'controller_oauthtoken'inshort_paramswithconfig_name = 'tower_cli.cfg').Tested with
pytest awx_collection/test/awx/test_token_auth.pyin the awx_devel image (ansible-core 2.21.0): 10 passed — the 6 pre-existing canonicalaap_tokencases (string and dict inputs) plus 4 new/extended compat cases (oauth_tokenalias on modules and lookup, legacy config-file key,aap_tokenprecedence over the legacy key).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests