Skip to content

Commit 310fb85

Browse files
committed
remove auth ini logic
1 parent 948961b commit 310fb85

File tree

7 files changed

+65
-634
lines changed

7 files changed

+65
-634
lines changed

development/CONTRIBUTING.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,15 @@ export FIREWORKS_API_BASE="https://dev.api.fireworks.ai" # If targeting dev API
106106

107107
**B. Configuration File (Lower Priority)**
108108

109-
If environment variables are not set, Eval Protocol will attempt to read credentials from `~/.fireworks/auth.ini`.
110-
111-
Create or ensure the file `~/.fireworks/auth.ini` exists with the following format:
112-
```ini
113-
[fireworks]
114-
api_key = YOUR_FIREWORKS_API_KEY
115-
account_id = YOUR_FIREWORKS_ACCOUNT_ID
116-
```
117-
Replace with your actual development credentials if using this method.
109+
Eval Protocol does not read `~/.fireworks/auth.ini` (or any firectl profiles). Use environment variables instead.
118110

119111
**Credential Sourcing Order:**
120112
Eval Protocol prioritizes credentials as follows:
121-
1. Environment Variables (`FIREWORKS_API_KEY`, `FIREWORKS_ACCOUNT_ID`)
122-
2. `~/.fireworks/auth.ini` configuration file
113+
1. Environment Variables (`FIREWORKS_API_KEY`, optional `FIREWORKS_ACCOUNT_ID`)
123114

124115
**Purpose of Credentials:**
125116
* `FIREWORKS_API_KEY`: Authenticates your requests to the Fireworks AI service.
126-
* `FIREWORKS_ACCOUNT_ID`: Identifies your account for operations like managing evaluators. It specifies *where* (under which account) an operation should occur.
117+
* `FIREWORKS_ACCOUNT_ID`: Identifies your account for operations like managing evaluators. Typically this is derived automatically from `FIREWORKS_API_KEY` via the `verifyApiKey` endpoint.
127118
* `FIREWORKS_API_BASE`: Allows targeting different API environments (e.g., development, staging).
128119

129120
**Other Environment Variables:**

docs/cli_reference/cli_overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ The CLI recognizes the following environment variables:
329329

330330
- `FIREWORKS_API_KEY`: Your Fireworks API key (required for deployment operations)
331331
- `FIREWORKS_API_BASE`: Base URL for the Fireworks API (defaults to `https://api.fireworks.ai`)
332-
- `FIREWORKS_ACCOUNT_ID`: Your Fireworks account ID (optional, can be configured in auth.ini)
332+
- `FIREWORKS_ACCOUNT_ID`: Your Fireworks account ID (optional; typically derived automatically from `FIREWORKS_API_KEY`)
333333
- `MODEL_AGENT`: Default agent model to use (e.g., "openai/gpt-4o-mini")
334334
- `MODEL_SIM`: Default simulation model to use (e.g., "openai/gpt-3.5-turbo")
335335

eval_protocol/auth.py

Lines changed: 13 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -1,222 +1,24 @@
1-
import configparser
21
import logging
32
import os
4-
from pathlib import Path
5-
from typing import Dict, Optional # Added Dict
3+
from typing import Optional
64

75
import requests
86

97
logger = logging.getLogger(__name__)
108

