From 61eb20e6dd96fc80b8a469c3f733df04b7cef154 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 14 Nov 2024 04:09:55 -0500 Subject: [PATCH] Update OAuth --- src/posit/connect/bundles.py | 3 +-- src/posit/connect/client.py | 2 +- src/posit/connect/oauth/oauth.py | 20 ++++++++++++-------- src/posit/connect/resources.py | 10 ---------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/posit/connect/bundles.py b/src/posit/connect/bundles.py index 7a7fbf29..50c2baf0 100644 --- a/src/posit/connect/bundles.py +++ b/src/posit/connect/bundles.py @@ -5,11 +5,10 @@ import io from typing import List -from posit.connect._types_context import ContextP - from ._active import ActiveDict, ReadOnlyDict from ._api_call import ApiCallMixin, get_api_stream, post_api from ._types_content_item import ContentItemContext +from ._types_context import ContextP from .tasks import Task, Tasks diff --git a/src/posit/connect/client.py b/src/posit/connect/client.py index e1ed577e..f3069a59 100644 --- a/src/posit/connect/client.py +++ b/src/posit/connect/client.py @@ -268,7 +268,7 @@ def oauth(self) -> OAuth: OAuth The oauth API instance. """ - return OAuth(self.resource_params, self.cfg.api_key) + return OAuth(self._ctx, self.cfg.api_key) @property @requires(version="2024.10.0-dev") diff --git a/src/posit/connect/oauth/oauth.py b/src/posit/connect/oauth/oauth.py index 6784db89..32341414 100644 --- a/src/posit/connect/oauth/oauth.py +++ b/src/posit/connect/oauth/oauth.py @@ -4,26 +4,30 @@ from typing_extensions import TypedDict -from ..resources import ResourceParameters, Resources, resource_parameters_to_context +from .._types_context import ContextP +from ..context import Context from .integrations import Integrations from .sessions import Sessions -class OAuth(Resources): - def __init__(self, params: ResourceParameters, api_key: str) -> None: - super().__init__(params) +class OAuth(ContextP[Context]): + def __init__(self, ctx: Context, api_key: str) -> None: + super().__init__() + self._ctx = ctx + + # TODO-barret-q: Is this used? self.api_key = api_key @property def integrations(self): - return Integrations(resource_parameters_to_context(self.params)) + return Integrations(self._ctx) @property def sessions(self): - return Sessions(resource_parameters_to_context(self.params)) + return Sessions(self._ctx) def get_credentials(self, user_session_token: Optional[str] = None) -> Credentials: - url = self.params.url + "v1/oauth/integrations/credentials" + url = self._ctx.url + "v1/oauth/integrations/credentials" # craft a credential exchange request data = {} @@ -32,7 +36,7 @@ def get_credentials(self, user_session_token: Optional[str] = None) -> Credentia if user_session_token: data["subject_token"] = user_session_token - response = self.params.session.post(url, data=data) + response = self._ctx.session.post(url, data=data) return Credentials(**response.json()) diff --git a/src/posit/connect/resources.py b/src/posit/connect/resources.py index e99c4926..160a579a 100644 --- a/src/posit/connect/resources.py +++ b/src/posit/connect/resources.py @@ -16,7 +16,6 @@ overload, ) -from ._types_content_item import ContentItemContext from .context import Context if TYPE_CHECKING: @@ -53,15 +52,6 @@ def resource_parameters_to_context(params: ResourceParameters) -> Context: return Context(params.session, params.url) -def resource_parameters_to_content_item_context( - params: ResourceParameters, - content_guid: str, -) -> ContentItemContext: - """Temp method to aid in transitioning from `ResourceParameters` to `Context`.""" - ctx = Context(params.session, params.url) - return ContentItemContext(ctx, content_guid=content_guid) - - class Resource(dict): def __init__(self, /, params: ResourceParameters, **kwargs): self.params = params