|
2 | 2 | import time |
3 | 3 | from pathlib import Path |
4 | 4 | from typing import Optional |
| 5 | +from uuid import uuid4 |
5 | 6 |
|
6 | 7 | import questionary |
7 | 8 | import requests |
|
15 | 16 | from codecarbon import __app_name__, __version__ |
16 | 17 | from codecarbon.cli.cli_utils import ( |
17 | 18 | create_new_config_file, |
| 19 | + get_api_enabled, |
18 | 20 | get_api_endpoint, |
19 | 21 | get_config, |
20 | 22 | get_existing_local_exp_id, |
@@ -177,13 +179,29 @@ def config(): |
177 | 179 | else: |
178 | 180 | file_path = create_new_config_file() |
179 | 181 |
|
| 182 | + api_enabled = get_api_enabled() |
| 183 | + api_enabled = typer.prompt( |
| 184 | + f"API is currently {'enabled' if api_enabled == '1' else 'disabled'}. Press enter to continue or change to 0/1", |
| 185 | + type=str, |
| 186 | + default="0", |
| 187 | + ) |
| 188 | + overwrite_local_config("api_enabled", api_enabled, path=file_path) |
| 189 | + |
| 190 | + if api_enabled == "0": |
| 191 | + overwrite_local_config("experiment_id", str(uuid4()), path=file_path) |
| 192 | + return |
| 193 | + |
180 | 194 | api_endpoint = get_api_endpoint(file_path) |
181 | 195 | api_endpoint = typer.prompt( |
182 | | - f"Current API endpoint is {api_endpoint}. Press enter to continue or input other url", |
| 196 | + f"Current API endpoint is at {api_endpoint}. Press enter to continue or input other url", |
183 | 197 | type=str, |
184 | 198 | default=api_endpoint, |
185 | 199 | ) |
186 | 200 | overwrite_local_config("api_endpoint", api_endpoint, path=file_path) |
| 201 | + |
| 202 | + print(f"Logging in to auth server at {AUTH_SERVER_URL}") |
| 203 | + fief_auth.authorize() |
| 204 | + |
187 | 205 | api = ApiClient(endpoint_url=api_endpoint) |
188 | 206 | api.set_access_token(_get_access_token()) |
189 | 207 | organizations = api.get_list_organizations() |
|
0 commit comments