Skip to content

Commit f4abc41

Browse files
chore: apply ruff linting fixes to CLI module
fix: apply ruff fixes to CLI and update Okta provider test
1 parent de5d3c3 commit f4abc41

File tree

18 files changed

+207
-168
lines changed

18 files changed

+207
-168
lines changed

src/crewai/cli/authentication/providers/__init__.py

Whitespace-only changes.

src/crewai/cli/authentication/providers/auth0.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from crewai.cli.authentication.providers.base_provider import BaseProvider
22

3+
34
class Auth0Provider(BaseProvider):
45
def get_authorize_url(self) -> str:
56
return f"https://{self._get_domain()}/oauth/device/code"
@@ -14,13 +15,20 @@ def get_issuer(self) -> str:
1415
return f"https://{self._get_domain()}/"
1516

1617
def get_audience(self) -> str:
17-
assert self.settings.audience is not None, "Audience is required"
18+
if self.settings.audience is None:
19+
raise ValueError(
20+
"Audience is required. Please set it in the configuration."
21+
)
1822
return self.settings.audience
1923

2024
def get_client_id(self) -> str:
21-
assert self.settings.client_id is not None, "Client ID is required"
25+
if self.settings.client_id is None:
26+
raise ValueError(
27+
"Client ID is required. Please set it in the configuration."
28+
)
2229
return self.settings.client_id
2330

2431
def _get_domain(self) -> str:
25-
assert self.settings.domain is not None, "Domain is required"
32+
if self.settings.domain is None:
33+
raise ValueError("Domain is required. Please set it in the configuration.")
2634
return self.settings.domain
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
from abc import ABC, abstractmethod
2+
23
from crewai.cli.authentication.main import Oauth2Settings
34

5+
46
class BaseProvider(ABC):
57
def __init__(self, settings: Oauth2Settings):
68
self.settings = settings
79

810
@abstractmethod
9-
def get_authorize_url(self) -> str:
10-
...
11+
def get_authorize_url(self) -> str: ...
1112

1213
@abstractmethod
13-
def get_token_url(self) -> str:
14-
...
14+
def get_token_url(self) -> str: ...
1515

1616
@abstractmethod
17-
def get_jwks_url(self) -> str:
18-
...
17+
def get_jwks_url(self) -> str: ...
1918

2019
@abstractmethod
21-
def get_issuer(self) -> str:
22-
...
20+
def get_issuer(self) -> str: ...
2321

2422
@abstractmethod
25-
def get_audience(self) -> str:
26-
...
23+
def get_audience(self) -> str: ...
2724

2825
@abstractmethod
29-
def get_client_id(self) -> str:
30-
...
26+
def get_client_id(self) -> str: ...

src/crewai/cli/authentication/providers/okta.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from crewai.cli.authentication.providers.base_provider import BaseProvider
22

3+
34
class OktaProvider(BaseProvider):
45
def get_authorize_url(self) -> str:
56
return f"https://{self.settings.domain}/oauth2/default/v1/device/authorize"
@@ -14,9 +15,15 @@ def get_issuer(self) -> str:
1415
return f"https://{self.settings.domain}/oauth2/default"
1516

1617
def get_audience(self) -> str:
17-
assert self.settings.audience is not None
18+
if self.settings.audience is None:
19+
raise ValueError(
20+
"Audience is required. Please set it in the configuration."
21+
)
1822
return self.settings.audience
1923

2024
def get_client_id(self) -> str:
21-
assert self.settings.client_id is not None
25+
if self.settings.client_id is None:
26+
raise ValueError(
27+
"Client ID is required. Please set it in the configuration."
28+
)
2229
return self.settings.client_id

src/crewai/cli/authentication/providers/workos.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from crewai.cli.authentication.providers.base_provider import BaseProvider
22

3+
34
class WorkosProvider(BaseProvider):
45
def get_authorize_url(self) -> str:
56
return f"https://{self._get_domain()}/oauth2/device_authorization"
@@ -17,9 +18,13 @@ def get_audience(self) -> str:
1718
return self.settings.audience or ""
1819

1920
def get_client_id(self) -> str:
20-
assert self.settings.client_id is not None, "Client ID is required"
21+
if self.settings.client_id is None:
22+
raise ValueError(
23+
"Client ID is required. Please set it in the configuration."
24+
)
2125
return self.settings.client_id
2226

