Skip to content

Commit

Permalink
fix: run pre-commit, replace OSError with ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Dec 6, 2024
1 parent 601129d commit 1f6b7e9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
75 changes: 37 additions & 38 deletions docs/channels_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Common Variables
This variables is used across all types of channels:

**ZEEBE_ADDRESS**
:Description:
:Description:
The default address of the Zeebe Gateway.
:Usage:

:Usage:
Used in both secure and insecure channel configurations.
:func:`pyzeebe.create_insecure_channel`
:func:`pyzeebe.create_secure_channel`
:Default:

:Default:
``"localhost:26500"``

Common OAuth2 Variables
Expand All @@ -34,19 +34,19 @@ Common OAuth2 Variables
These variables are specifically for connecting to generic OAuth2 or Camunda Cloud instances.

**CAMUNDA_CLIENT_ID** / **ZEEBE_CLIENT_ID**
:Description:
:Description:
The client ID required for OAuth2 client credential authentication.
:Usage:

:Usage:
Required for OAuth2 and Camunda Cloud channels.
:func:`pyzeebe.create_oauth2_client_credentials_channel`
:func:`pyzeebe.create_camunda_cloud_channel`

**CAMUNDA_CLIENT_SECRET** / **ZEEBE_CLIENT_SECRET**
:Description:
:Description:
The client secret for the OAuth2 client.
:Usage:

:Usage:
Required for OAuth2 and Camunda Cloud channels.
:func:`pyzeebe.create_oauth2_client_credentials_channel`
:func:`pyzeebe.create_camunda_cloud_channel`
Expand All @@ -57,22 +57,22 @@ OAuth2 Variables (Self-Managed)
These variables are primarily used for OAuth2 authentication in self-managed Camunda 8 instances.

**CAMUNDA_OAUTH_URL** / **ZEEBE_AUTHORIZATION_SERVER_URL**
:Description:
:Description:
Specifies the URL of the authorization server issuing access tokens to the client.
:Usage:

:Usage:
Required if channel initialization argument was not specified.
:func:`pyzeebe.create_oauth2_client_credentials_channel`

**CAMUNDA_TOKEN_AUDIENCE** / **ZEEBE_TOKEN_AUDIENCE**
:Description:
:Description:
Specifies the audience for the OAuth2 token.
:Usage:

:Usage:
Used when creating OAuth2 or Camunda Cloud channels.
:func:`pyzeebe.create_oauth2_client_credentials_channel`
:Default:

:Default:
``None`` if not provided.

Camunda Cloud Variables (SaaS)
Expand All @@ -81,43 +81,42 @@ Camunda Cloud Variables (SaaS)
These variables are specifically for connecting to Camunda Cloud instances.

**CAMUNDA_OAUTH_URL** / **ZEEBE_AUTHORIZATION_SERVER_URL**
:Description:
:Description:
Specifies the URL of the authorization server issuing access tokens to the client.
:Usage:

:Usage:
Used in the OAuth2 and Camunda Cloud channel configurations.
:func:`pyzeebe.create_camunda_cloud_channel`
:Default:

:Default:
``"https://login.cloud.camunda.io/oauth/token"`` if not specified.

**CAMUNDA_CLUSTER_ID**
:Description:
:Description:
The unique identifier for the Camunda Cloud cluster to connect to.
:Usage:

:Usage:
Required if channel initialization argument was not specified.
:func:`pyzeebe.create_camunda_cloud_channel`

**CAMUNDA_CLUSTER_REGION**
:Description:
:Description:
The region where the Camunda Cloud cluster is hosted.
:Usage:

:Usage:
Required for Camunda Cloud channels.
:func:`pyzeebe.create_camunda_cloud_channel`
:Default:

:Default:
``"bru-2"`` if not provided.

**CAMUNDA_TOKEN_AUDIENCE** / **ZEEBE_TOKEN_AUDIENCE**
:Description:
:Description:
Specifies the audience for the OAuth2 token.
:Usage:

:Usage:
Used when creating OAuth2 or Camunda Cloud channels.
:func:`pyzeebe.create_camunda_cloud_channel`

