Skip to content

Commit

Permalink
Update OAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Nov 14, 2024
1 parent 42580b9 commit 61eb20e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/posit/connect/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/posit/connect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 12 additions & 8 deletions src/posit/connect/oauth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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())


Expand Down
10 changes: 0 additions & 10 deletions src/posit/connect/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
overload,
)

from ._types_content_item import ContentItemContext
from .context import Context

if TYPE_CHECKING:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 61eb20e

Please sign in to comment.