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

Function _write_profile

tests/lib/test_credentials.py:129–158  ·  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

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

Source from the content-addressed store, hash-verified

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

Calls 1

_migrate_legacy_configFunction · 0.85

Tested by

no test coverage detected