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,
)
| 141 | |
| 142 | |
| 143 | def _write_profile( |
| 144 | config_dir: pathlib.Path, |
| 145 | profile: str, |
| 146 | config: Dict[str, Any], |
| 147 | credentials: Optional[Dict[str, Any]] = None, |
| 148 | ) -> None: |
| 149 | """Test helper: lay out `configs/<profile>.json` and optionally |
| 150 | `credentials/<profile>.json` under `config_dir`. |
| 151 | |
| 152 | Accepts either the new nested `{"authentication": {...}}` shape or a |
| 153 | legacy flat shape (`{"type": "workload_identity", ...}`) for backwards |
| 154 | compatibility with the tests that predate the schema migration. Legacy |
| 155 | inputs are translated via `_migrate_legacy_config` before being |
| 156 | written to disk. |
| 157 | |
| 158 | Prepends `"type": "oauth_token"` to the credentials dict unless the |
| 159 | caller already supplied a `type` key (so negative tests can override). |
| 160 | """ |
| 161 | if "type" in config and "authentication" not in config: |
| 162 | config = _migrate_legacy_config(config) |
| 163 | (config_dir / "configs").mkdir(parents=True, exist_ok=True) |
| 164 | config_path = config_dir / "configs" / f"{profile}.json" |
| 165 | config_path.write_text(json.dumps(config)) |
| 166 | # The config reader refuses files that group or others can write. |
| 167 | config_path.chmod(0o644) |
| 168 | if credentials is not None: |
| 169 | if "type" not in credentials: |
| 170 | credentials = {"type": "oauth_token", **credentials} |
| 171 | (config_dir / "credentials").mkdir(parents=True, exist_ok=True) |
| 172 | creds_path = config_dir / "credentials" / f"{profile}.json" |
| 173 | creds_path.write_text(json.dumps(credentials)) |
| 174 | # Match the 0o600 invariant the real credentials reader now enforces. |
| 175 | creds_path.chmod(0o600) |
| 176 | |
| 177 | |
| 178 | # --------------------------------------------------------------------------- # |
no test coverage detected