MCPcopy Create free account
hub / github.com/HKUDS/OpenSpace / get_openspace_auth

Function get_openspace_auth

openspace/cloud/auth.py:24–60  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

22
23
24def 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
63def get_api_base(cli_override: Optional[str] = None) -> str:

Callers 2

_get_cloud_clientFunction · 0.90
hybrid_search_skillsFunction · 0.90

Calls 3

read_host_mcp_envFunction · 0.90
getMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected