mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 19:56:53 +00:00
`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) <noreply@anthropic.com>
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.errors import AnsibleError
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from utils.cache.api import provider_enabled, resolve_api
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
"""
|
|
lookup('api_enabled', '<provider>') e.g. lookup('api_enabled', 'github')
|
|
|
|
True when every credential the provider declares in group_vars/all/18_api.yml
|
|
carries a value in the effective ``API`` mapping. Integrations that depend on
|
|
a proprietary provider gate on this instead of spelling the emptiness test
|
|
out per call site, so an added credential key extends the gate everywhere and
|
|
the result is a real boolean rather than a string a filter has to coerce.
|
|
"""
|
|
|
|
def run(self, terms, variables: dict[str, Any] | None = None, **kwargs):
|
|
if not terms or len(terms) != 1:
|
|
raise AnsibleError(
|
|
"lookup('api_enabled') takes exactly one term: '<provider>' "
|
|
"(e.g. 'github')."
|
|
)
|
|
|
|
templar = getattr(self, "_templar", None)
|
|
variables = variables or getattr(templar, "available_variables", {}) or {}
|
|
|
|
provider = str(terms[0]).strip()
|
|
if not provider:
|
|
raise AnsibleError("lookup('api_enabled'): empty provider name.")
|
|
|
|
try:
|
|
api = resolve_api(variables, templar=templar)
|
|
return [provider_enabled(api, provider)]
|
|
except (KeyError, TypeError) as error:
|
|
raise AnsibleError(f"lookup('api_enabled'): {error}") from error
|