Skip to content

Commit

Permalink
Merge pull request #514 from felicijus/bug/510-fix-create-camunda-clo…
Browse files Browse the repository at this point in the history
…ud-channel

fix: create_camunda_cloud_channel
  • Loading branch information
dimastbk authored Oct 11, 2024
2 parents 9e1cf7b + 1fdf406 commit 0447086
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
8 changes: 4 additions & 4 deletions pyzeebe/channel/camunda_cloud_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def _create_camunda_cloud_credentials(
) -> grpc.ChannelCredentials:
try:
access_token = _get_access_token(
"https://login.cloud.camunda.io/oauth/token",
client_id,
client_secret,
f"{cluster_id}.{region}.zeebe.camunda.io",
url="https://login.cloud.camunda.io/oauth/token",
client_id=client_id,
client_secret=client_secret,
audience="zeebe.camunda.io",
)
return _create_oauth_credentials(access_token)
except InvalidOAuthCredentialsError as oauth_error:
Expand Down
6 changes: 3 additions & 3 deletions pyzeebe/channel/oauth_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def create_camunda_cloud_channel(
client_secret: str,
cluster_id: str,
region: str = "bru-2",
scope: str = "Zeebe",
authorization_server: str = "https://login.cloud.camunda.io/oauth/token",
audience: str = "zeebe.camunda.io",
scope: str | None = None,
audience: str | None = "zeebe.camunda.io",
channel_credentials: grpc.ChannelCredentials | None = None,
channel_options: ChannelArgumentType | None = None,
leeway: int = 60,
Expand All @@ -96,10 +96,10 @@ def create_camunda_cloud_channel(
client_secret (str): The client secret.
cluster_id (str): The ID of the cluster to connect to.
region (Optional[str]): The region of the cluster. Defaults to "bru-2".
scope (Optional[str]): The scope of the access request. Defaults to "Zeebe".
authorization_server (Optional[str]): The authorization server issuing access tokens
to the client after successfully authenticating the client.
Defaults to "https://login.cloud.camunda.io/oauth/token".
scope (Optional[str]): The scope of the access request. Can be set to CAMUNDA_CLUSTER_ID. Defaults to None.
audience (Optional[str]): The audience for authentication. Defaults to "zeebe.camunda.io".
channel_credentials (grpc.ChannelCredentials): The gRPC channel credentials.
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/channel/camunda_cloud_channel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def test_gets_access_token_using_correct_parameters(
cluster_id: str,
region: str,
):
expected_request_body = (
f"client_id={client_id}&client_secret={client_secret}&audience={cluster_id}.{region}.zeebe.camunda.io"
)
expected_request_body = f"client_id={client_id}&client_secret={client_secret}&audience=zeebe.camunda.io"

create_camunda_cloud_channel(client_id, client_secret, cluster_id, region)

Expand Down
30 changes: 27 additions & 3 deletions tests/unit/channel/oauth_channel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ def test_create_oauth2_client_credentials_channel(
client_id = "client_id"
client_secret = "client_secret"
authorization_server = "https://authorization.server"
channel = create_oauth2_client_credentials_channel(grpc_address, client_id, client_secret, authorization_server)
scope = "scope"
audience = "audience"

channel = create_oauth2_client_credentials_channel(
grpc_address=grpc_address,
client_id=client_id,
client_secret=client_secret,
authorization_server=authorization_server,
scope=scope,
audience=audience,
channel_credentials=None,
channel_options=None,
leeway=60,
expire_in=None,
)

assert isinstance(channel, grpc.aio.Channel)

Expand All @@ -35,12 +49,22 @@ def test_create_camunda_cloud_channel(
client_secret = "client_secret"
cluster_id = "cluster_id"
region = "bru-2"
scope = "Zeebe"
authorization_server = "https://login.cloud.camunda.io/oauth/token"
scope = None
audience = "zeebe.camunda.io"

channel = create_camunda_cloud_channel(
client_id, client_secret, cluster_id, region, scope, authorization_server, audience
client_id=client_id,
client_secret=client_secret,
cluster_id=cluster_id,
region=region,
authorization_server=authorization_server,
scope=scope,
audience=audience,
channel_credentials=None,
channel_options=None,
leeway=60,
expire_in=None,
)

assert isinstance(channel, grpc.aio.Channel)

0 comments on commit 0447086

Please sign in to comment.