Handle Gitea all token scope
This commit is contained in:
@@ -65,6 +65,11 @@ SCOPE_FIELDS = [
|
||||
("u", "user"),
|
||||
]
|
||||
|
||||
SCOPE_CATEGORY_ALIASES = {
|
||||
"organization": ["organization", "org"],
|
||||
"repository": ["repository", "repo"],
|
||||
}
|
||||
|
||||
ORG_PERMISSION_FIELDS = [
|
||||
("o", "owner"),
|
||||
("a", "admin"),
|
||||
@@ -1559,13 +1564,16 @@ def api_get_json(api_url: str, token_value: str, user_name: str = "", basic: boo
|
||||
|
||||
|
||||
def scope_mask(scopes: list[str]) -> str:
|
||||
scope_set = {scope.lower() for scope in scopes}
|
||||
scope_set = {scope.strip().lower() for scope in scopes if scope.strip()}
|
||||
if "all" in scope_set:
|
||||
return "w" * len(SCOPE_FIELDS)
|
||||
|
||||
values = []
|
||||
for _, category in SCOPE_FIELDS:
|
||||
if f"write:{category}" in scope_set:
|
||||
category_names = SCOPE_CATEGORY_ALIASES.get(category, [category])
|
||||
if any(f"write:{category_name}" in scope_set for category_name in category_names):
|
||||
values.append("w")
|
||||
elif f"read:{category}" in scope_set:
|
||||
elif any(f"read:{category_name}" in scope_set for category_name in category_names):
|
||||
values.append("r")
|
||||
else:
|
||||
values.append("-")
|
||||
|
||||
Reference in New Issue
Block a user