-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): implement basic admin user scopes
- Loading branch information
1 parent
53d6f3e
commit d8cbe6d
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
from typing import Set | ||
|
||
|
||
class AdminRole(Enum): | ||
ADMIN = "admin" | ||
MEMBER = "member" | ||
MEMBER_READ = "member_read" | ||
|
||
|
||
ADMIN_CATEGORY_RESOURCES = { | ||
# clickhouse migrations | ||
"migrations.all", | ||
"migrations.system", | ||
"migrations.generic_metrics", | ||
"migrations.profiles", | ||
"migrations.functions", | ||
"migrations.replays", | ||
"migrations.querylog", | ||
"migrations.test_migration", | ||
} | ||
|
||
|
||
@dataclass(frozen=True) | ||
class AuthScope: | ||
category: str | ||
resource: str | ||
role: AdminRole | ||
|
||
def to_str(self) -> str: | ||
return f"{self.category}.{self.resource}.{self.role.value}" | ||
|
||
|
||
def scopes() -> Set[AuthScope]: | ||
scopes = set() | ||
for item in ADMIN_CATEGORY_RESOURCES: | ||
category, resource = item.split(".") | ||
scopes.update([AuthScope(category, resource, role) for role in AdminRole]) | ||
return scopes | ||
|
||
|
||
ADMIN_SCOPES = scopes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters