Format token item table without secrets
This commit is contained in:
@@ -667,6 +667,35 @@ def print_status_counts(status_counts: dict[str, int]) -> None:
|
||||
print(f"{status_name}\t{status_counts[status_name]}")
|
||||
|
||||
|
||||
TOKEN_ITEM_COLUMNS = [
|
||||
("item", 4),
|
||||
("source", 11),
|
||||
("remote", 10),
|
||||
("kind", 8),
|
||||
("user", 10),
|
||||
("token_ref", 10),
|
||||
("result", 16),
|
||||
("status", 12),
|
||||
("url", 32),
|
||||
]
|
||||
|
||||
|
||||
def fit_cell(value: str, width: int) -> str:
|
||||
if len(value) <= width:
|
||||
return value.ljust(width)
|
||||
if width <= 1:
|
||||
return value[:width]
|
||||
return f"{value[:width - 1]}…"
|
||||
|
||||
|
||||
def print_token_item_table(rows: list[dict[str, str]]) -> None:
|
||||
print("items")
|
||||
print(" ".join(fit_cell(name, width) for name, width in TOKEN_ITEM_COLUMNS))
|
||||
print(" ".join("-" * width for _, width in TOKEN_ITEM_COLUMNS))
|
||||
for row in rows:
|
||||
print(" ".join(fit_cell(row.get(name, ""), width) for name, width in TOKEN_ITEM_COLUMNS))
|
||||
|
||||
|
||||
def print_token_item_rows(
|
||||
endpoint_names: list[str],
|
||||
repo_servers: dict[str, dict],
|
||||
@@ -681,8 +710,7 @@ def print_token_item_rows(
|
||||
if endpoint:
|
||||
scan_rows_by_endpoint.setdefault(endpoint, []).append(row)
|
||||
|
||||
print("items")
|
||||
print("item\tsource\tremote\tkind\tuser\ttoken\tresult\tstatus\turl")
|
||||
item_rows: list[dict[str, str]] = []
|
||||
for index, endpoint in enumerate(endpoint_names, start=1):
|
||||
item_id = str(index)
|
||||
repo_entry = repo_servers.get(endpoint)
|
||||
@@ -695,43 +723,104 @@ def print_token_item_rows(
|
||||
if repo_rows:
|
||||
for row in repo_rows:
|
||||
token_label = "remote" if row["url_kind"] == "auth" else ""
|
||||
print(
|
||||
f"{item_id}\trepo\t{row['remote']}\t{row['url_kind']}\t"
|
||||
f"{row['user']}\t{token_label}\t{row['result']}\t{status_name}\t{endpoint}"
|
||||
item_rows.append(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
"remote": row["remote"],
|
||||
"kind": row["url_kind"],
|
||||
"user": row["user"],
|
||||
"token_ref": token_label,
|
||||
"result": row["result"],
|
||||
"status": status_name,
|
||||
"url": endpoint,
|
||||
}
|
||||
)
|
||||
elif repo_entry is None:
|
||||
print(f"{item_id}\trepo\t\tmissing\t\t\tmissing\t{status_name}\t{endpoint}")
|
||||
item_rows.append(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
"kind": "missing",
|
||||
"result": "missing",
|
||||
"status": status_name,
|
||||
"url": endpoint,
|
||||
}
|
||||
)
|
||||
else:
|
||||
repo_kind, repo_result = repo_result_for_entry(repo_entry)
|
||||
remote_names = ",".join(sorted(repo_entry.get("remotes", set())))
|
||||
repo_users = token_name_rows(repo_entry.get("users", {}))
|
||||
if repo_users:
|
||||
for user_name, _ in repo_users:
|
||||
print(
|
||||
f"{item_id}\trepo\t{remote_names}\t{repo_kind}\t"
|
||||
f"{user_name}\tremote\t{repo_result}\t{status_name}\t{endpoint}"
|
||||
item_rows.append(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
"remote": remote_names,
|
||||
"kind": repo_kind,
|
||||
"user": user_name,
|
||||
"token_ref": "remote",
|
||||
"result": repo_result,
|
||||
"status": status_name,
|
||||
"url": endpoint,
|
||||
}
|
||||
)
|
||||
else:
|
||||
print(
|
||||
f"{item_id}\trepo\t{remote_names}\t{repo_kind}\t\t\t"
|
||||
f"{repo_result}\t{status_name}\t{endpoint}"
|
||||
item_rows.append(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
"remote": remote_names,
|
||||
"kind": repo_kind,
|
||||
"result": repo_result,
|
||||
"status": status_name,
|
||||
"url": endpoint,
|
||||
}
|
||||
)
|
||||
|
||||
if store_entry is None:
|
||||
print(f"{item_id}\ttokens.json\t\tmissing\t\t\tmissing\t{status_name}\t{endpoint}")
|
||||
item_rows.append(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "tokens.json",
|
||||
"kind": "missing",
|
||||
"result": "missing",
|
||||
"status": status_name,
|
||||
"url": endpoint,
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
store_users = token_name_rows(store_entry.get("users", {}))
|
||||
if not store_users:
|
||||
print(f"{item_id}\ttokens.json\t\tstore\t\t\tempty\t{status_name}\t{endpoint}")
|
||||
item_rows.append(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "tokens.json",
|
||||
"kind": "store",
|
||||
"result": "empty",
|
||||
"status": status_name,
|
||||
"url": endpoint,
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
for user_name, token_name in store_users:
|
||||
print(
|
||||
f"{item_id}\ttokens.json\t\tstore\t{user_name}\t"
|
||||
f"{token_name}\tpresent\t{status_name}\t{endpoint}"
|
||||
item_rows.append(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "tokens.json",
|
||||
"kind": "store",
|
||||
"user": user_name,
|
||||
"token_ref": token_name,
|
||||
"result": "present",
|
||||
"status": status_name,
|
||||
"url": endpoint,
|
||||
}
|
||||
)
|
||||
|
||||
print_token_item_table(item_rows)
|
||||
return status_counts
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user