Skip to content

Commit 4f3098d

Browse files
committed
feat: remove attributes from oauth resources
1 parent 2cd8fe6 commit 4f3098d

File tree

4 files changed

+20
-128
lines changed

4 files changed

+20
-128
lines changed

src/posit/connect/oauth/integrations.py

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,13 @@
66

77

88
class Integration(Resource):
9-
"""OAuth integration resource.
10-
11-
Attributes
12-
----------
13-
id : str
14-
The internal numeric identifier of this OAuth integration.
15-
guid : str
16-
The unique identifier of this OAuth integration which is used in REST API requests.
17-
name : str
18-
A descriptive name to identify each OAuth integration.
19-
description : Optional[str]
20-
A brief text to describe each OAuth integration
21-
template : str
22-
The template to use to configure this OAuth integration.
23-
config : dict
24-
The OAuth integration configuration based on the template.
25-
created_time : str
26-
The timestamp (RFC3339) indicating when this OAuth integration was created.
27-
updated_time : str
28-
The timestamp (RFC3339) indicating when this OAuth integration was last updated.
29-
"""
30-
31-
# CRUD Methods
9+
"""OAuth integration resource."""
3210

3311
def delete(self) -> None:
3412
"""Delete the OAuth integration."""
35-
path = f"v1/oauth/integrations/{self.guid}"
36-
url = self.url + path
37-
self.session.delete(url)
13+
path = f"v1/oauth/integrations/{self['guid']}"
14+
url = self.params.url + path
15+
self.params.session.delete(url)
3816

3917
@overload
4018
def update(
@@ -63,44 +41,10 @@ def update(self, *args, **kwargs) -> None:
6341
def update(self, *args, **kwargs) -> None:
6442
"""Update the OAuth integration."""
6543
body = dict(*args, **kwargs)
66-
url = self.url + f"v1/oauth/integrations/{self.guid}"
67-
response = self.session.patch(url, json=body)
44+
url = self.params.url + f"v1/oauth/integrations/{self['guid']}"
45+
response = self.params.session.patch(url, json=body)
6846
super().update(**response.json())
6947

70-
# Properties
71-
72-
@property
73-
def id(self) -> str:
74-
return self.get("id") # type: ignore
75-
76-
@property
77-
def guid(self) -> str:
78-
return self.get("guid") # type: ignore
79-
80-
@property
81-
def name(self) -> str:
82-
return self.get("name") # type: ignore
83-
84-
@property
85-
def description(self) -> Optional[str]:
86-
return self.get("description") # type: ignore
87-
88-
@property
89-
def template(self) -> str:
90-
return self.get("template") # type: ignore
91-
92-
@property
93-
def config(self) -> dict:
94-
return self.get("config") # type: ignore
95-
96-
@property
97-
def created_time(self) -> str:
98-
return self.get("created_time") # type: ignore
99-
100-
@property
101-
def updated_time(self) -> str:
102-
return self.get("updated_time") # type: ignore
103-
10448

10549
class Integrations(Resources):
10650
"""Integrations resource."""
@@ -155,8 +99,8 @@ def create(self, **kwargs) -> Integration:
15599
"""
156100
...
157101
path = "v1/oauth/integrations"
158-
url = self.url + path
159-
response = self.session.post(url, json=kwargs)
102+
url = self.params.url + path
103+
response = self.params.session.post(url, json=kwargs)
160104
return Integration(self.params, **response.json())
161105

162106
def find(self) -> List[Integration]:
@@ -167,9 +111,9 @@ def find(self) -> List[Integration]:
167111
List[Integration]
168112
"""
169113
path = "v1/oauth/integrations"
170-
url = self.url + path
114+
url = self.params.url + path
171115

172-
response = self.session.get(url)
116+
response = self.params.session.get(url)
173117
return [
174118
Integration(
175119
self.params,
@@ -190,6 +134,6 @@ def get(self, guid: str) -> Integration:
190134
Integration
191135
"""
192136
path = f"v1/oauth/integrations/{guid}"
193-
url = self.url + path
194-
response = self.session.get(url)
137+
url = self.params.url + path
138+
response = self.params.session.get(url)
195139
return Integration(self.params, **response.json())

src/posit/connect/oauth/oauth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_credentials(
3232
if user_session_token:
3333
data["subject_token"] = user_session_token
3434

35-
response = self.session.post(url, data=data)
35+
response = self.params.session.post(url, data=data)
3636
return Credentials(**response.json())
3737

3838

src/posit/connect/oauth/sessions.py

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,12 @@
66

77

88
class Session(Resource):
9-
"""OAuth session resource.
10-
11-
Attributes
12-
----------
13-
id : str
14-
The internal numeric identifier of this OAuth session.
15-
guid : str
16-
The unique identifier of this OAuth session which is used in REST API requests.
17-
user_guid : str
18-
The unique identifier of the user that is associatid with this OAuth session.
19-
oauth_integration_guid : str
20-
The unique identifier of the OAuth integration that is associated with this OAuth session.
21-
has_refresh_token : bool
22-
Indicates whether this OAuth session has a refresh token.
23-
created_time : str
24-
The timestamp (RFC3339) indicating when this OAuth session was created.
25-
updated_time : str
26-
The timestamp (RFC3339) indicating when this OAuth session was last updated.
27-
"""
28-
29-
# Properties
30-
31-
@property
32-
def id(self) -> str:
33-
return self.get("id") # type: ignore
34-
35-
@property
36-
def guid(self) -> str:
37-
return self.get("guid") # type: ignore
38-
39-
@property
40-
def user_guid(self) -> str:
41-
return self.get("user_guid") # type: ignore
42-
43-
@property
44-
def oauth_integration_guid(self) -> str:
45-
return self.get("oauth_integration_guid") # type: ignore
46-
47-
@property
48-
def has_refresh_token(self) -> bool:
49-
return self.get("has_refresh_token") # type: ignore
50-
51-
@property
52-
def created_time(self) -> str:
53-
return self.get("created_time") # type: ignore
54-
55-
@property
56-
def updated_time(self) -> str:
57-
return self.get("updated_time") # type: ignore
58-
59-
# CRUD Methods
9+
"""OAuth session resource."""
6010

6111
def delete(self) -> None:
62-
path = f"v1/oauth/sessions/{self.guid}"
63-
url = self.url + path
64-
self.session.delete(url)
12+
path = f"v1/oauth/sessions/{self['guid']}"
13+
url = self.params.url + path
14+
self.params.session.delete(url)
6515

6616

6717
class Sessions(Resources):
@@ -77,7 +27,7 @@ def find(self, **kwargs) -> List[Session]: ...
7727

7828
def find(self, **kwargs) -> List[Session]:
7929
url = self.params.url + "v1/oauth/sessions"
80-
response = self.session.get(url, params=kwargs)
30+
response = self.params.session.get(url, params=kwargs)
8131
results = response.json()
8232
return [Session(self.params, **result) for result in results]
8333

@@ -93,6 +43,6 @@ def get(self, guid: str) -> Session:
9343
Session
9444
"""
9545
path = f"v1/oauth/sessions/{guid}"
96-
url = self.url + path
97-
response = self.session.get(url)
46+
url = self.params.url + path
47+
response = self.params.session.get(url)
9848
return Session(self.params, **response.json())

src/posit/connect/resources.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,3 @@ def update(self, *args, **kwargs):
4343
class Resources:
4444
def __init__(self, params: ResourceParameters) -> None:
4545
self.params = params
46-
self.session = params.session
47-
self.url = params.url

0 commit comments

Comments
 (0)