11-
# Default locations (used for tests and as fallback). Actual resolution is dynamic via _get_auth_ini_file().
12-
FIREWORKS_CONFIG_DIR = Path.home() / ".fireworks"
13-
AUTH_INI_FILE = FIREWORKS_CONFIG_DIR / "auth.ini"
14-
15-
16-
def _get_profile_base_dir() -> Path:
17-
"""
18-
Resolve the Fireworks configuration base directory following firectl behavior:
19-
- Default: ~/.fireworks
20-
- If FIREWORKS_PROFILE is set and non-empty: ~/.fireworks/profiles/<profile>
21-
"""
22-
profile_name = os.environ.get("FIREWORKS_PROFILE", "").strip()
23-
base_dir = Path.home() / ".fireworks"
24-
if profile_name:
25-
base_dir = base_dir / "profiles" / profile_name
26-
return base_dir
27-
28-
29-
def _get_auth_ini_file() -> Path:
30-
"""
31-
Determine the auth.ini file path.
32-
Priority:
33-
1) FIREWORKS_AUTH_FILE env var when set
34-
2) ~/.fireworks[/profiles/<profile>]/auth.ini (profile driven)
35-
"""
36-
auth_file_env = os.environ.get("FIREWORKS_AUTH_FILE")
37-
if auth_file_env:
38-
return Path(auth_file_env)
39-
return _get_profile_base_dir() / "auth.ini"
40-
41-
42-
def _is_profile_active() -> bool:
43-
"""
44-
Returns True if a specific profile or explicit auth file is active.
45-
In this case, profile-based credentials should take precedence over env vars.
46-
"""
47-
if os.environ.get("FIREWORKS_AUTH_FILE"):
48-
return True
49-
prof = os.environ.get("FIREWORKS_PROFILE", "").strip()
50-
return bool(prof)
51-
52-
53-
def _parse_simple_auth_file(file_path: Path) -> Dict[str, str]:
54-
"""
55-
Parses an auth file with simple key=value lines.
56-
Handles comments starting with # or ;.
57-
Strips whitespace and basic quotes from values.
58-
"""
59-
creds = {}
60-
if not file_path.exists():
61-
return creds
62-
try:
63-
with open(file_path, "r", encoding="utf-8") as f:
64-
for line in f:
65-
line = line.strip()
66-
if not line or line.startswith("#") or line.startswith(";"):
67-
continue
68-
if "=" in line:
69-
key, value = line.split("=", 1)
70-
key = key.strip()
71-
value = value.strip()
72-
# Remove surrounding quotes if present
73-
if value and (
74-
(value.startswith('"') and value.endswith('"'))
75-
or (value.startswith("'") and value.endswith("'"))
76-
):
77-
value = value[1:-1]
78-
79-
if key in ["api_key", "account_id"] and value:
80-
creds[key] = value
81-
except Exception as e:
82-
logger.warning("Error during simple parsing of %s: %s", str(file_path), e)
83-
return creds
84-
85-
86-
def _get_credential_from_config_file(key_name: str) -> Optional[str]:
87-
"""
88-
Helper to get a specific credential (api_key or account_id) from auth.ini.
89-
Tries simple parsing first, then configparser.
90-
"""
91-
auth_ini_path = _get_auth_ini_file()
92-
if not auth_ini_path.exists():
93-
return None
94-
95-
# 1. Try simple key-value parsing first
96-
simple_creds = _parse_simple_auth_file(auth_ini_path)
97-
if key_name in simple_creds:
98-
logger.debug("Using %s from simple key-value parsing of %s.", key_name, str(auth_ini_path))
99-
return simple_creds[key_name]
100-
101-
# 2. Fallback to configparser if not found via simple parsing or if simple parsing failed
102-
# This path will also generate the "no section headers" warning if applicable,
103-
# but only if simple parsing didn't yield the key.
104-
try:
105-
config = configparser.ConfigParser()
106-
config.read(auth_ini_path)
107-
108-
# Try [fireworks] section
109-
if "fireworks" in config and config.has_option("fireworks", key_name):
110-
value_from_file = config.get("fireworks", key_name)
111-
if value_from_file:
112-
logger.debug("Using %s from [fireworks] section in %s.", key_name, str(auth_ini_path))
113-
return value_from_file
114-
115-
# Try default section (configparser might place items without section header here)
116-
if config.has_option(config.default_section, key_name):
117-
value_from_default = config.get(config.default_section, key_name)
118-
if value_from_default:
119-
logger.debug(
120-
"Using %s from default section [%s] in %s.",
121-
key_name,
122-
config.default_section,
123-
str(auth_ini_path),
124-
)
125-
return value_from_default
126-
127-
except configparser.MissingSectionHeaderError:
128-
# This error implies the file is purely key-value, which simple parsing should have handled.
129-
# If simple parsing failed to get the key, then it's likely not there or malformed.
130-
logger.debug("%s has no section headers, and simple parsing did not find %s.", str(auth_ini_path), key_name)
131-
except configparser.Error as e_config:
132-
logger.warning("Configparser error reading %s for %s: %s", str(auth_ini_path), key_name, e_config)
133-
except Exception as e_general:
134-
logger.warning("Unexpected error reading %s for %s: %s", str(auth_ini_path), key_name, e_general)
135-
136-
return None
137-
138-
139-
def _get_credentials_from_config_file() -> Dict[str, Optional[str]]:
140-
"""
141-
Retrieve both api_key and account_id from auth.ini with a single read/parse.
142-
Tries simple parsing first for both keys, then falls back to configparser for any missing ones.
143-
Returns a dict with up to two keys: 'api_key' and 'account_id'.
144-
"""
145-
results: Dict[str, Optional[str]] = {}
146-
auth_ini_path = _get_auth_ini_file()
147-
if not auth_ini_path.exists():
148-
return results
149-
150-
# 1) Simple key=value parsing
151-
try:
152-
simple_creds = _parse_simple_auth_file(auth_ini_path)
153-
if "api_key" in simple_creds and simple_creds["api_key"]:
154-
results["api_key"] = simple_creds["api_key"]
155-
if "account_id" in simple_creds and simple_creds["account_id"]:
156-
results["account_id"] = simple_creds["account_id"]
157-
if "api_key" in results and "account_id" in results:
158-
return results
159-
except Exception as e:
160-
logger.warning("Error during simple parsing of %s: %s", str(auth_ini_path), e)
161-
162-
# 2) ConfigParser for any missing keys
163-
try:
164-
config = configparser.ConfigParser()
165-
config.read(auth_ini_path)
166-
for key_name in ("api_key", "account_id"):
167-
if key_name in results and results[key_name]:
168-
continue
169-
if "fireworks" in config and config.has_option("fireworks", key_name):
170-
value_from_file = config.get("fireworks", key_name)
171-
if value_from_file:
172-
results[key_name] = value_from_file
173-
continue
174-
if config.has_option(config.default_section, key_name):
175-
value_from_default = config.get(config.default_section, key_name)
176-
if value_from_default:
177-
results[key_name] = value_from_default
178-
except configparser.MissingSectionHeaderError:
179-
# Purely key=value file without section headers; simple parsing should have handled it already.
180-
logger.debug("%s has no section headers; falling back to simple parsing results.", str(auth_ini_path))
181-
except configparser.Error as e_config:
182-
logger.warning("Configparser error reading %s: %s", str(auth_ini_path), e_config)
183-
except Exception as e_general:
184-
logger.warning("Unexpected error reading %s: %s", str(auth_ini_path), e_general)
185-
186-
return results
187-
1889

