MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / _write_profile

Function _write_profile

tests/lib/test_credentials.py:136–165  ·  view source on GitHub ↗

Test helper: lay out `configs/ .json` and optionally `credentials/ .json` under `config_dir`. Accepts either the new nested `{"authentication": {...}}` shape or a legacy flat shape (`{"type": "workload_identity", ...}`) for backwards compatibility with the tests that

(
    config_dir: pathlib.Path,
    profile: str,
    config: Dict[str, Any],
    credentials: Optional[Dict[str, Any]] = None,
)

Source from the content-addressed store, hash-verified

134
135
136def _write_profile(
137 config_dir: pathlib.Path,
138 profile: str,
139 config: Dict[str, Any],
140 credentials: Optional[Dict[str, Any]] = None,
141) -> None:
142 """Test helper: lay out `configs/<profile>.json` and optionally
143 `credentials/<profile>.json` under `config_dir`.
144
145 Accepts either the new nested `{"authentication": {...}}` shape or a
146 legacy flat shape (`{"type": "workload_identity", ...}`) for backwards
147 compatibility with the tests that predate the schema migration. Legacy
148 inputs are translated via `_migrate_legacy_config` before being
149 written to disk.
150
151 Prepends `"type": "oauth_token"` to the credentials dict unless the
152 caller already supplied a `type` key (so negative tests can override).
153 """
154 if "type" in config and "authentication" not in config:
155 config = _migrate_legacy_config(config)
156 (config_dir / "configs").mkdir(parents=True, exist_ok=True)
157 (config_dir / "configs" / f"{profile}.json").write_text(json.dumps(config))
158 if credentials is not None:
159 if "type" not in credentials:
160 credentials = {"type": "oauth_token", **credentials}
161 (config_dir / "credentials").mkdir(parents=True, exist_ok=True)
162 creds_path = config_dir / "credentials" / f"{profile}.json"
163 creds_path.write_text(json.dumps(credentials))
164 # Match the 0o600 invariant the real credentials reader now enforces.
165 creds_path.chmod(0o600)
166
167
168# --------------------------------------------------------------------------- #

Calls 1

_migrate_legacy_configFunction · 0.85

Tested by

no test coverage detected