|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Build the Python SDK and run validation tests. |
| 4 | +Cross-platform (Windows, macOS, Linux). |
| 5 | +
|
| 6 | +Prerequisites: Node.js, Python 3.x, Java 17+ on PATH. |
| 7 | +Optional env: API_SPECS_PATH (default api-specs), SKIP_TESTS (default false). |
| 8 | +
|
| 9 | +Usage (from repo root): |
| 10 | + python scripts/build_and_validate_sdk.py |
| 11 | + SKIP_TESTS=true python scripts/build_and_validate_sdk.py |
| 12 | + API_SPECS_PATH=other-specs python scripts/build_and_validate_sdk.py |
| 13 | +""" |
| 14 | + |
| 15 | +import os |
| 16 | +import shutil |
| 17 | +import subprocess |
| 18 | +import sys |
| 19 | +import urllib.request |
| 20 | + |
| 21 | + |
| 22 | +def repo_root(): |
| 23 | + return os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
| 24 | + |
| 25 | + |
| 26 | +def main(): |
| 27 | + root = repo_root() |
| 28 | + os.chdir(root) |
| 29 | + |
| 30 | + api_specs_path = os.environ.get("API_SPECS_PATH", "api-specs") |
| 31 | + skip_tests = os.environ.get("SKIP_TESTS", "false").lower() in ("1", "true", "yes") |
| 32 | + |
| 33 | + print(f"Building SDK (api-specs-path={api_specs_path}, skip-tests={skip_tests})") |
| 34 | + |
| 35 | + # Download OpenAPI Generator if not present |
| 36 | + jar_path = os.path.join(root, "openapi-generator-cli.jar") |
| 37 | + if not os.path.isfile(jar_path): |
| 38 | + print("Downloading OpenAPI Generator...") |
| 39 | + url = "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.12.0/openapi-generator-cli-7.12.0.jar" |
| 40 | + urllib.request.urlretrieve(url, jar_path) |
| 41 | + |
| 42 | + # Prescript |
| 43 | + print("Running prescript...") |
| 44 | + idn_path = os.path.join(api_specs_path, "idn") |
| 45 | + subprocess.run(["node", "sdk-resources/prescript.js", idn_path], check=True, cwd=root) |
| 46 | + |
| 47 | + def build_sdk(name, spec, config, out_dir): |
| 48 | + print(f"Building {name} SDK...") |
| 49 | + sailpoint_dir = os.path.join(root, "sailpoint", out_dir) |
| 50 | + if os.path.isdir(sailpoint_dir): |
| 51 | + shutil.rmtree(sailpoint_dir) |
| 52 | + spec_path = os.path.join(api_specs_path, "idn", spec) |
| 53 | + subprocess.run( |
| 54 | + [ |
| 55 | + "java", "-jar", jar_path, "generate", |
| 56 | + "-i", spec_path, |
| 57 | + "-g", "python", "-o", ".", |
| 58 | + "--global-property", "skipFormModel=false,apiDocs=true,modelDocs=true", |
| 59 | + "--config", f"sdk-resources/{config}", |
| 60 | + ], |
| 61 | + check=True, |
| 62 | + cwd=root, |
| 63 | + ) |
| 64 | + subprocess.run( |
| 65 | + ["node", "sdk-resources/postscript.js", sailpoint_dir], |
| 66 | + check=True, |
| 67 | + cwd=root, |
| 68 | + ) |
| 69 | + |
| 70 | + build_sdk("V3", "sailpoint-api.v3.yaml", "v3-config.yaml", "v3") |
| 71 | + build_sdk("Beta", "sailpoint-api.beta.yaml", "beta-config.yaml", "beta") |
| 72 | + build_sdk("V2024", "sailpoint-api.v2024.yaml", "v2024-config.yaml", "v2024") |
| 73 | + build_sdk("V2025", "sailpoint-api.v2025.yaml", "v2025-config.yaml", "v2025") |
| 74 | + build_sdk("V2026", "sailpoint-api.v2026.yaml", "v2026-config.yaml", "v2026") |
| 75 | + |
| 76 | + # Install and test (use current Python / venv) |
| 77 | + pip_cmd = [sys.executable, "-m", "pip"] |
| 78 | + print("Installing dependencies and SDK...") |
| 79 | + subprocess.run(pip_cmd + ["install", "-r", "requirements.txt"], check=True, cwd=root) |
| 80 | + subprocess.run(pip_cmd + ["install", "-e", "."], check=True, cwd=root) |
| 81 | + |
| 82 | + if not skip_tests: |
| 83 | + print("Running validation tests...") |
| 84 | + subprocess.run( |
| 85 | + [sys.executable, "validation_test.py", "-v"], |
| 86 | + check=True, |
| 87 | + cwd=root, |
| 88 | + ) |
| 89 | + else: |
| 90 | + print(f"Skipping tests (SKIP_TESTS={os.environ.get('SKIP_TESTS', '')})") |
| 91 | + |
| 92 | + print("Done.") |
| 93 | + |
| 94 | + |
| 95 | +if __name__ == "__main__": |
| 96 | + main() |
0 commit comments