Files
apim-apps/apim_apps/loader.py
T
k3nny 0f1a6d865d feat(apim-apps): add external credentials support for new applications
Applications can now declare a `credentials:` list in the YAML manifest.
Each entry holds a static `client_id` (and optional `secret`) that is
provisioned via POST /applications/{id}/extcredentials when the application
is first created. Existing applications are never modified.

Also adds CHANGELOG.md and ROADMAP.md for the v0.1.0 initial release.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-29 22:16:48 +02:00

134 lines
4.2 KiB
Python

import json
import textwrap
import yaml
from .models import ApiAccess, AppCredential, AppSpec, EnvConfig, Manifest, OrgSpec
EXAMPLE_MANIFEST = textwrap.dedent("""\
# =============================================================================
# Manifeste de normalisation Axway API Manager
# =============================================================================
# Décrit les applications clientes à garantir sur les environnements.
#
# Les organisations sont gérées manuellement dans l'API Manager.
# Ce manifeste ne contient que la section "applications".
#
# Chaque objet peut cibler des environnements spécifiques via "environments:".
# Si "environments" est absent ou vide → s'applique à TOUS les environnements.
# =============================================================================
applications:
# Application présente sur tous les environnements
- name: "MonAppMobile"
organization: "Partenaires-Externes"
description: "Application mobile grand public"
email: "mobile-app@example.com"
enabled: true
credentials:
- client_id: "my-external-client-id"
apis:
- name: "Catalogue-Produits"
version: "v2"
- name: "Commandes"
version: "v1"
- "Notifications" # syntaxe courte (sans version)
# Application restreinte à PROD et PREPROD
- name: "BackOffice-CRM"
organization: "Equipe-Integration"
description: "Connecteur CRM back-office"
email: "crm-team@example.com"
enabled: true
environments:
- PREPROD
- PROD
apis:
- name: "Clients"
version: "v3"
- name: "Contrats"
version: "v1"
# Application de test uniquement sur DEV et RECETTE
- name: "Robot-Tests-API"
organization: "Equipe-QA"
description: "Client Robot Framework pour tests d'intégration"
enabled: true
environments:
- DEV
- RECETTE
apis:
- "Catalogue-Produits"
- "Commandes"
- "Clients"
""")
EXAMPLE_CONFIG = json.dumps({
"environments": [
{"name": "DEV", "url": "https://apimgr-dev.example.com:8075", "verify_ssl": False},
{"name": "RECETTE", "url": "https://apimgr-rec.example.com:8075", "verify_ssl": False},
{"name": "PREPROD", "url": "https://apimgr-ppd.example.com:8075", "verify_ssl": False},
{"name": "PROD", "url": "https://apimgr-prd.example.com:8075", "verify_ssl": True},
]
}, indent=2, ensure_ascii=False)
def load_manifest(path: str) -> Manifest:
with open(path, encoding="utf-8") as f:
raw = yaml.safe_load(f)
manifest = Manifest()
for o in raw.get("organizations", []):
manifest.organizations.append(OrgSpec(
name=o["name"],
description=o.get("description", ""),
email=o.get("email", ""),
phone=o.get("phone", ""),
enabled=o.get("enabled", True),
development=o.get("development", False),
environments=o.get("environments", []),
))
for a in raw.get("applications", []):
apis = []
for api in a.get("apis", []):
if isinstance(api, str):
apis.append(ApiAccess(api_name=api))
else:
apis.append(ApiAccess(api_name=api["name"], api_version=api.get("version", "")))
credentials = [
AppCredential(client_id=c["client_id"], secret=c.get("secret", ""))
for c in a.get("credentials", [])
if c.get("client_id")
]
manifest.applications.append(AppSpec(
name=a["name"],
org_name=a["organization"],
description=a.get("description", ""),
email=a.get("email", ""),
phone=a.get("phone", ""),
enabled=a.get("enabled", True),
apis=apis,
environments=a.get("environments", []),
credentials=credentials,
))
return manifest
def load_config(path: str) -> list[EnvConfig]:
with open(path, encoding="utf-8") as f:
raw = json.load(f)
return [
EnvConfig(
name=e["name"],
url=e["url"],
username="",
password="",
verify_ssl=e.get("verify_ssl", False),
)
for e in raw["environments"]
]