2327
def _get_domain(self) -> str:
24-
assert self.settings.domain is not None, "Domain is required"
28+
if self.settings.domain is None:
29+
raise ValueError("Domain is required. Please set it in the configuration.")
2530
return self.settings.domain

src/crewai/cli/authentication/utils.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ def validate_jwt_token(
1717
missing required claims).
1818
"""
1919

20-
decoded_token = None
21-
2220
try:
2321
jwk_client = PyJWKClient(jwks_url)
2422
signing_key = jwk_client.get_signing_key_from_jwt(jwt_token)
2523

2624
_unverified_decoded_token = jwt.decode(
2725
jwt_token, options={"verify_signature": False}
2826
)
29-
decoded_token = jwt.decode(
27+
return jwt.decode(
3028
jwt_token,
3129
signing_key.key,
3230
algorithms=["RS256"],
@@ -40,23 +38,22 @@ def validate_jwt_token(
4038
"require": ["exp", "iat", "iss", "aud", "sub"],
4139
},
4240
)
43-
return decoded_token
4441

45-
except jwt.ExpiredSignatureError:
46-
raise Exception("Token has expired.")
47-
except jwt.InvalidAudienceError:
42+
except jwt.ExpiredSignatureError as e:
43+
raise Exception("Token has expired.") from e
44+
except jwt.InvalidAudienceError as e:
4845
actual_audience = _unverified_decoded_token.get("aud", "[no audience found]")
4946
raise Exception(
5047
f"Invalid token audience. Got: '{actual_audience}'. Expected: '{audience}'"
51-
)
52-
except jwt.InvalidIssuerError:
48+
) from e
49+
except jwt.InvalidIssuerError as e:
5350
actual_issuer = _unverified_decoded_token.get("iss", "[no issuer found]")
5451
raise Exception(
5552
f"Invalid token issuer. Got: '{actual_issuer}'. Expected: '{issuer}'"
56-
)
53+
) from e
5754
except jwt.MissingRequiredClaimError as e:
58-
raise Exception(f"Token is missing required claims: {str(e)}")
55+
raise Exception(f"Token is missing required claims: {e!s}") from e
5956
except jwt.exceptions.PyJWKClientError as e:
60-
raise Exception(f"JWKS or key processing error: {str(e)}")
57+
raise Exception(f"JWKS or key processing error: {e!s}") from e
6158
except jwt.InvalidTokenError as e:
62-
raise Exception(f"Invalid token: {str(e)}")
59+
raise Exception(f"Invalid token: {e!s}") from e

src/crewai/cli/cli.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from importlib.metadata import version as get_version
2-
from typing import Optional
32

43
import click
5-
from crewai.cli.config import Settings
6-
from crewai.cli.settings.main import SettingsCommand
4+
75
from crewai.cli.add_crew_to_flow import add_crew_to_flow
6+
from crewai.cli.config import Settings
87
from crewai.cli.create_crew import create_crew
98
from crewai.cli.create_flow import create_flow
109
from crewai.cli.crew_chat import run_chat
10+
from crewai.cli.settings.main import SettingsCommand
1111
from crewai.memory.storage.kickoff_task_outputs_storage import (
1212
KickoffTaskOutputsSQLiteStorage,
1313
)
@@ -237,13 +237,11 @@ def login():
237237
@crewai.group()
238238
def deploy():
239239
"""Deploy the Crew CLI group."""
240-
pass
241240

242241

243242
@crewai.group()
244243
def tool():
245244
"""Tool Repository related commands."""
246-
pass
247245

248246

249247
@deploy.command(name="create")
@@ -263,31 +261,31 @@ def deploy_list():
263261

264262
@deploy.command(name="push")
265263
@click.option("-u", "--uuid", type=str, help="Crew UUID parameter")
266-
def deploy_push(uuid: Optional[str]):
264+
def deploy_push(uuid: str | None):
267265
"""Deploy the Crew."""
268266
deploy_cmd = DeployCommand()
269267
deploy_cmd.deploy(uuid=uuid)
270268

271269

272270
@deploy.command(name="status")
273271
@click.option("-u", "--uuid", type=str, help="Crew UUID parameter")
274-
def deply_status(uuid: Optional[str]):
272+
def deply_status(uuid: str | None):
275273
"""Get the status of a deployment."""
276274
deploy_cmd = DeployCommand()
277275
deploy_cmd.get_crew_status(uuid=uuid)
278276

279277

280278
@deploy.command(name="logs")
281279
@click.option("-u", "--uuid", type=str, help="Crew UUID parameter")
282-
def deploy_logs(uuid: Optional[str]):
280+
def deploy_logs(uuid: str | None):
283281
"""Get the logs of a deployment."""
284282
deploy_cmd = DeployCommand()
285283
deploy_cmd.get_crew_logs(uuid=uuid)
286284

287285

288286
@deploy.command(name="remove")
289287
@click.option("-u", "--uuid", type=str, help="Crew UUID parameter")
290-
def deploy_remove(uuid: Optional[str]):
288+
def deploy_remove(uuid: str | None):
291289
"""Remove a deployment."""
292290
deploy_cmd = DeployCommand()
293291
deploy_cmd.remove_crew(uuid=uuid)
@@ -327,7 +325,6 @@ def tool_publish(is_public: bool, force: bool):
327325
@crewai.group()
328326
def flow():
329327
"""Flow related commands."""
330-
pass
331328

332329

333330
@flow.command(name="kickoff")
@@ -359,7 +356,7 @@ def chat():
359356
and using the Chat LLM to generate responses.
360357
"""
361358
click.secho(
362-
"\nStarting a conversation with the Crew\n" "Type 'exit' or Ctrl+C to quit.\n",
359+
"\nStarting a conversation with the Crew\nType 'exit' or Ctrl+C to quit.\n",
363360
)
364361