18910
def get_fireworks_api_key() -> Optional[str]:
19011
"""
19112
Retrieves the Fireworks API key.
19213
193-
The key is sourced in the following order:
194-
1. FIREWORKS_API_KEY environment variable.
195-
2. 'api_key' from the [fireworks] section of ~/.fireworks/auth.ini.
196-
19714
Returns:
19815
The API key if found, otherwise None.
19916
"""
200-
# If a profile is active, prefer profile file first, then env
201-
if _is_profile_active():
202-
api_key_from_file = _get_credential_from_config_file("api_key")
203-
if api_key_from_file:
204-
return api_key_from_file
205-
api_key = os.environ.get("FIREWORKS_API_KEY")
206-
if api_key:
207-
logger.debug("Using FIREWORKS_API_KEY from environment variable (profile active but file missing).")
208-
return api_key
209-
else:
210-
# Default behavior: env overrides file
211-
api_key = os.environ.get("FIREWORKS_API_KEY")
212-
if api_key:
213-
logger.debug("Using FIREWORKS_API_KEY from environment variable.")
214-
return api_key
215-
api_key_from_file = _get_credential_from_config_file("api_key")
216-
if api_key_from_file:
217-
return api_key_from_file
218-
219-
logger.debug("Fireworks API key not found in environment variables or auth.ini.")
17+
api_key = os.environ.get("FIREWORKS_API_KEY")
18+
if api_key and api_key.strip():
19+
logger.debug("Using FIREWORKS_API_KEY from environment variable.")
20+
return api_key.strip()
21+
logger.debug("Fireworks API key not found in environment variables.")
22022
return None
22123

22224

