From f614740a508a14844d024b60b9da33eda9574a78 Mon Sep 17 00:00:00 2001 From: Taylor Steinberg Date: Wed, 28 Feb 2024 11:08:12 -0500 Subject: [PATCH] chore: applies formatting (#56) --- src/posit/connect/content_test.py | 94 ++++++++++++------------ src/posit/connect/external/databricks.py | 17 +++-- src/posit/connect/oauth.py | 9 +-- src/posit/connect/oauth_test.py | 12 +-- src/posit/connect/urls_test.py | 1 - src/posit/connect/users_test.py | 1 - 6 files changed, 63 insertions(+), 71 deletions(-) diff --git a/src/posit/connect/content_test.py b/src/posit/connect/content_test.py index b521caf4..4bee4cd2 100644 --- a/src/posit/connect/content_test.py +++ b/src/posit/connect/content_test.py @@ -4,7 +4,6 @@ class TestContents: - @responses.activate def test_get_all_content(self): responses.get( @@ -149,53 +148,52 @@ def test_get_all_content(self): ) responses.get( "https://connect.example/__api__/v1/content/f2f37341-e21d-3d80-c698-a935ad614066", - json= - { - "guid": "f2f37341-e21d-3d80-c698-a935ad614066", - "name": "Performance-Data-1671216053560", - "title": "Performance Data", - "description": "", - "access_type": "logged_in", - "connection_timeout": None, - "read_timeout": None, - "init_timeout": None, - "idle_timeout": None, - "max_processes": None, - "min_processes": None, - "max_conns_per_process": None, - "load_factor": None, - "memory_request": None, - "memory_limit": None, - "cpu_request": None, - "cpu_limit": None, - "amd_gpu_limit": None, - "nvidia_gpu_limit": None, - "service_account_name": None, - "default_image_name": None, - "created_time": "2022-12-16T18:40:53Z", - "last_deployed_time": "2024-02-24T09:56:30Z", - "bundle_id": "401171", - "app_mode": "quarto-static", - "content_category": "", - "parameterized": False, - "cluster_name": "Local", - "image_name": None, - "r_version": None, - "py_version": "3.9.17", - "quarto_version": "1.3.340", - "r_environment_management": None, - "default_r_environment_management": None, - "py_environment_management": True, - "default_py_environment_management": None, - "run_as": None, - "run_as_current_user": False, - "owner_guid": "87c12c08-11cd-4de1-8da3-12a7579c4998", - "content_url": "https://connect.example/content/f2f37341-e21d-3d80-c698-a935ad614066/", - "dashboard_url": "https://connect.example/connect/#/apps/f2f37341-e21d-3d80-c698-a935ad614066", - "app_role": "viewer", - "id": "8274", - } - ) + json={ + "guid": "f2f37341-e21d-3d80-c698-a935ad614066", + "name": "Performance-Data-1671216053560", + "title": "Performance Data", + "description": "", + "access_type": "logged_in", + "connection_timeout": None, + "read_timeout": None, + "init_timeout": None, + "idle_timeout": None, + "max_processes": None, + "min_processes": None, + "max_conns_per_process": None, + "load_factor": None, + "memory_request": None, + "memory_limit": None, + "cpu_request": None, + "cpu_limit": None, + "amd_gpu_limit": None, + "nvidia_gpu_limit": None, + "service_account_name": None, + "default_image_name": None, + "created_time": "2022-12-16T18:40:53Z", + "last_deployed_time": "2024-02-24T09:56:30Z", + "bundle_id": "401171", + "app_mode": "quarto-static", + "content_category": "", + "parameterized": False, + "cluster_name": "Local", + "image_name": None, + "r_version": None, + "py_version": "3.9.17", + "quarto_version": "1.3.340", + "r_environment_management": None, + "default_r_environment_management": None, + "py_environment_management": True, + "default_py_environment_management": None, + "run_as": None, + "run_as_current_user": False, + "owner_guid": "87c12c08-11cd-4de1-8da3-12a7579c4998", + "content_url": "https://connect.example/content/f2f37341-e21d-3d80-c698-a935ad614066/", + "dashboard_url": "https://connect.example/connect/#/apps/f2f37341-e21d-3d80-c698-a935ad614066", + "app_role": "viewer", + "id": "8274", + }, + ) con = Client("12345", "https://connect.example") all_content = con.content.find() assert len(all_content) == 3 diff --git a/src/posit/connect/external/databricks.py b/src/posit/connect/external/databricks.py index cce1a81d..da4e7265 100644 --- a/src/posit/connect/external/databricks.py +++ b/src/posit/connect/external/databricks.py @@ -7,12 +7,13 @@ HeaderFactory = Callable[[], Dict[str, str]] + # https://github.com/databricks/databricks-sdk-py/blob/v0.20.0/databricks/sdk/credentials_provider.py # https://github.com/databricks/databricks-sql-python/blob/v3.1.0/src/databricks/sql/auth/authenticators.py # In order to keep compatibility with the Databricks SDK class CredentialsProvider(abc.ABC): """CredentialsProvider is the protocol (call-side interface) - for authenticating requests to Databricks REST APIs""" + for authenticating requests to Databricks REST APIs""" @abc.abstractmethod def auth_type(self) -> str: @@ -33,8 +34,11 @@ def auth_type(self) -> str: def __call__(self, *args, **kwargs) -> HeaderFactory: def inner() -> Dict[str, str]: - access_token = self.posit_oauth.get_credentials(self.user_session_token)['access_token'] + access_token = self.posit_oauth.get_credentials(self.user_session_token)[ + "access_token" + ] return {"Authorization": f"Bearer {access_token}"} + return inner @@ -44,8 +48,9 @@ def is_local() -> bool: return not os.getenv("RSTUDIO_PRODUCT") == "CONNECT" -def viewer_credentials_provider(client: Optional[Client] = None, user_session_token: Optional[str] = None) -> Optional[CredentialsProvider]: - +def viewer_credentials_provider( + client: Optional[Client] = None, user_session_token: Optional[str] = None +) -> Optional[CredentialsProvider]: # If the content is not running on Connect then viewer auth should # fall back to the locally configured credentials hierarchy if is_local(): @@ -57,7 +62,9 @@ def viewer_credentials_provider(client: Optional[Client] = None, user_session_to # If the user-session-token wasn't provided and we're running on Connect then we raise an exception. # user_session_token is required to impersonate the viewer. if user_session_token is None: - raise ValueError("The user-session-token is required for viewer authentication.") + raise ValueError( + "The user-session-token is required for viewer authentication." + ) return PositOAuthIntegrationCredentialsProvider(client.oauth, user_session_token) diff --git a/src/posit/connect/oauth.py b/src/posit/connect/oauth.py index 9fecdb40..958c4089 100644 --- a/src/posit/connect/oauth.py +++ b/src/posit/connect/oauth.py @@ -14,17 +14,12 @@ class Credentials(TypedDict, total=False): class OAuthIntegration: - - def __init__( - self, config: Config, session: Session - ) -> None: + def __init__(self, config: Config, session: Session) -> None: self.url = urls.append_path(config.url, "v1/oauth/integrations/credentials") self.config = config self.session = session - - def get_credentials(self, user_session_token: Optional[str]=None) -> Credentials: - + def get_credentials(self, user_session_token: Optional[str] = None) -> Credentials: # craft a basic credential exchange request where the self.config.api_key owner # is requesting their own credentials data = dict() diff --git a/src/posit/connect/oauth_test.py b/src/posit/connect/oauth_test.py index f81389b3..f213b15c 100644 --- a/src/posit/connect/oauth_test.py +++ b/src/posit/connect/oauth_test.py @@ -2,8 +2,8 @@ from .client import Client -class TestOAuthIntegrations: +class TestOAuthIntegrations: @responses.activate def test_get_credentials(self): responses.post( @@ -41,11 +41,5 @@ def test_get_credentials(self): }, ) con = Client(api_key="12345", url="https://connect.example/") - assert ( - con.oauth.get_credentials()["access_token"] - == "sdk-user-token" - ) - assert ( - con.oauth.get_credentials("cit")["access_token"] - == "viewer-token" - ) + assert con.oauth.get_credentials()["access_token"] == "sdk-user-token" + assert con.oauth.get_credentials("cit")["access_token"] == "viewer-token" diff --git a/src/posit/connect/urls_test.py b/src/posit/connect/urls_test.py index 12adc6d4..b561bf40 100644 --- a/src/posit/connect/urls_test.py +++ b/src/posit/connect/urls_test.py @@ -32,4 +32,3 @@ def test_validate_without_scheme(): def test_validate_without_netloc(): with pytest.raises(ValueError): validate("http:///__api__") - diff --git a/src/posit/connect/users_test.py b/src/posit/connect/users_test.py index a42d4230..28385c74 100644 --- a/src/posit/connect/users_test.py +++ b/src/posit/connect/users_test.py @@ -5,7 +5,6 @@ class TestUsers: - @responses.activate def test_get_users(self): responses.get(