-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from JonatanMartens/development
1.2.0
- Loading branch information
Showing
19 changed files
with
283 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from grpc import ChannelCredentials | ||
|
||
|
||
class BaseCredentials(ABC): | ||
grpc_credentials: ChannelCredentials | ||
|
||
@abstractmethod | ||
def get_connection_uri(self) -> str: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pyzeebe.credentials.oauth_credentials import OAuthCredentials | ||
|
||
|
||
class CamundaCloudCredentials(OAuthCredentials): | ||
def __init__(self, client_id: str, client_secret: str, cluster_id: str): | ||
super().__init__(url="https://login.cloud.camunda.io/oauth/token", client_id=client_id, | ||
client_secret=client_secret, audience=f"{cluster_id}.zeebe.camunda.io") | ||
|
||
def get_connection_uri(self) -> str: | ||
return f"{self.audience}:443" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from unittest.mock import patch | ||
from uuid import uuid4 | ||
|
||
from pyzeebe.credentials.camunda_cloud_credentials import CamundaCloudCredentials | ||
|
||
|
||
def test_init(): | ||
client_id = str(uuid4()) | ||
client_secret = str(uuid4()) | ||
cluster_id = str(uuid4()) | ||
|
||
with patch("pyzeebe.credentials.oauth_credentials.OAuthCredentials.__init__") as init: | ||
CamundaCloudCredentials(client_id, client_secret, cluster_id) | ||
init.assert_called_with(url=f"https://login.cloud.camunda.io/oauth/token", client_id=client_id, | ||
client_secret=client_secret, audience=f"{cluster_id}.zeebe.camunda.io") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import grpc | ||
from oauthlib import oauth2 | ||
from requests_oauthlib import OAuth2Session | ||
|
||
from pyzeebe.credentials.base_credentials import BaseCredentials | ||
|
||
|
||
class OAuthCredentials(BaseCredentials): | ||
def __init__(self, url: str, client_id: str, client_secret: str, audience: str): | ||
self.url = url | ||
self.client_id = client_id | ||
self.client_secret = client_secret | ||
self.audience = audience | ||
|
||
self.access_token = self.get_access_token(url, client_id, client_secret, audience) | ||
token_credentials = grpc.access_token_call_credentials(self.access_token) | ||
ssl_credentials = grpc.ssl_channel_credentials() | ||
self.grpc_credentials = grpc.composite_channel_credentials(ssl_credentials, token_credentials) | ||
|
||
@staticmethod | ||
def get_access_token(url: str, client_id: str, client_secret: str, audience: str) -> str: | ||
client = oauth2.BackendApplicationClient(client_id) | ||
client.prepare_request_body(include_client_id=True) | ||
with OAuth2Session(client=client) as session: | ||
return session.post(url, | ||
data={ | ||
"client_id": client_id, | ||
"client_secret": client_secret, | ||
"audience": audience | ||
}).json()["access_token"] | ||
|
||
def get_connection_uri(self) -> str: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from unittest.mock import patch | ||
from uuid import uuid4 | ||
|
||
from pyzeebe.credentials.oauth_credentials import OAuthCredentials | ||
|
||
|
||
def test_get_access_token(): | ||
with patch('requests_oauthlib.OAuth2Session.post') as post_mock: | ||
url = f"https://{str(uuid4())}/oauth/token" | ||
client_id = str(uuid4()) | ||
client_secret = str(uuid4()) | ||
audience = str(uuid4()) | ||
OAuthCredentials.get_access_token(url=url, client_id=client_id, client_secret=client_secret, audience=audience) | ||
post_mock.assert_called_with(url, | ||
data={ | ||
'client_id': client_id, | ||
'client_secret': client_secret, | ||
'audience': audience | ||
}) |
Oops, something went wrong.