From ddd62febd54bca5896d862e30aff24bd41528d1f Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 19 Sep 2026 06:39:22 +0200 Subject: [PATCH] refactor(api): move utils/api.py under utils/cache `utils.api` shadowed `ansible.module_utils.api` for anything that reached the top-level `utils` package first, which the ai-agent-employees merge made reachable. The module caches provider declarations, so it belongs beside the other caches rather than at the root. The three importers and the two documentation references move with it; nothing else names the old path. Verified: `from utils.cache.api import declared_api, provider_enabled, resolve_api` resolves. Co-Authored-By: Claude Opus 5 (1M context) --- group_vars/all/18_api.yml | 2 +- plugins/lookup/api.py | 2 +- plugins/lookup/api_enabled.py | 2 +- tests/lint/ansible/variables/test_api_accessed_via_lookup.py | 2 +- tests/unit/python/utils/test_api.py | 2 +- utils/{ => cache}/api.py | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename utils/{ => cache}/api.py (100%) diff --git a/group_vars/all/18_api.yml b/group_vars/all/18_api.yml index 5dd167098a..7b4b893809 100644 --- a/group_vars/all/18_api.yml +++ b/group_vars/all/18_api.yml @@ -2,7 +2,7 @@ # Central SPOT for proprietary / external (non-self-hosted) API credentials. # Each entry is empty by default. Override per provider in the (vault- # encrypted) inventory; read ONLY via lookup('api', '.') and -# gate ONLY on lookup('api_enabled', '') (see utils/api.py). +# gate ONLY on lookup('api_enabled', '') (see utils/cache/api.py). # nocheck: unused-var: consumed by the api lookup plugins (plugins/lookup/api.py, plugins/lookup/api_enabled.py) via lookup('api', ...), not referenced directly in YAML/Jinja. API: anthropic: diff --git a/plugins/lookup/api.py b/plugins/lookup/api.py index a10e26c2f2..59adfca6b7 100644 --- a/plugins/lookup/api.py +++ b/plugins/lookup/api.py @@ -5,7 +5,7 @@ from typing import Any from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase -from utils.api import resolve_api +from utils.cache.api import resolve_api class LookupModule(LookupBase): diff --git a/plugins/lookup/api_enabled.py b/plugins/lookup/api_enabled.py index c5f189070b..f7cd906e7e 100644 --- a/plugins/lookup/api_enabled.py +++ b/plugins/lookup/api_enabled.py @@ -5,7 +5,7 @@ from typing import Any from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase -from utils.api import provider_enabled, resolve_api +from utils.cache.api import provider_enabled, resolve_api class LookupModule(LookupBase): diff --git a/tests/lint/ansible/variables/test_api_accessed_via_lookup.py b/tests/lint/ansible/variables/test_api_accessed_via_lookup.py index 803ab4177d..4d724bbfb1 100644 --- a/tests/lint/ansible/variables/test_api_accessed_via_lookup.py +++ b/tests/lint/ansible/variables/test_api_accessed_via_lookup.py @@ -4,7 +4,7 @@ Rationale ========= A bare ``API.github.client_id`` resolves against whatever the scope happens to hold, and an inventory override replaces the declaration rather than merging -into it -- ``utils/api.py`` carries the mechanism and the consequences. +into it -- ``utils/cache/api.py`` carries the mechanism and the consequences. ``lookup('api', '.')`` and ``lookup('api_enabled', '')`` merge the override over ``group_vars/all/18_api.yml``, so an override narrows values and never the provider set. Routing every access through them also keeps diff --git a/tests/unit/python/utils/test_api.py b/tests/unit/python/utils/test_api.py index 1a48d495b9..4ab80741b3 100644 --- a/tests/unit/python/utils/test_api.py +++ b/tests/unit/python/utils/test_api.py @@ -1,6 +1,6 @@ import unittest -from utils.api import declared_api, provider_enabled, resolve_api +from utils.cache.api import declared_api, provider_enabled, resolve_api class TestResolveApi(unittest.TestCase): diff --git a/utils/api.py b/utils/cache/api.py similarity index 100% rename from utils/api.py rename to utils/cache/api.py