Decompose token endpoints in scan output
This commit is contained in:
@@ -671,11 +671,15 @@ TOKEN_ITEM_COLUMNS = [
|
||||
("item", 4),
|
||||
("source", 11),
|
||||
("id", 10),
|
||||
("server", 6),
|
||||
("scheme", 6),
|
||||
("host", 15),
|
||||
("port", 5),
|
||||
("credential", 10),
|
||||
("user", 10),
|
||||
("has_token", 9),
|
||||
("sync", 5),
|
||||
("endpoint", 32),
|
||||
("repo_user", 9),
|
||||
("store_user", 10),
|
||||
("token", 5),
|
||||
("sync", 4),
|
||||
]
|
||||
|
||||
|
||||
@@ -699,6 +703,36 @@ def sync_flag(status_name: str) -> str:
|
||||
return "yes" if status_name == "in_sync" else "no"
|
||||
|
||||
|
||||
def users_label(server_entry: dict | None) -> str:
|
||||
if server_entry is None:
|
||||
return ""
|
||||
return ",".join(sorted(str(user_name) for user_name in server_entry.get("users", {})))
|
||||
|
||||
|
||||
def endpoint_column_values(endpoint: str, repo_entry: dict | None, store_entry: dict | None) -> dict[str, str]:
|
||||
values = {
|
||||
"server": "",
|
||||
"scheme": "",
|
||||
"host": "",
|
||||
"port": "",
|
||||
}
|
||||
for server_entry in [repo_entry, store_entry]:
|
||||
if server_entry is None:
|
||||
continue
|
||||
values["server"] = values["server"] or str(server_entry.get("type", ""))
|
||||
values["scheme"] = values["scheme"] or str(server_entry.get("scheme", ""))
|
||||
values["host"] = values["host"] or str(server_entry.get("host", ""))
|
||||
port_value = server_entry.get("port", "")
|
||||
values["port"] = values["port"] or ("" if port_value is None else str(port_value))
|
||||
|
||||
split_endpoint = urlsplit(endpoint)
|
||||
values["scheme"] = values["scheme"] or split_endpoint.scheme
|
||||
values["host"] = values["host"] or (split_endpoint.hostname or "")
|
||||
if not values["port"] and split_endpoint.port is not None:
|
||||
values["port"] = str(split_endpoint.port)
|
||||
return values
|
||||
|
||||
|
||||
def print_token_item_rows(
|
||||
endpoint_names: list[str],
|
||||
repo_servers: dict[str, dict],
|
||||
@@ -721,6 +755,10 @@ def print_token_item_rows(
|
||||
status_name, _, _ = compare_server_entries(repo_entry, store_entry)
|
||||
if status_name in status_counts:
|
||||
status_counts[status_name] += 1
|
||||
endpoint_values = endpoint_column_values(endpoint, repo_entry, store_entry)
|
||||
repo_users_label = users_label(repo_entry)
|
||||
store_users_label = users_label(store_entry)
|
||||
sync_value = sync_flag(status_name)
|
||||
|
||||
repo_rows = scan_rows_by_endpoint.get(endpoint, [])
|
||||
if repo_rows:
|
||||
@@ -731,11 +769,12 @@ def print_token_item_rows(
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
"id": row["remote"],
|
||||
**endpoint_values,
|
||||
"credential": row["url_kind"],
|
||||
"user": row["user"],
|
||||
"has_token": "yes" if token_label else "no",
|
||||
"sync": sync_flag(status_name),
|
||||
"endpoint": endpoint,
|
||||
"repo_user": row["user"],
|
||||
"store_user": store_users_label,
|
||||
"token": "yes" if token_label else "no",
|
||||
"sync": sync_value,
|
||||
}
|
||||
)
|
||||
elif repo_entry is None:
|
||||
@@ -743,10 +782,11 @@ def print_token_item_rows(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
**endpoint_values,
|
||||
"credential": "missing",
|
||||
"has_token": "no",
|
||||
"sync": sync_flag(status_name),
|
||||
"endpoint": endpoint,
|
||||
"store_user": store_users_label,
|
||||
"token": "no",
|
||||
"sync": sync_value,
|
||||
}
|
||||
)
|
||||
else:
|
||||
@@ -761,11 +801,12 @@ def print_token_item_rows(
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
"id": remote_names,
|
||||
**endpoint_values,
|
||||
"credential": repo_kind,
|
||||
"user": user_name,
|
||||
"has_token": "yes" if token_label else "no",
|
||||
"sync": sync_flag(status_name),
|
||||
"endpoint": endpoint,
|
||||
"repo_user": user_name,
|
||||
"store_user": store_users_label,
|
||||
"token": "yes" if token_label else "no",
|
||||
"sync": sync_value,
|
||||
}
|
||||
)
|
||||
else:
|
||||
@@ -774,10 +815,11 @@ def print_token_item_rows(
|
||||
"item": item_id,
|
||||
"source": "repo",
|
||||
"id": remote_names,
|
||||
**endpoint_values,
|
||||
"credential": repo_kind,
|
||||
"has_token": "yes" if repo_result == "present" else "no",
|
||||
"sync": sync_flag(status_name),
|
||||
"endpoint": endpoint,
|
||||
"store_user": store_users_label,
|
||||
"token": "yes" if repo_result == "present" else "no",
|
||||
"sync": sync_value,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -786,10 +828,11 @@ def print_token_item_rows(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "tokens.json",
|
||||
**endpoint_values,
|
||||
"credential": "missing",
|
||||
"has_token": "no",
|
||||
"sync": sync_flag(status_name),
|
||||
"endpoint": endpoint,
|
||||
"repo_user": repo_users_label,
|
||||
"token": "no",
|
||||
"sync": sync_value,
|
||||
}
|
||||
)
|
||||
continue
|
||||
@@ -800,10 +843,11 @@ def print_token_item_rows(
|
||||
{
|
||||
"item": item_id,
|
||||
"source": "tokens.json",
|
||||
**endpoint_values,
|
||||
"credential": "store",
|
||||
"has_token": "no",
|
||||
"sync": sync_flag(status_name),
|
||||
"endpoint": endpoint,
|
||||
"repo_user": repo_users_label,
|
||||
"token": "no",
|
||||
"sync": sync_value,
|
||||
}
|
||||
)
|
||||
continue
|
||||
@@ -814,11 +858,12 @@ def print_token_item_rows(
|
||||
"item": item_id,
|
||||
"source": "tokens.json",
|
||||
"credential": "store",
|
||||
"user": user_name,
|
||||
"id": token_name,
|
||||
"has_token": "yes" if token_name else "no",
|
||||
"sync": sync_flag(status_name),
|
||||
"endpoint": endpoint,
|
||||
**endpoint_values,
|
||||
"repo_user": repo_users_label,
|
||||
"store_user": user_name,
|
||||
"token": "yes" if token_name else "no",
|
||||
"sync": sync_value,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user