Skip to content

Commit a70b75b

Browse files
Merge pull request #41 from cogsol/40-feature-improve-credentials-experience-in-the-framework
fix: improve API key error messages and add tests for credential checks
2 parents c4df0f3 + 50151f3 commit a70b75b

6 files changed

Lines changed: 337 additions & 17 deletions

File tree

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ agents/salesagent/
118118

119119
### 3. Configure Environment
120120

121-
Copy `.env.example` to `.env` and set your API credentials:
121+
To use CogSol you need API credentials. Visit **[https://onboarding.cogsol.ai](https://onboarding.cogsol.ai)** to obtain your credentials. Make sure to also configure the service API key in the implantation portal before running any commands.
122+
123+
Copy `.env.example` to `.env` and fill in the credentials obtained from the portal:
122124

123125
```env
124126
COGSOL_ENV=development
125-
COGSOL_API_KEY=your-api-key
127+
COGSOL_API_KEY=your-api-key # Obtain from https://onboarding.cogsol.ai
126128
# Optional: Azure AD B2C client credentials for JWT
127129
# If not provided, the Auth will be skipped
128130
COGSOL_AUTH_CLIENT_ID=your-client-id
@@ -690,17 +692,14 @@ from cogsol.content import BaseRetrieval, ReorderingStrategy
690692

691693
### Environment Variables
692694

695+
Credentials are obtained from the CogSol onboarding portal at **[https://onboarding.cogsol.ai](https://onboarding.cogsol.ai)**. Configure your service API key there before running migrations or using the CLI.
696+
693697
| Variable | Required | Description |
694698
|----------|----------|-------------|
695-
| `COGSOL_API_KEY` | Yes | API Key authentication |
699+
| `COGSOL_API_KEY` | Yes | Service API key — obtain from the portal at https://onboarding.cogsol.ai |
696700
| `COGSOL_ENV` | No | Environment name (e.g., `local`, `development`, `production`) |
697-
| `COGSOL_AUTH_CLIENT_ID` | No | Client Id provided for adminitrators |
698-
| `COGSOL_AUTH_SECRET` | No | Auth Secret provided for adminitrators |
699-
700-
# Optional: Azure AD B2C client credentials for JWT\
701-
# If not provided, the Auth will be skipped
702-
COGSOL_AUTH_CLIENT_ID=your-client-id
703-
COGSOL_AUTH_SECRET=your-client-secret
701+
| `COGSOL_AUTH_CLIENT_ID` | No | Client Id provided for administrators |
702+
| `COGSOL_AUTH_SECRET` | No | Auth secret provided for administrators |
704703

705704
### Project Settings (`settings.py`)
706705

cogsol/core/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ def _refresh_bearer_token(self) -> None:
134134
client_secret = os.environ.get("COGSOL_AUTH_SECRET")
135135

136136
if not client_secret:
137-
raise CogSolAPIError("Missing authentication configuration: COGSOL_AUTH_SECRET")
137+
raise CogSolAPIError(
138+
"Missing authentication configuration: COGSOL_AUTH_SECRET is not set.\n"
139+
"To obtain your credentials, visit https://onboarding.cogsol.ai\n"
140+
"and configure the service API key in the implantation portal."
141+
)
138142

139143
authority = "https://pyxiscognitivesweden.b2clogin.com/pyxiscognitivesweden.onmicrosoft.com/B2C_1A_CS_signup_signin_Sweden_MigrationOIDC"
140144
scopes = [f"https://pyxiscognitivesweden.onmicrosoft.com/{client_id}/.default"]

cogsol/management/commands/chat.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,16 @@ def handle(self, project_path: Path | None, **options: Any) -> int:
319319

320320
api_base = get_cognitive_api_base_url()
321321
api_key = os.environ.get("COGSOL_API_KEY")
322-
if not api_base:
323-
print_error("COGSOL_API_BASE is required in .env to chat with CogSol.")
322+
if not api_key and not os.environ.get("COGSOL_AUTH_CLIENT_ID"):
323+
print_error(
324+
"No API credentials found.\n"
325+
"Set COGSOL_API_KEY in your .env file to authenticate with the CogSol API.\n"
326+
"\n"
327+
"To obtain your credentials:\n"
328+
" 1. Visit https://onboarding.cogsol.ai\n"
329+
" 2. Configure the service API key in the implantation portal\n"
330+
" 3. Copy the key to COGSOL_API_KEY in your .env file"
331+
)
324332
return 1
325333

326334
remote_ids = self._load_remote_ids(project_path, app)

cogsol/management/commands/importagent.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,16 @@ def handle(self, project_path: Path | None, **options: Any) -> int:
296296
api_base = get_cognitive_api_base_url()
297297
api_key = os.environ.get("COGSOL_API_KEY")
298298
content_base = get_content_api_base_url() or api_base
299-
if not api_base:
300-
print("COGSOL_API_BASE is required in .env to import.")
299+
if not api_key and not os.environ.get("COGSOL_AUTH_CLIENT_ID"):
300+
print(
301+
"Error: No API credentials found.\n"
302+
"Set COGSOL_API_KEY in your .env file to authenticate with the CogSol API.\n"
303+
"\n"
304+
"To obtain your credentials:\n"
305+
" 1. Visit https://onboarding.cogsol.ai\n"
306+
" 2. Configure the service API key in the implantation portal\n"
307+
" 3. Copy the key to COGSOL_API_KEY in your .env file"
308+
)
301309
return 1
302310

303311
client = CogSolClient(api_base, api_key=api_key, content_base_url=content_base)

cogsol/management/commands/migrate.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ def handle(self, project_path: Path | None, **options: Any) -> int:
5858
api_base = get_cognitive_api_base_url()
5959
api_key = self._env("COGSOL_API_KEY", required=False)
6060
content_base = get_content_api_base_url()
61-
if not api_base:
62-
print("COGSOL_API_BASE is required in .env to run migrations against CogSol APIs.")
61+
if not api_key and not os.environ.get("COGSOL_AUTH_CLIENT_ID"):
62+
print(
63+
"Error: No API credentials found.\n"
64+
"Set COGSOL_API_KEY in your .env file to authenticate with the CogSol API.\n"
65+
"\n"
66+
"To obtain your credentials:\n"
67+
" 1. Visit https://onboarding.cogsol.ai\n"
68+
" 2. Configure the service API key in the implantation portal\n"
69+
" 3. Copy the key to COGSOL_API_KEY in your .env file"
70+
)
6371
return 1
6472

6573
exit_code = 0

0 commit comments

Comments
 (0)