Decompose token endpoints in scan output
This commit is contained in:
@@ -159,9 +159,10 @@ Podstawowe komendy tokenow:
|
|||||||
`tokens scan` wypisuje waska tabele. Dla jednego endpointu zobaczysz
|
`tokens scan` wypisuje waska tabele. Dla jednego endpointu zobaczysz
|
||||||
osobny wiersz `source=repo` oraz osobny wiersz `source=tokens.json`.
|
osobny wiersz `source=repo` oraz osobny wiersz `source=tokens.json`.
|
||||||
Ten sam numer `item` laczy oba wiersze w pare dla jednego endpointu.
|
Ten sam numer `item` laczy oba wiersze w pare dla jednego endpointu.
|
||||||
Kolumny `has_token` i `sync` pokazuja, gdzie jest token i czy repo zgadza sie
|
Kolumny `token` i `sync` pokazuja, gdzie jest token i czy repo zgadza sie
|
||||||
z `tokens.json`. Kolumna `id` pokazuje `r1` dla tokena w repo albo `t1` dla
|
z `tokens.json`. Kolumna `id` pokazuje `r1` dla tokena w repo albo `t1` dla
|
||||||
tokena w `tokens.json`, bez pokazywania sekretu.
|
tokenu w `tokens.json`, bez pokazywania sekretu. Endpoint jest rozbity na
|
||||||
|
`server`, `scheme`, `host` i `port`.
|
||||||
|
|
||||||
## Fetch i switch
|
## Fetch i switch
|
||||||
|
|
||||||
|
|||||||
+11
-10
@@ -305,22 +305,23 @@ Typowy wynik:
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
items
|
items
|
||||||
item source id credential user has_token sync endpoint
|
item source id server scheme host port credential repo_user store_user token sync
|
||||||
---- ----------- ---------- ---------- ---------- --------- ----- --------------------------------
|
---- ----------- ---------- ------ ------ --------------- ----- ---------- --------- ---------- ----- ----
|
||||||
1 repo r1 auth u1 yes yes http://77.90.8.171:3001
|
1 repo r1 gitea http 77.90.8.171 3001 auth u1 u1 yes yes
|
||||||
1 tokens.json t1 store u1 yes yes http://77.90.8.171:3001
|
1 tokens.json t1 gitea http 77.90.8.171 3001 store u1 u1 yes yes
|
||||||
```
|
```
|
||||||
|
|
||||||
Jesli remote istnieje, ale ma URL bez `LOGIN:TOKEN@`, wynik bedzie mial
|
Jesli remote istnieje, ale ma URL bez `LOGIN:TOKEN@`, wynik bedzie mial
|
||||||
w wierszu `repo` wartosci `credential=plain` i `has_token=no`. Jezeli ten sam
|
w wierszu `repo` wartosci `credential=plain` i `token=no`. Jezeli ten sam
|
||||||
endpoint istnieje w `tokens.json`, drugi wiersz tego samego `item` pokaze
|
endpoint istnieje w `tokens.json`, drugi wiersz tego samego `item` pokaze
|
||||||
`source=tokens.json`, `id=t1` i `has_token=yes`.
|
`source=tokens.json`, `id=t1`, `store_user=u1` i `token=yes`.
|
||||||
|
|
||||||
Ten sam numer `item` oznacza jedna pare logiczna dla jednego endpointu. Wiersz
|
Ten sam numer `item` oznacza jedna pare logiczna dla jednego endpointu. Wiersz
|
||||||
`source=repo` pokazuje stan remote, a wiersz `source=tokens.json` pokazuje stan
|
`source=repo` pokazuje stan remote, a wiersz `source=tokens.json` pokazuje stan
|
||||||
lokalnego store. Kolumna `sync` jest flaga zgodnosci calej pary repo/store.
|
lokalnego store. Kolumna `sync` jest flaga zgodnosci calej pary repo/store.
|
||||||
Kolumna `id` pokazuje identyfikator miejsca przechowywania tokena: dla repo jest
|
Kolumna `id` pokazuje identyfikator miejsca przechowywania tokena: dla repo jest
|
||||||
to nazwa remota, na przyklad `r1`, a dla store nazwa tokenu, na przyklad `t1`.
|
to nazwa remota, na przyklad `r1`, a dla store nazwa tokenu, na przyklad `t1`.
|
||||||
|
Endpoint jest rozbity na `server`, `scheme`, `host` i `port`.
|
||||||
|
|
||||||
Przyklad:
|
Przyklad:
|
||||||
|
|
||||||
@@ -384,10 +385,10 @@ repo_root<TAB>...
|
|||||||
token_path<TAB>...
|
token_path<TAB>...
|
||||||
|
|
||||||
items
|
items
|
||||||
item source id credential user has_token sync endpoint
|
item source id server scheme host port credential repo_user store_user token sync
|
||||||
---- ----------- ---------- ---------- ---------- --------- ----- --------------------------------
|
---- ----------- ---------- ------ ------ --------------- ----- ---------- --------- ---------- ----- ----
|
||||||
1 repo r1 plain no no http://77.90.8.171:3001
|
1 repo r1 gitea http 77.90.8.171 3001 plain u1 no no
|
||||||
1 tokens.json t1 store u1 yes no http://77.90.8.171:3001
|
1 tokens.json t1 gitea http 77.90.8.171 3001 store u1 u1 yes no
|
||||||
|
|
||||||
status
|
status
|
||||||
item<TAB>value
|
item<TAB>value
|
||||||
|
|||||||
+7
-3
@@ -105,11 +105,15 @@ Kolumny w tabeli `items`:
|
|||||||
- `item` - numer porownywanego endpointu
|
- `item` - numer porownywanego endpointu
|
||||||
- `source` - `repo` albo `tokens.json`
|
- `source` - `repo` albo `tokens.json`
|
||||||
- `id` - identyfikator miejsca tokena: remote `r1` dla repo albo token `t1` dla `tokens.json`
|
- `id` - identyfikator miejsca tokena: remote `r1` dla repo albo token `t1` dla `tokens.json`
|
||||||
|
- `server` - typ serwera, na przyklad `gitea`
|
||||||
|
- `scheme` - schemat URL, na przyklad `http`
|
||||||
|
- `host` - host endpointu, na przyklad `77.90.8.171`
|
||||||
|
- `port` - port endpointu, na przyklad `3001`
|
||||||
- `credential` - typ wpisu: `auth`, `plain`, `store` albo `missing`
|
- `credential` - typ wpisu: `auth`, `plain`, `store` albo `missing`
|
||||||
- `user` - login odczytany z URL albo ze store
|
- `repo_user` - login odczytany z remote URL-i repo
|
||||||
- `has_token` - `yes` albo `no`, czyli czy dane zrodlo ma token dla endpointu
|
- `store_user` - login odczytany z `tokens.json`
|
||||||
|
- `token` - `yes` albo `no`, czyli czy dane zrodlo ma token dla endpointu
|
||||||
- `sync` - `yes` albo `no`, czyli czy para repo/store jest zgodna
|
- `sync` - `yes` albo `no`, czyli czy para repo/store jest zgodna
|
||||||
- `endpoint` - endpoint serwera bez sekretu, trzymany jako ostatnia kolumna i przycinany do szerokosci tabeli
|
|
||||||
|
|
||||||
Tabela nie wypisuje sekretu tokena. Jezeli token jest w remote, `id` pokazuje
|
Tabela nie wypisuje sekretu tokena. Jezeli token jest w remote, `id` pokazuje
|
||||||
nazwe remota, na przyklad `r1`. Jezeli token jest w `tokens.json`, `id`
|
nazwe remota, na przyklad `r1`. Jezeli token jest w `tokens.json`, `id`
|
||||||
|
|||||||
@@ -671,11 +671,15 @@ TOKEN_ITEM_COLUMNS = [
|
|||||||
("item", 4),
|
("item", 4),
|
||||||
("source", 11),
|
("source", 11),
|
||||||
("id", 10),
|
("id", 10),
|
||||||
|
("server", 6),
|
||||||
|
("scheme", 6),
|
||||||
|
("host", 15),
|
||||||
|
("port", 5),
|
||||||
("credential", 10),
|
("credential", 10),
|
||||||
("user", 10),
|
("repo_user", 9),
|
||||||
("has_token", 9),
|
("store_user", 10),
|
||||||
("sync", 5),
|
("token", 5),
|
||||||
("endpoint", 32),
|
("sync", 4),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -699,6 +703,36 @@ def sync_flag(status_name: str) -> str:
|
|||||||
return "yes" if status_name == "in_sync" else "no"
|
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(
|
def print_token_item_rows(
|
||||||
endpoint_names: list[str],
|
endpoint_names: list[str],
|
||||||
repo_servers: dict[str, dict],
|
repo_servers: dict[str, dict],
|
||||||
@@ -721,6 +755,10 @@ def print_token_item_rows(
|
|||||||
status_name, _, _ = compare_server_entries(repo_entry, store_entry)
|
status_name, _, _ = compare_server_entries(repo_entry, store_entry)
|
||||||
if status_name in status_counts:
|
if status_name in status_counts:
|
||||||
status_counts[status_name] += 1
|
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, [])
|
repo_rows = scan_rows_by_endpoint.get(endpoint, [])
|
||||||
if repo_rows:
|
if repo_rows:
|
||||||
@@ -731,11 +769,12 @@ def print_token_item_rows(
|
|||||||
"item": item_id,
|
"item": item_id,
|
||||||
"source": "repo",
|
"source": "repo",
|
||||||
"id": row["remote"],
|
"id": row["remote"],
|
||||||
|
**endpoint_values,
|
||||||
"credential": row["url_kind"],
|
"credential": row["url_kind"],
|
||||||
"user": row["user"],
|
"repo_user": row["user"],
|
||||||
"has_token": "yes" if token_label else "no",
|
"store_user": store_users_label,
|
||||||
"sync": sync_flag(status_name),
|
"token": "yes" if token_label else "no",
|
||||||
"endpoint": endpoint,
|
"sync": sync_value,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
elif repo_entry is None:
|
elif repo_entry is None:
|
||||||
@@ -743,10 +782,11 @@ def print_token_item_rows(
|
|||||||
{
|
{
|
||||||
"item": item_id,
|
"item": item_id,
|
||||||
"source": "repo",
|
"source": "repo",
|
||||||
|
**endpoint_values,
|
||||||
"credential": "missing",
|
"credential": "missing",
|
||||||
"has_token": "no",
|
"store_user": store_users_label,
|
||||||
"sync": sync_flag(status_name),
|
"token": "no",
|
||||||
"endpoint": endpoint,
|
"sync": sync_value,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -761,11 +801,12 @@ def print_token_item_rows(
|
|||||||
"item": item_id,
|
"item": item_id,
|
||||||
"source": "repo",
|
"source": "repo",
|
||||||
"id": remote_names,
|
"id": remote_names,
|
||||||
|
**endpoint_values,
|
||||||
"credential": repo_kind,
|
"credential": repo_kind,
|
||||||
"user": user_name,
|
"repo_user": user_name,
|
||||||
"has_token": "yes" if token_label else "no",
|
"store_user": store_users_label,
|
||||||
"sync": sync_flag(status_name),
|
"token": "yes" if token_label else "no",
|
||||||
"endpoint": endpoint,
|
"sync": sync_value,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -774,10 +815,11 @@ def print_token_item_rows(
|
|||||||
"item": item_id,
|
"item": item_id,
|
||||||
"source": "repo",
|
"source": "repo",
|
||||||
"id": remote_names,
|
"id": remote_names,
|
||||||
|
**endpoint_values,
|
||||||
"credential": repo_kind,
|
"credential": repo_kind,
|
||||||
"has_token": "yes" if repo_result == "present" else "no",
|
"store_user": store_users_label,
|
||||||
"sync": sync_flag(status_name),
|
"token": "yes" if repo_result == "present" else "no",
|
||||||
"endpoint": endpoint,
|
"sync": sync_value,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -786,10 +828,11 @@ def print_token_item_rows(
|
|||||||
{
|
{
|
||||||
"item": item_id,
|
"item": item_id,
|
||||||
"source": "tokens.json",
|
"source": "tokens.json",
|
||||||
|
**endpoint_values,
|
||||||
"credential": "missing",
|
"credential": "missing",
|
||||||
"has_token": "no",
|
"repo_user": repo_users_label,
|
||||||
"sync": sync_flag(status_name),
|
"token": "no",
|
||||||
"endpoint": endpoint,
|
"sync": sync_value,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
@@ -800,10 +843,11 @@ def print_token_item_rows(
|
|||||||
{
|
{
|
||||||
"item": item_id,
|
"item": item_id,
|
||||||
"source": "tokens.json",
|
"source": "tokens.json",
|
||||||
|
**endpoint_values,
|
||||||
"credential": "store",
|
"credential": "store",
|
||||||
"has_token": "no",
|
"repo_user": repo_users_label,
|
||||||
"sync": sync_flag(status_name),
|
"token": "no",
|
||||||
"endpoint": endpoint,
|
"sync": sync_value,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
@@ -814,11 +858,12 @@ def print_token_item_rows(
|
|||||||
"item": item_id,
|
"item": item_id,
|
||||||
"source": "tokens.json",
|
"source": "tokens.json",
|
||||||
"credential": "store",
|
"credential": "store",
|
||||||
"user": user_name,
|
|
||||||
"id": token_name,
|
"id": token_name,
|
||||||
"has_token": "yes" if token_name else "no",
|
**endpoint_values,
|
||||||
"sync": sync_flag(status_name),
|
"repo_user": repo_users_label,
|
||||||
"endpoint": endpoint,
|
"store_user": user_name,
|
||||||
|
"token": "yes" if token_name else "no",
|
||||||
|
"sync": sync_value,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user