365362
run_chat()
@@ -368,7 +365,6 @@ def chat():
368365
@crewai.group(invoke_without_command=True)
369366
def org():
370367
"""Organization management commands."""
371-
pass
372368

373369

374370
@org.command("list")
@@ -396,7 +392,6 @@ def current():
396392
@crewai.group()
397393
def enterprise():
398394
"""Enterprise Configuration commands."""
399-
pass
400395

401396

402397
@enterprise.command("configure")
@@ -410,7 +405,6 @@ def enterprise_configure(enterprise_url: str):
410405
@crewai.group()
411406
def config():
412407
"""CLI Configuration commands."""
413-
pass
414408

415409

416410
@config.command("list")

src/crewai/cli/config.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import json
22
from pathlib import Path
3-
from typing import Optional
43

54
from pydantic import BaseModel, Field
65

76
from crewai.cli.constants import (
8-
DEFAULT_CREWAI_ENTERPRISE_URL,
9-
CREWAI_ENTERPRISE_DEFAULT_OAUTH2_PROVIDER,
107
CREWAI_ENTERPRISE_DEFAULT_OAUTH2_AUDIENCE,
118
CREWAI_ENTERPRISE_DEFAULT_OAUTH2_CLIENT_ID,
129
CREWAI_ENTERPRISE_DEFAULT_OAUTH2_DOMAIN,
10+
CREWAI_ENTERPRISE_DEFAULT_OAUTH2_PROVIDER,
11+
DEFAULT_CREWAI_ENTERPRISE_URL,
1312
)
1413
from crewai.cli.shared.token_manager import TokenManager
1514

@@ -56,20 +55,20 @@
5655

5756

5857
class Settings(BaseModel):
59-
enterprise_base_url: Optional[str] = Field(
58+
enterprise_base_url: str | None = Field(
6059
default=DEFAULT_CLI_SETTINGS["enterprise_base_url"],
6160
description="Base URL of the CrewAI Enterprise instance",
6261
)
63-
tool_repository_username: Optional[str] = Field(
62+
tool_repository_username: str | None = Field(
6463
None, description="Username for interacting with the Tool Repository"
6564
)
66-
tool_repository_password: Optional[str] = Field(
65+
tool_repository_password: str | None = Field(
6766
None, description="Password for interacting with the Tool Repository"
6867
)
69-
org_name: Optional[str] = Field(
68+
org_name: str | None = Field(
7069
None, description="Name of the currently active organization"
7170
)
72-
org_uuid: Optional[str] = Field(
71+
org_uuid: str | None = Field(
7372
None, description="UUID of the currently active organization"
7473
)
7574
config_path: Path = Field(default=DEFAULT_CONFIG_PATH, frozen=True, exclude=True)
@@ -79,7 +78,7 @@ class Settings(BaseModel):
7978
default=DEFAULT_CLI_SETTINGS["oauth2_provider"],
8079
)
8180

82-
oauth2_audience: Optional[str] = Field(
81+
oauth2_audience: str | None = Field(
8382
description="OAuth2 audience value, typically used to identify the target API or resource.",
8483
default=DEFAULT_CLI_SETTINGS["oauth2_audience"],
8584
)

0 commit comments

Comments
 (0)