:Default:
``"zeebe.camunda.io"`` if not provided.

:Default:
``"zeebe.camunda.io"`` if not provided.
12 changes: 6 additions & 6 deletions pyzeebe/channel/oauth_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create_oauth2_client_credentials_channel(
authorization_server: str = Unset,
scope: str | None = Unset,
audience: str | None = Unset,
channel_credentials: grpc.ChannelCredentials = grpc.ssl_channel_credentials(),
channel_credentials: grpc.ChannelCredentials | None = None,
channel_options: ChannelArgumentType | None = None,
leeway: int = 60,
expire_in: int | None = None,
Expand All @@ -52,8 +52,8 @@ def create_oauth2_client_credentials_channel(
audience (str | None, optional): The audience for authentication.
Defaults to value from CAMUNDA_TOKEN_AUDIENCE or ZEEBE_TOKEN_AUDIENCE environment variable
channel_credentials (grpc.ChannelCredentials): The gRPC channel credentials.
Defaults to grpc.ssl_channel_credentials().
channel_credentials (grpc.ChannelCredentials | None): The gRPC channel credentials.
Defaults to `grpc.ssl_channel_credentials`.
channel_options (ChannelArgumentType | None): Additional options for the gRPC channel.
Defaults to None.
See https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments
Expand Down Expand Up @@ -120,7 +120,7 @@ def create_camunda_cloud_channel(
authorization_server: str = Unset,
scope: str | None = Unset,
audience: str | None = Unset,
channel_credentials: grpc.ChannelCredentials = grpc.ssl_channel_credentials(),
channel_credentials: grpc.ChannelCredentials | None = None,
channel_options: ChannelArgumentType | None = None,
leeway: int = 60,
expire_in: int | None = None,
Expand All @@ -147,8 +147,8 @@ def create_camunda_cloud_channel(
or ZEEBE_TOKEN_AUDIENCE environment variable
or "zeebe.camunda.io".
channel_credentials (grpc.ChannelCredentials): The gRPC channel credentials.
Defaults to grpc.ssl_channel_credentials().
channel_credentials (grpc.ChannelCredentials | None): The gRPC channel credentials.
Defaults to `grpc.ssl_channel_credentials`.
channel_options (ChannelArgumentType | None): Additional options for the gRPC channel.
Defaults to None.
See https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments
Expand Down
28 changes: 14 additions & 14 deletions pyzeebe/channel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def get_camunda_oauth_url(default: str | None = None) -> str:
str: CAMUNDA_OAUTH_URL or ZEEBE_AUTHORIZATION_SERVER_URL environment variable or provided default
Raises:
EnvironmentError: If neither CAMUNDA_OAUTH_URL nor ZEEBE_AUTHORIZATION_SERVER_URL is provided.
ValueError: If neither CAMUNDA_OAUTH_URL nor ZEEBE_AUTHORIZATION_SERVER_URL is provided.
"""
r = os.getenv("CAMUNDA_OAUTH_URL") or os.getenv("ZEEBE_AUTHORIZATION_SERVER_URL") or default

if r is None:
raise EnvironmentError("No CAMUNDA_OAUTH_URL or ZEEBE_AUTHORIZATION_SERVER_URL provided!")
raise ValueError("No CAMUNDA_OAUTH_URL or ZEEBE_AUTHORIZATION_SERVER_URL provided!")

return r

Expand All @@ -47,12 +47,12 @@ def get_camunda_client_id() -> str:
str: CAMUNDA_CLIENT_ID or ZEEBE_CLIENT_ID environment variable
Raises:
EnvironmentError: If neither CAMUNDA_CLIENT_ID nor ZEEBE_CLIENT_ID is provided.
ValueError: If neither CAMUNDA_CLIENT_ID nor ZEEBE_CLIENT_ID is provided.
"""
r = os.getenv("CAMUNDA_CLIENT_ID") or os.getenv("ZEEBE_CLIENT_ID")

if r is None:
raise EnvironmentError("No CAMUNDA_CLIENT_ID or ZEEBE_CLIENT_ID provided!")
raise ValueError("No CAMUNDA_CLIENT_ID or ZEEBE_CLIENT_ID provided!")

return r

Expand All @@ -65,12 +65,12 @@ def get_camunda_client_secret() -> str:
str: CAMUNDA_CLIENT_SECRET or ZEEBE_CLIENT_SECRET environment variable
Raises:
EnvironmentError: If neither CAMUNDA_CLIENT_SECRET nor ZEEBE_CLIENT_SECRET is provided.
ValueError: If neither CAMUNDA_CLIENT_SECRET nor ZEEBE_CLIENT_SECRET is provided.
"""
r = os.getenv("CAMUNDA_CLIENT_SECRET") or os.getenv("ZEEBE_CLIENT_SECRET")

if r is None:
raise EnvironmentError("No CAMUNDA_CLIENT_SECRET or ZEEBE_CLIENT_SECRET provided!")
raise ValueError("No CAMUNDA_CLIENT_SECRET or ZEEBE_CLIENT_SECRET provided!")

return r

Expand All @@ -83,12 +83,12 @@ def get_camunda_cluster_id() -> str:
str: CAMUNDA_CLUSTER_ID environment variable
Raises:
EnvironmentError: If CAMUNDA_CLUSTER_ID is not provided.
ValueError: If CAMUNDA_CLUSTER_ID is not provided.
"""
r = os.getenv("CAMUNDA_CLUSTER_ID")

if r is None:
raise EnvironmentError("No CAMUNDA_CLUSTER_ID provided!")
raise ValueError("No CAMUNDA_CLUSTER_ID provided!")

return r

Expand All @@ -104,12 +104,12 @@ def get_camunda_cluster_region(default: str | None = None) -> str:
str: CAMUNDA_CLUSTER_REGION environment variable or provided default
Raises:
EnvironmentError: If CAMUNDA_CLUSTER_REGION is not provided.
ValueError: If CAMUNDA_CLUSTER_REGION is not provided.
"""
r = os.getenv("CAMUNDA_CLUSTER_REGION") or default

if r is None:
raise EnvironmentError("No CAMUNDA_CLUSTER_REGION provided!")
raise ValueError("No CAMUNDA_CLUSTER_REGION provided!")

return r

Expand All @@ -125,12 +125,12 @@ def get_camunda_token_audience(default: str | None = None) -> str:
str: CAMUNDA_TOKEN_AUDIENCE or ZEEBE_TOKEN_AUDIENCE environment variable or provided default
Raises:
EnvironmentError: If neither CAMUNDA_TOKEN_AUDIENCE nor ZEEBE_TOKEN_AUDIENCE is provided.
ValueError: If neither CAMUNDA_TOKEN_AUDIENCE nor ZEEBE_TOKEN_AUDIENCE is provided.
"""
r = os.getenv("CAMUNDA_TOKEN_AUDIENCE") or os.getenv("ZEEBE_TOKEN_AUDIENCE") or default

if r is None:
raise EnvironmentError("No CAMUNDA_TOKEN_AUDIENCE or ZEEBE_TOKEN_AUDIENCE provided!")
raise ValueError("No CAMUNDA_TOKEN_AUDIENCE or ZEEBE_TOKEN_AUDIENCE provided!")

return r

Expand All @@ -147,9 +147,9 @@ def get_camunda_address(cluster_id: str | None = None, cluster_region: str | Non
str: The Camunda Cloud gRPC server address.
Raises:
EnvironmentError: If either cluster_id or cluster_region is not provided.
ValueError: If either cluster_id or cluster_region is not provided.
"""
if (cluster_id is None) or (cluster_region is None):
raise EnvironmentError("The cluster_id and cluster_region must be provided!")
raise ValueError("The cluster_id and cluster_region must be provided!")

return f"{cluster_id}.{cluster_region}.zeebe.camunda.io:443"
2 changes: 1 addition & 1 deletion pyzeebe/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

Headers: TypeAlias = Mapping[str, Any]
Variables: TypeAlias = Mapping[str, Any]
Unset = str("UNSET")
Unset = "UNSET"

ChannelArgumentType: TypeAlias = Sequence[tuple[str, Any]]

0 comments on commit 1f6b7e9

Please sign in to comment.