Resolve OpenSpace credentials and base URL. Returns: ``(auth_headers, api_base)`` — headers dict ready for HTTP requests and the API base URL. If no credentials are found, ``auth_headers`` is empty.
()
| 22 | |
| 23 | |
| 24 | def get_openspace_auth() -> tuple[Dict[str, str], str]: |
| 25 | """Resolve OpenSpace credentials and base URL. |
| 26 | |
| 27 | Returns: |
| 28 | ``(auth_headers, api_base)`` — headers dict ready for HTTP requests |
| 29 | and the API base URL. If no credentials are found, ``auth_headers`` |
| 30 | is empty. |
| 31 | """ |
| 32 | from openspace.host_detection import read_host_mcp_env |
| 33 | |
| 34 | auth_headers: Dict[str, str] = {} |
| 35 | api_base = OPENSPACE_DEFAULT_BASE |
| 36 | |
| 37 | # Tier 1: env vars |
| 38 | env_key = os.environ.get("OPENSPACE_API_KEY", "").strip() |
| 39 | env_base = os.environ.get("OPENSPACE_API_BASE", "").strip() |
| 40 | |
| 41 | if env_key: |
| 42 | auth_headers["X-API-Key"] = env_key |
| 43 | if env_base: |
| 44 | api_base = env_base.rstrip("/") |
| 45 | logger.info("OpenSpace auth: using OPENSPACE_API_KEY env var") |
| 46 | return auth_headers, api_base |
| 47 | |
| 48 | # Tier 2: host agent config MCP env block |
| 49 | mcp_env = read_host_mcp_env() |
| 50 | cfg_key = str(mcp_env.get("OPENSPACE_API_KEY", "")).strip() |
| 51 | cfg_base = str(mcp_env.get("OPENSPACE_API_BASE", "")).strip() |
| 52 | |
| 53 | if cfg_key: |
| 54 | auth_headers["X-API-Key"] = cfg_key |
| 55 | if cfg_base: |
| 56 | api_base = cfg_base.rstrip("/") |
| 57 | logger.info("OpenSpace auth: using OPENSPACE_API_KEY from host agent MCP env config") |
| 58 | return auth_headers, api_base |
| 59 | |
| 60 | return auth_headers, api_base |
| 61 | |
| 62 | |
| 63 | def get_api_base(cli_override: Optional[str] = None) -> str: |
no test coverage detected