|
| 1 | +import json |
1 | 2 | import os |
2 | 3 | import secrets |
3 | 4 | import shutil |
@@ -173,6 +174,40 @@ def _prompt_storage(existing: dict[str, str]) -> dict[str, str]: |
173 | 174 | if project.strip(): |
174 | 175 | env["GCP_PROJECT"] = project.strip() |
175 | 176 | env["REMOTE_WORKSPACE_HOST"] = "gcp" |
| 177 | + |
| 178 | + default_sa_path = existing.get("TFL_GCP_SERVICE_ACCOUNT_JSON_PATH", "") |
| 179 | + sa_path = typer.prompt( |
| 180 | + "Path to service account JSON key file (for remote job launches, press Enter to skip)", |
| 181 | + default=default_sa_path, |
| 182 | + show_default=False, |
| 183 | + ).strip() |
| 184 | + if sa_path: |
| 185 | + sa_path = os.path.expanduser(sa_path) |
| 186 | + if not os.path.isfile(sa_path): |
| 187 | + console.print( |
| 188 | + f"[error]File not found: {sa_path} — skipping service account key setup.[/error]" |
| 189 | + "\n[bold error]WARNING: Remote Job (using GCP for storage) launches will fail without a valid service account key.[/bold error]" |
| 190 | + ) |
| 191 | + else: |
| 192 | + try: |
| 193 | + with open(sa_path, "r", encoding="utf-8") as _f: |
| 194 | + json.load(_f) |
| 195 | + env["TFL_GCP_SERVICE_ACCOUNT_JSON_PATH"] = sa_path |
| 196 | + except json.JSONDecodeError: |
| 197 | + console.print( |
| 198 | + "[error]File is not valid JSON — skipping service account key setup.[/error]" |
| 199 | + "\n[bold error]WARNING: Remote Job (using GCP for storage) launches will fail without a valid service account key.[/bold error]" |
| 200 | + ) |
| 201 | + except OSError as e: |
| 202 | + console.print( |
| 203 | + f"[error]Could not read file: {e} — skipping service account key setup.[/error]" |
| 204 | + "\n[bold error]WARNING: Remote Job (using GCP for storage) launches will fail without a valid service account key.[/bold error]" |
| 205 | + ) |
| 206 | + else: |
| 207 | + console.print( |
| 208 | + "[bold error]WARNING: No service account key provided. Remote Job (using GCP for storage) launches will fail.[/bold error]" |
| 209 | + "\n[dim]You can re-run 'lab server init' to configure this later.[/dim]" |
| 210 | + ) |
176 | 211 | elif provider == "azure": |
177 | 212 | console.print("\n[info]Azure Blob Storage authentication:[/info]") |
178 | 213 | use_conn_string = typer.confirm("Use a connection string?", default=True) |
|
0 commit comments