Skip to content

Commit 280efee

Browse files
TPT-4623: Add databases and vpc OAuth scopes (#734)
* Add databases and vpc OAuth scopes * Fix doc
1 parent bda548e commit 280efee

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

linode_api4/login_client.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ class OAuthScopes:
3030
Lists of OAuth Scopes are accepted when calling the :any:`generate_login_url`
3131
method of the :any:`LinodeLoginClient`.
3232
33-
All contained enumerations of OAuth Scopes have two levels, "read_only" and
33+
Most contained enumerations of OAuth Scopes have two levels, "read_only" and
3434
"read_write". "read_only" access grants you the ability to get resources and
3535
of that type, but not to change, create, or delete them. "read_write" access
36-
allows to full access to resources of the requested type. In the above
36+
allows to full access to resources of the requested type. :any:`OAuthScopes.VPC`
37+
is the exception and exposes only "read_write" and "all". In the above
3738
example, you are requesting access to view, modify, create, and delete
3839
Linodes, and to view Domains.
3940
"""
@@ -268,6 +269,33 @@ def __repr__(self):
268269
return "images:*"
269270
return "images:{}".format(self.name)
270271

272+
class Databases(Enum):
273+
"""
274+
Access to Managed Databases
275+
"""
276+
277+
read_only = 0
278+
read_write = 1
279+
all = 2
280+
281+
def __repr__(self):
282+
if self.name == "all":
283+
return "databases:*"
284+
return "databases:{}".format(self.name)
285+
286+
class VPC(Enum):
287+
"""
288+
Access to VPCs and subnets
289+
"""
290+
291+
read_write = 1
292+
all = 2
293+
294+
def __repr__(self):
295+
if self.name == "all":
296+
return "vpc:*"
297+
return "vpc:{}".format(self.name)
298+
271299
_scope_families = {
272300
"linodes": Linodes,
273301
"domains": Domains,
@@ -286,6 +314,8 @@ def __repr__(self):
286314
"nodebalancers": NodeBalancers,
287315
"longview": Longview,
288316
"images": Images,
317+
"databases": Databases,
318+
"vpc": VPC,
289319
}
290320

291321
@staticmethod

test/unit/login_client_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,21 @@ def test_parse_scopes_all(self):
5353
scopes,
5454
[getattr(c, "all") for c in OAuthScopes._scope_families.values()],
5555
)
56+
57+
def test_parse_scopes_databases_and_vpc(self):
58+
"""
59+
Tests parsing documented databases and vpc scopes
60+
"""
61+
scopes = OAuthScopes.parse(
62+
"databases:read_only,databases:read_write,vpc:read_write,vpc:*"
63+
)
64+
self.assertEqual(
65+
scopes,
66+
[
67+
OAuthScopes.Databases.read_only,
68+
OAuthScopes.Databases.read_write,
69+
OAuthScopes.VPC.read_write,
70+
OAuthScopes.VPC.all,
71+
],
72+
)
73+
self.assertEqual(OAuthScopes.parse("vpc:read_only"), [])

0 commit comments

Comments
 (0)