MCPcopy Index your code
hub / github.com/commandoperator/cmdop-sdk / resolve

Method resolve

python/src/cmdop/config.py:36–81  ·  view source on GitHub ↗

Build a config, applying explicit > env > default precedence. Relay token sources: ``CMDOP_TOKEN`` then ``CMDOP_API_KEY`` (token wins if both) — keeps single-credential setups working. The skills plane reads ``api_key`` from ``CMDOP_API_KEY`` independently.

(
        cls,
        *,
        token: str | None = None,
        base_url: str | None = None,
        fleet_id: str | None = None,
        timeout_ms: int | None = None,
        api_key: str | None = None,
        api_base_url: str | None = None,
    )

Source from the content-addressed store, hash-verified

34
35 @classmethod
36 def resolve(
37 cls,
38 *,
39 token: str | None = None,
40 base_url: str | None = None,
41 fleet_id: str | None = None,
42 timeout_ms: int | None = None,
43 api_key: str | None = None,
44 api_base_url: str | None = None,
45 ) -> ClientConfig:
46 """Build a config, applying explicit > env > default precedence.
47
48 Relay token sources: ``CMDOP_TOKEN`` then ``CMDOP_API_KEY`` (token wins
49 if both) — keeps single-credential setups working. The skills plane
50 reads ``api_key`` from ``CMDOP_API_KEY`` independently.
51 """
52 token = token or os.environ.get("CMDOP_TOKEN") or os.environ.get("CMDOP_API_KEY")
53 if not token:
54 raise ValueError(
55 "No token. Pass token= or set CMDOP_TOKEN (or CMDOP_API_KEY)."
56 )
57
58 resolved_base = base_url or os.environ.get("CMDOP_BASE_URL") or DEFAULT_BASE_URL
59
60 resolved_fleet = fleet_id or os.environ.get("CMDOP_FLEET_ID") or None
61
62 if timeout_ms is not None:
63 resolved_timeout = timeout_ms
64 else:
65 env_timeout = os.environ.get("CMDOP_TIMEOUT_MS")
66 resolved_timeout = int(env_timeout) if env_timeout else DEFAULT_TIMEOUT_MS
67
68 resolved_api_key = api_key or os.environ.get("CMDOP_API_KEY") or None
69
70 resolved_api_base = (
71 api_base_url or os.environ.get("CMDOP_API_BASE_URL") or DEFAULT_API_BASE_URL
72 )
73
74 return cls(
75 token=token,
76 base_url=resolved_base.rstrip("/"),
77 fleet_id=resolved_fleet,
78 timeout_ms=resolved_timeout,
79 api_key=resolved_api_key,
80 api_base_url=resolved_api_base.rstrip("/"),
81 )

Callers 15

__init__Method · 0.80
test_token_env_fallbackFunction · 0.80
test_defaultsFunction · 0.80
test_base_url_precedenceFunction · 0.80
_make_transportFunction · 0.80

Calls 1

getMethod · 0.45

Tested by 12

test_token_env_fallbackFunction · 0.64
test_defaultsFunction · 0.64
test_base_url_precedenceFunction · 0.64
_make_transportFunction · 0.64
_make_transportFunction · 0.64