Add token validity and endpoint columns
This commit is contained in:
@@ -716,18 +716,27 @@ TOKEN_REF_WIDTH = 9
|
||||
TOKEN_COLUMNS = [
|
||||
("item", "item", 4),
|
||||
("server", "server", 6),
|
||||
("proto", "proto", 5),
|
||||
("host", "host", 13),
|
||||
("port", "port", 5),
|
||||
("owner", "org", 9),
|
||||
("repo_name", "repo", 11),
|
||||
("user", "user", 4),
|
||||
("remote", "remote", 6),
|
||||
("token_ref", "token_ref", TOKEN_REF_WIDTH),
|
||||
("token", "token", 12),
|
||||
("valid", "valid", 5),
|
||||
("scope_mask", "scope", 6),
|
||||
("org_mask", "org", 6),
|
||||
("repo_mask", "repo", 6),
|
||||
]
|
||||
|
||||
TOKEN_SEPARATOR_OVERRIDES = {
|
||||
"scope_mask": "awrop-",
|
||||
"org_mask": "oawrc-",
|
||||
"repo_mask": "oawr--",
|
||||
}
|
||||
|
||||
|
||||
def fit_cell(value: str, width: int) -> str:
|
||||
if len(value) <= width:
|
||||
@@ -740,7 +749,7 @@ def fit_cell(value: str, width: int) -> str:
|
||||
def print_fixed_table(title: str, columns: list[tuple[str, str, int]], rows: list[dict[str, str]]) -> None:
|
||||
print(title)
|
||||
print(" ".join(fit_cell(label, width) for _, label, width in columns).rstrip())
|
||||
print(" ".join("-" * width for _, _, width in columns).rstrip())
|
||||
print(" ".join(fit_cell(TOKEN_SEPARATOR_OVERRIDES.get(name, "-" * width), width) for name, _, width in columns).rstrip())
|
||||
for row in rows:
|
||||
print(" ".join(fit_cell(row.get(name, ""), width) for name, _, width in columns).rstrip())
|
||||
|
||||
@@ -928,6 +937,7 @@ def load_gitea_authz(endpoint: str, user_name: str, token_name: str, token_value
|
||||
api_base = endpoint.rstrip("/") + "/api/v1"
|
||||
result = {
|
||||
"ok": False,
|
||||
"valid": "!",
|
||||
"scope_mask": "!!!!!",
|
||||
"org_mask": "!!!!!",
|
||||
"repo_mask": "!!!!",
|
||||
@@ -936,6 +946,7 @@ def load_gitea_authz(endpoint: str, user_name: str, token_name: str, token_value
|
||||
try:
|
||||
tokens_url = f"{api_base}/users/{quote(user_name, safe='')}/tokens"
|
||||
token_list = api_get_json(tokens_url, token_value, user_name=user_name, basic=True)
|
||||
result["valid"] = "+"
|
||||
token_last8 = token_value[-8:]
|
||||
token_entry = next(
|
||||
(
|
||||
@@ -967,7 +978,10 @@ def load_gitea_authz(endpoint: str, user_name: str, token_name: str, token_value
|
||||
|
||||
result["ok"] = True
|
||||
return result
|
||||
except (OSError, ValueError, urlerror.URLError, urlerror.HTTPError):
|
||||
except urlerror.HTTPError as error:
|
||||
result["valid"] = "-" if error.code in {401, 403} else "!"
|
||||
return result
|
||||
except (OSError, ValueError, urlerror.URLError):
|
||||
return result
|
||||
|
||||
|
||||
@@ -1016,13 +1030,16 @@ def print_token_item_rows(
|
||||
{
|
||||
"item": str(len(token_rows) + 1),
|
||||
"server": endpoint_values["server"],
|
||||
"proto": endpoint_values["scheme"],
|
||||
"host": endpoint_values["host"],
|
||||
"port": endpoint_values["port"],
|
||||
"owner": owner,
|
||||
"repo_name": repo_name,
|
||||
"user": user_name,
|
||||
"remote": remote_name,
|
||||
"token_ref": format_token_ref(token_name, marker),
|
||||
"token": short_secret(token_value),
|
||||
"valid": authz.get("valid", "?") if authz else "?",
|
||||
"scope_mask": authz.get("scope_mask", "?????") if authz else "?????",
|
||||
"org_mask": authz.get("org_mask", "?????") if authz else "?????",
|
||||
"repo_mask": authz.get("repo_mask", "????") if authz else "????",
|
||||
|
||||
Reference in New Issue
Block a user