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

Function _write_profile

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

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

Calls 1

_migrate_legacy_configFunction · 0.85

Tested by

no test coverage detected