@@ -226,36 +28,18 @@ def get_fireworks_account_id() -> Optional[str]:
22628
22729
The Account ID is sourced in the following order:
22830
1. FIREWORKS_ACCOUNT_ID environment variable.
229-
2. 'account_id' from the [fireworks] section of ~/.fireworks/auth.ini.
230-
3. If an API key is available (env or auth.ini), resolve via verifyApiKey.
31+
2. If an API key is available (env), resolve via verifyApiKey.
23132
23233
Returns:
23334
The Account ID if found, otherwise None.
23435
"""
235-
# If a profile is active, prefer profile file first, then env
236-
if _is_profile_active():
237-
creds = _get_credentials_from_config_file()
238-
account_id_from_file = creds.get("account_id")
239-
if account_id_from_file:
240-
return account_id_from_file
241-
account_id = os.environ.get("FIREWORKS_ACCOUNT_ID")
242-
if account_id:
243-
logger.debug("Using FIREWORKS_ACCOUNT_ID from environment variable (profile active but file missing).")
244-
return account_id
245-
else:
246-
# Default behavior: env overrides file
247-
account_id = os.environ.get("FIREWORKS_ACCOUNT_ID")
248-
if account_id:
249-
logger.debug("Using FIREWORKS_ACCOUNT_ID from environment variable.")
250-
return account_id
251-
creds = _get_credentials_from_config_file()
252-
account_id_from_file = creds.get("account_id")
253-
if account_id_from_file:
254-
return account_id_from_file
36+
account_id = os.environ.get("FIREWORKS_ACCOUNT_ID")
37+
if account_id and account_id.strip():
38+
logger.debug("Using FIREWORKS_ACCOUNT_ID from environment variable.")
39+
return account_id.strip()
25540

256-
# 3) Fallback: if API key is present, attempt to resolve via verifyApiKey (env or auth.ini)
41+
# Fallback: if API key is present, attempt to resolve via verifyApiKey (env)
25742
try:
258-
# Intentionally use get_fireworks_api_key to centralize precedence (env vs file)
25943
api_key_for_verify = get_fireworks_api_key()
26044
if api_key_for_verify:
26145
resolved = verify_api_key_and_get_account_id(api_key=api_key_for_verify, api_base=get_fireworks_api_base())
@@ -265,7 +49,7 @@ def get_fireworks_account_id() -> Optional[str]:
26549
except Exception as e:
26650
logger.debug("Failed to resolve FIREWORKS_ACCOUNT_ID via verifyApiKey: %s", e)
26751

268-
logger.debug("Fireworks Account ID not found in environment variables, auth.ini, or via verifyApiKey.")
52+
logger.debug("Fireworks Account ID not found in environment variables or via verifyApiKey.")
26953
return None
27054

27155

eval_protocol/cli.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ def parse_args(args=None):
3636
"""Parse command line arguments"""
3737
parser = argparse.ArgumentParser(description="eval-protocol: Tools for evaluation and reward modeling")
3838
parser.add_argument("--verbose", "-v", action="store_true", help="Enable verbose logging")
39-
parser.add_argument(
40-
"--profile",
41-
help="Fireworks profile to use (reads ~/.fireworks/profiles/<name>/auth.ini and settings.ini)",
42-
)
4339
parser.add_argument(
4440
"--server",
4541
help="Fireworks API server hostname or URL (e.g., dev.api.fireworks.ai or https://dev.api.fireworks.ai)",
@@ -537,38 +533,8 @@ def _extract_flag_value(argv_list, flag_name):
537533
return tok.split("=", 1)[1]
538534
return None
539535

540-
pre_profile = _extract_flag_value(raw_argv, "--profile")
541536
pre_server = _extract_flag_value(raw_argv, "--server")
542537

543-
# Handle Fireworks profile selection early so downstream modules see the env
544-
profile = pre_profile
545-
if profile:
546-
try:
547-
os.environ["FIREWORKS_PROFILE"] = profile
548-
# Mirror firectl behavior: ~/.fireworks[/profiles/<profile>]
549-
base_dir = Path.home() / ".fireworks"
550-
if profile:
551-
base_dir = base_dir / "profiles" / profile
552-
os.makedirs(str(base_dir), mode=0o700, exist_ok=True)
553-
554-
# Provide helpful env hints for consumers (optional)
555-
os.environ["FIREWORKS_AUTH_FILE"] = str(base_dir / "auth.ini")
556-
os.environ["FIREWORKS_SETTINGS_FILE"] = str(base_dir / "settings.ini")
557-
logger.debug("Using Fireworks profile '%s' at %s", profile, base_dir)
558-
except OSError as e:
559-
logger.warning("Failed to initialize Fireworks profile '%s': %s", profile, e)
560-
561-
# Proactively resolve and export account_id from the active profile to avoid stale .env overrides
562-
try:
563-
from eval_protocol.auth import get_fireworks_account_id as _resolve_account_id
564-
565-
resolved_account = _resolve_account_id()
566-
if resolved_account:
567-
os.environ["FIREWORKS_ACCOUNT_ID"] = resolved_account
568-
logger.debug("Resolved account_id from profile '%s': %s", profile, resolved_account)
569-
except Exception as e: # noqa: B902
570-
logger.debug("Unable to resolve account_id from profile '%s': %s", profile, e)
571-
572538
# Handle Fireworks server selection early
573539
server = pre_server
574540
if server:

eval_protocol/cli_commands/upload.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ def upload_command(args: argparse.Namespace) -> int:
248248
print(f"Warning: Failed to create/update {secret_name} secret on Fireworks.")
249249
else:
250250
if not fw_account_id:
251-
print("Warning: FIREWORKS_ACCOUNT_ID not found; cannot register secrets.")
251+
print(
252+
"Warning: Could not resolve Fireworks account id from FIREWORKS_API_KEY; cannot register secrets."
253+
)
252254
if not secrets_from_file:
253255
print("Warning: No API keys found in environment or .env file; no secrets to register.")
254256
except Exception as e:

0 commit comments

Comments
 (0)