Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions linode_api4/login_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ def __repr__(self):
return "images:*"
return "images:{}".format(self.name)

class Databases(Enum):
"""
Access to Managed Databases
"""

read_only = 0
read_write = 1
all = 2

def __repr__(self):
if self.name == "all":
return "databases:*"
return "databases:{}".format(self.name)

class VPC(Enum):
"""
Access to VPCs and subnets
"""
Comment thread
zliang-akamai marked this conversation as resolved.

read_write = 1
all = 2

def __repr__(self):
if self.name == "all":
return "vpc:*"
return "vpc:{}".format(self.name)

_scope_families = {
"linodes": Linodes,
"domains": Domains,
Expand All @@ -286,6 +313,8 @@ def __repr__(self):
"nodebalancers": NodeBalancers,
"longview": Longview,
"images": Images,
"databases": Databases,
"vpc": VPC,
}

@staticmethod
Expand Down
18 changes: 18 additions & 0 deletions test/unit/login_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,21 @@ def test_parse_scopes_all(self):
scopes,
[getattr(c, "all") for c in OAuthScopes._scope_families.values()],
)

def test_parse_scopes_databases_and_vpc(self):
"""
Tests parsing documented databases and vpc scopes
"""
scopes = OAuthScopes.parse(
"databases:read_only,databases:read_write,vpc:read_write,vpc:*"
)
Comment thread
zliang-akamai marked this conversation as resolved.
self.assertEqual(
scopes,
[
OAuthScopes.Databases.read_only,
OAuthScopes.Databases.read_write,
OAuthScopes.VPC.read_write,
OAuthScopes.VPC.all,
],
)
self.assertEqual(OAuthScopes.parse("vpc:read_only"), [])