Restructure token store by remote id

This commit is contained in:
mpabi
2026-04-26 22:12:45 +02:00
parent d2d200257f
commit 55c52c7b4f
5 changed files with 768 additions and 352 deletions
+98 -36
View File
@@ -103,22 +103,23 @@ Minimalny format pliku:
```json
{
"version": 2,
"servers": {
"http://77.90.8.171:3001": {
"type": "gitea",
"scheme": "http",
"host": "77.90.8.171",
"port": 3001,
"users": {
"u1": {
"tokens": {
"t1": "TU_WSTAW_TOKEN"
}
}
}
"version": 3,
"tokens": [
{
"id": "r1",
"value": "TU_WSTAW_TOKEN",
"server": {
"type": "gitea",
"endpoint": "http://77.90.8.171:3001",
"scheme": "http",
"host": "77.90.8.171",
"port": 3001
},
"user": "u1",
"org": "edu-tools",
"repo": "rv-launcher"
}
}
]
}
```
@@ -306,13 +307,13 @@ Typowy wynik:
tokens
item server proto host org repo user remote token_ref token valid scope org repo
---- ------ ----- ------------------ --------- ----------- ---- ------ --------- ------------ ------------------- aAimnopru oawrc- oawr--
1 gitea http 77.90.8.171:3001 edu-tools rv-launcher u1 r1 t1 * e59cc...13be forever -----w--- +++++ ++++
1 gitea http 77.90.8.171:3001 edu-tools rv-launcher u1 r1 r1 * e59cc...13be forever -----w--- +++++ ++++
```
`token_ref` jest komorka stalej szerokosci: nazwa tokena jest po lewej, a marker
po prawej. Marker `*` oznacza, ze token w remote i `tokens.json` jest zgodny
oraz uprawnienia zostaly wczytane. Marker `R` oznacza token tylko w remote, a
`S` token tylko w `tokens.json`.
po prawej. Nazwa tokena jest taka sama jak nazwa git remote, np. `r1`. Marker
`*` oznacza, ze remote i `tokens.json` sa zgodne. Marker `R` oznacza token tylko
w remote, a `S` token tylko w `tokens.json`.
Maski uprawnien:
@@ -330,10 +331,11 @@ Przyklad:
./rvctl tokens scan --repo ~/dev/workspace/rv/series/inf/03
```
## `tokens add TOKEN_ID`
## `tokens add REMOTE_ID`
Dodaje pusty szkielet tokena do `tokens.json`. Pole `value` jest puste i trzeba
je uzupelnic recznie przed uzyciem tokena.
Dodaje pusty szkielet tokena do `tokens.json`. `REMOTE_ID` musi byc taki sam
jak nazwa git remote, np. `r1`. Pole `value` jest puste i trzeba je uzupelnic
recznie przed uzyciem tokena.
Przelaczniki:
@@ -342,9 +344,9 @@ Przelaczniki:
- `--value TOKEN`
Opcjonalna wartosc tokena. Domyslnie pusta.
- `--user NAME`
Opcjonalny opis usera API.
Login uzywany w URL-u auth, np. `u1`.
- `--remote NAME`
Opcjonalny remote powiazany z tokenem.
Alias zgodnosci. Jesli podany, musi byc taki sam jak `REMOTE_ID`.
- `--org NAME`
Opcjonalna organizacja dla remota.
- `--repo NAME`
@@ -355,8 +357,51 @@ Przelaczniki:
Przyklady:
```bash
./rvctl tokens add r6
./rvctl tokens add t1 --remote r1 --org edu-tools --repo rv-launcher
./rvctl tokens add r1
./rvctl tokens add r1 --user u1 --org edu-tools --repo rv-launcher
```
## `tokens sync remote REMOTE_ID`
Czyta dane auth z git remote `REMOTE_ID` i zapisuje je do `tokens.json`. Nie
pobiera metadanych z API.
Przelaczniki:
- `--repo PATH`
Sciezka wewnatrz docelowego repo. Domyslnie biezacy katalog.
- `--dry-run`
Pokazuje plan bez zapisu.
Przyklad:
```bash
./rvctl tokens sync remote r1
./rvctl tokens sync remote r1 --repo ~/dev/workspace/rv/tools/rv-launcher
```
## `tokens sync store REMOTE_ID`
Zapisuje dane auth z rekordu `REMOTE_ID` w `tokens.json` do git remote o tej
samej nazwie.
Przelaczniki:
- `--repo PATH`
Sciezka wewnatrz docelowego repo. Domyslnie biezacy katalog.
- `--url URL`
URL remota, jesli remote jeszcze nie istnieje.
- `--server ENDPOINT`
Endpoint serwera z `tokens.json`.
- `--replace`
Nadpisuje inne dane auth juz wpisane w remote URL.
- `--dry-run`
Pokazuje plan bez zapisu.
Przyklad:
```bash
./rvctl tokens sync store r1 --repo ~/dev/workspace/rv/series/inf/03
```
## `tokens read`
@@ -379,10 +424,9 @@ type<TAB>gitea
scheme<TAB>http
host<TAB>77.90.8.171
port<TAB>3001
users<TAB>1
tokens<TAB>1
user<TAB>u1
token<TAB>t1<TAB>SE****23
id<TAB>r1<TAB>SE****23
user<TAB>r1<TAB>u1
```
Przyklad:
@@ -415,7 +459,7 @@ token_path<TAB>...
tokens
item server proto host org repo user remote token_ref token valid scope org repo
---- ------ ----- ------------------ --------- ----------- ---- ------ --------- ------------ ------------------- aAimnopru oawrc- oawr--
1 gitea http 77.90.8.171:3001 edu-tools rv-launcher u1 r1 t1 * e59cc...13be forever -----w--- +++++ ++++
1 gitea http 77.90.8.171:3001 edu-tools rv-launcher u1 r1 r1 * e59cc...13be forever -----w--- +++++ ++++
status
item<TAB>value
@@ -445,7 +489,7 @@ Przelaczniki:
- `--user NAME`
Uzytkownik z wybranego endpointu.
- `--token-name NAME`
Nazwa tokena, na przyklad `t1`.
Remote id w `tokens.json`, na przyklad `r1`. Domyslnie wartosc `--remote`.
- `--replace`
Nadpisuje inne dane auth juz wpisane w remote URL.
- `--dry-run`
@@ -454,12 +498,30 @@ Przelaczniki:
Przyklad:
```bash
./rvctl tokens write --repo ~/dev/workspace/rv/series/inf/03 --remote r1 --server http://77.90.8.171:3001 --user u1 --token-name t1
./rvctl tokens write --repo ~/dev/workspace/rv/series/inf/03 --remote r1 --server http://77.90.8.171:3001
```
## `tokens update`
## `tokens update REMOTE_ID`
Uruchamia synchronizacje w zadanym kierunku.
Pobiera z API metadane dla rekordu `REMOTE_ID` zapisanego w `tokens.json`.
Nie synchronizuje sekretu z git remote.
Przelaczniki:
- `--server ENDPOINT`
Opcjonalny wybor endpointu, jesli ten sam `REMOTE_ID` istnieje dla wielu serwerow.
- `--dry-run`
Pokazuje plan bez zapisu.
Przyklad:
```bash
./rvctl tokens update r1
```
## `tokens update --from ...`
Komendy zgodnosci dla starego modelu kierunkowego.
Przelaczniki:
@@ -478,7 +540,7 @@ Przelaczniki:
- `--user NAME`
Opcjonalny wybor usera dla `--from store`.
- `--token-name NAME`
Opcjonalny wybor tokena dla `--from store`.
Opcjonalny wybor remote id dla `--from store`.
- `--replace`
Nadpisuje inne auth przy `--from store`.
- `--dry-run`
@@ -488,7 +550,7 @@ Przyklady:
```bash
./rvctl tokens update --from remotes --repo ~/dev/workspace/rv/series/inf/03
./rvctl tokens update --from store --repo ~/dev/workspace/rv/series/inf/03 --remote r1 --server http://77.90.8.171:3001 --user u1 --token-name t1
./rvctl tokens update --from store --repo ~/dev/workspace/rv/series/inf/03 --remote r1 --server http://77.90.8.171:3001
```
## `submission [series] [card]`
+106 -64
View File
@@ -4,28 +4,31 @@ Plik opisuje model pracy z tokenami w launcherze.
## Zrodlo prawdy
Sa dwa miejsca, w ktorych moga byc zapisane tokeny:
Sa dwa miejsca, w ktorych moga byc zapisane dane dostepowe:
- remote URL-e w repo, na przyklad `http://t1:SECRET@host/org/repo.git`
- remote URL w repo, na przyklad `http://u1:SECRET@host/org/repo.git`
- lokalny plik `~/dev/workspace/rv/tokens/tokens.json`
`tokens scan` tylko porownuje oba zrodla i niczego nie zapisuje.
`tokens update --from remotes` czyta remote URL-e, zapisuje tokeny do
`tokens.json` i wzbogaca je danymi z API, jezeli token dziala.
`tokens update --from store` zapisuje wybrany token z `tokens.json` do remote
URL-a repo.
`tokens scan` tylko porownuje oba miejsca i niczego nie zapisuje.
`tokens sync remote r1` czyta remote `r1` i zapisuje jego dane w
`tokens.json`.
`tokens sync store r1` zapisuje rekord `r1` z `tokens.json` do git remote
`r1`.
`tokens update r1` nie synchronizuje sekretu; tylko pobiera z API metadane
tokenu: `valid`, `scope`, `org_perm` i `repo_perm`.
## Format `tokens.json`
Aktualny format to `version: 3`. Glownym rekordem jest token. `server`, `user`,
`valid`, `scope` i `remotes` sa atrybutami tego tokena.
Aktualny format to `version: 3`. Glownym rekordem jest remote-token. Pole
`id` jest obowiazkowe i musi byc takie samo jak nazwa git remote, np. `r1`
albo `r1a`.
```json
{
"version": 3,
"tokens": [
{
"token_id": "t1",
"id": "r1",
"value": "SECRET",
"server": {
"type": "gitea",
@@ -35,17 +38,33 @@ Aktualny format to `version: 3`. Glownym rekordem jest token. `server`, `user`,
"port": 3001
},
"user": "u1",
"org": "edu-tools",
"repo": "rv-launcher",
"valid": "forever",
"scope": "-----w---",
"remotes": [
{
"name": "r1",
"org": "edu-tools",
"repo": "rv-launcher",
"org_perm": "+++++",
"repo_perm": "++++"
}
]
"scope": {
"a": "-",
"A": "-",
"i": "-",
"m": "-",
"n": "-",
"o": "-",
"p": "-",
"r": "w",
"u": "-"
},
"org_perm": {
"o": "+",
"a": "+",
"w": "+",
"r": "+",
"c": "+"
},
"repo_perm": {
"o": "+",
"a": "+",
"w": "+",
"r": "+"
}
}
]
}
@@ -57,28 +76,27 @@ Schemat JSON jest w pliku `doc/tokens.schema.json`.
Pola synchronizowane z remote URL-a:
- `id` - nazwa git remote, np. `r1`; to jest klucz rekordu w `tokens.json`
- `server.endpoint` - endpoint serwera, na przyklad `http://77.90.8.171:3001`
- `server.type` - typ serwera, na przyklad `gitea`, `github`, `gitlab`, `unknown`
- `token_id` - identyfikator z lewej strony URL-a, na przyklad `t1` w `http://t1:SECRET@...`
- `user` - login z URL-a, czyli lewa strona `http://u1:SECRET@...`
- `value` - sekret tokena
- `remotes[].name` - nazwa remota, na przyklad `r1`
- `remotes[].org` - organizacja z URL-a
- `remotes[].repo` - repo z URL-a
- `org` - organizacja z URL-a
- `repo` - repo z URL-a
Pola wzbogacane przez API przy `tokens update --from remotes`:
Pola wzbogacane przez API przy `tokens update r1`:
- `user` - login wlasciciela tokena odczytany z API
- `valid` - `forever`, data `expires_at`, `invalid`, `?` albo `!`
- `scope` - maska scope tokena w kolejnosci `aAimnopru`
- `remotes[].org_perm` - maska praw w organizacji
- `remotes[].repo_perm` - maska praw w repo
- `scope` - mapa scope tokena
- `org_perm` - mapa praw w organizacji
- `repo_perm` - mapa praw w repo
## Porownanie
Porownanie z `git remote -v` jest robione po:
```text
server.endpoint + remote.name + token_id + value + org + repo
server.endpoint + id + user + value + org + repo
```
Znacznik w kolumnie `token_ref`:
@@ -88,10 +106,13 @@ Znacznik w kolumnie `token_ref`:
- `S` - wpis istnieje tylko w `tokens.json`
- `!` - remote i `tokens.json` sa zgodne, ale zapisany token jest `invalid` albo ma blad walidacji
Bez `*` albo `!` kolumny `valid`, `scope`, `org` i `repo` w raporcie maja
Bez zgodnego wpisu kolumny `valid`, `scope`, `org` i `repo` w raporcie maja
wartosc `?`, bo launcher nie pokazuje metadanych API dla niesparowanych wpisow.
## Maski uprawnien
## Uprawnienia
W `tokens.json` uprawnienia sa zapisane jako mapy klucz-wartosc. W tabeli CLI sa
pokazywane skrocone maski.
Naglowki masek:
@@ -119,7 +140,22 @@ Znaki w `scope`:
- `?` - nie wczytano
- `!` - blad wczytania
Znaki w `org` i `repo`:
Kategorie `org_perm`:
- `o` - owner
- `a` - admin
- `w` - write
- `r` - read
- `c` - create repository
Kategorie `repo_perm`:
- `o` - owner
- `a` - admin
- `w` - write
- `r` - read
Znaki w `org_perm` i `repo_perm`:
- `+` - flaga wlaczona
- `-` - flaga wylaczona
@@ -130,26 +166,43 @@ Znaki w `org` i `repo`:
### `tokens scan`
Read-only. Czyta remote URL-e i `tokens.json`, a potem wypisuje tabele `tokens`.
Nie tworzy i nie modyfikuje `tokens.json`.
Read-only. Czyta remote URL-e i `tokens.json`, a potem wypisuje tabele
`tokens`. Nie tworzy i nie modyfikuje `tokens.json`.
```bash
./rvctl tokens scan
./rvctl tokens scan --repo ~/dev/workspace/rv/series/inf/03
```
### `tokens update --from remotes`
### `tokens sync remote REMOTE_ID`
Kopiuje tokeny z remote URL-i repo do `tokens.json`, zapisuje rekordy w formacie
v3 i probuje pobrac pola API: `user`, `valid`, `scope`, `org_perm`,
`repo_perm`.
Kopiuje dane dostepowe z git remote do `tokens.json`. Nie pobiera metadanych z
API.
```bash
./rvctl tokens update --from remotes --repo ~/dev/workspace/rv/tools/rv-launcher
./rvctl tokens update --from remotes --dry-run
./rvctl tokens sync remote r1
./rvctl tokens sync remote r1 --repo ~/dev/workspace/rv/tools/rv-launcher
```
`--dry-run` dziala jak read-only raport i niczego nie zapisuje.
### `tokens update REMOTE_ID`
Pobiera z API metadane dla rekordu `REMOTE_ID` juz zapisanego w `tokens.json`.
Nie zmienia git remote URL-a i nie kopiuje sekretu z remote.
```bash
./rvctl tokens update r1
./rvctl tokens update r1 --dry-run
```
### `tokens sync store REMOTE_ID`
Zapisuje dane z rekordu `REMOTE_ID` w `tokens.json` do git remote o tej samej
nazwie.
```bash
./rvctl tokens sync store r1 --repo ~/dev/workspace/rv/series/inf/03
./rvctl tokens sync store r1 --repo PATH --replace
```
### `tokens read`
@@ -163,16 +216,16 @@ Pokazuje zawartosc `tokens.json`.
### `tokens add`
Dodaje pusty szkielet tokena do `tokens.json`. Pole `value` zostaje puste, zeby
mozna bylo recznie wkleic sekret.
Dodaje pusty szkielet rekordu do `tokens.json`. `REMOTE_ID` musi odpowiadac
nazwie git remote.
```bash
./rvctl tokens add t1
./rvctl tokens add r6 --server http://77.90.8.171:3001
./rvctl tokens add t1 --remote r1 --org edu-tools --repo rv-launcher
./rvctl tokens add r1
./rvctl tokens add r1 --server http://77.90.8.171:3001 --user u1 --org edu-tools --repo rv-launcher
```
`tokens write` nie uzyje pustego tokena. Najpierw trzeba uzupelnic `value`.
`tokens sync store r1` nie uzyje pustego tokena. Najpierw trzeba uzupelnic
`value` i `user`.
### `tokens stats`
@@ -182,23 +235,12 @@ Pokazuje kontekst, tabele `tokens` i podsumowanie statusow endpointow.
./rvctl tokens stats --repo ~/dev/workspace/rv/series/inf/03
```
### `tokens write`
### Komendy zgodnosci
Zapisuje wybrany token z `tokens.json` do remote URL-a repo.
Stare komendy nadal dzialaja, ale sa mniej jednoznaczne:
```bash
./rvctl tokens write \
--repo ~/dev/workspace/rv/series/inf/03 \
--remote r1 \
--server http://77.90.8.171:3001 \
--token-name t1
```
### `tokens update --from store`
Alias kierunkowy na zapis store -> remote. Uzywa tych samych opcji co
`tokens write`.
```bash
./rvctl tokens update --from store --repo PATH --remote r1 --server http://77.90.8.171:3001 --token-name t1
./rvctl tokens update --from remotes --repo PATH
./rvctl tokens update --from store --repo PATH --remote r1 --server http://77.90.8.171:3001
./rvctl tokens write --repo PATH --remote r1 --server http://77.90.8.171:3001
```
+123 -41
View File
@@ -42,14 +42,125 @@
}
}
},
"remote": {
"scope_permissions": {
"type": "object",
"additionalProperties": false,
"required": ["name", "org", "repo"],
"required": ["a", "A", "i", "m", "n", "o", "p", "r", "u"],
"properties": {
"name": {
"a": {
"$ref": "#/$defs/scope_value",
"description": "activitypub"
},
"A": {
"$ref": "#/$defs/scope_value",
"description": "admin"
},
"i": {
"$ref": "#/$defs/scope_value",
"description": "issue"
},
"m": {
"$ref": "#/$defs/scope_value",
"description": "misc"
},
"n": {
"$ref": "#/$defs/scope_value",
"description": "notification"
},
"o": {
"$ref": "#/$defs/scope_value",
"description": "organization"
},
"p": {
"$ref": "#/$defs/scope_value",
"description": "package"
},
"r": {
"$ref": "#/$defs/scope_value",
"description": "repository"
},
"u": {
"$ref": "#/$defs/scope_value",
"description": "user"
}
}
},
"org_permissions": {
"type": "object",
"additionalProperties": false,
"required": ["o", "a", "w", "r", "c"],
"properties": {
"o": {
"$ref": "#/$defs/flag_value",
"description": "owner"
},
"a": {
"$ref": "#/$defs/flag_value",
"description": "admin"
},
"w": {
"$ref": "#/$defs/flag_value",
"description": "write"
},
"r": {
"$ref": "#/$defs/flag_value",
"description": "read"
},
"c": {
"$ref": "#/$defs/flag_value",
"description": "create repository"
}
}
},
"repo_permissions": {
"type": "object",
"additionalProperties": false,
"required": ["o", "a", "w", "r"],
"properties": {
"o": {
"$ref": "#/$defs/flag_value",
"description": "owner"
},
"a": {
"$ref": "#/$defs/flag_value",
"description": "admin"
},
"w": {
"$ref": "#/$defs/flag_value",
"description": "write"
},
"r": {
"$ref": "#/$defs/flag_value",
"description": "read"
}
}
},
"scope_value": {
"enum": ["w", "r", "-", "?", "!"]
},
"flag_value": {
"enum": ["+", "-", "?", "!"]
},
"token": {
"type": "object",
"additionalProperties": false,
"required": ["id", "value", "server", "org", "repo"],
"properties": {
"id": {
"type": "string",
"minLength": 1
"minLength": 1,
"description": "Git remote name, for example r1 or r1a."
},
"value": {
"type": "string",
"description": "Token secret. May be empty only in a manual skeleton."
},
"server": {
"$ref": "#/$defs/server"
},
"user": {
"type": "string",
"description": "User/login used in the authenticated remote URL."
},
"org": {
"type": "string"
@@ -57,49 +168,20 @@
"repo": {
"type": "string"
},
"org_perm": {
"type": "string",
"pattern": "^[+?!-]{5}$"
},
"repo_perm": {
"type": "string",
"pattern": "^[+?!-]{4}$"
}
}
},
"token": {
"type": "object",
"additionalProperties": false,
"required": ["token_id", "value", "server", "remotes"],
"properties": {
"token_id": {
"type": "string",
"minLength": 1
},
"value": {
"type": "string"
},
"server": {
"$ref": "#/$defs/server"
},
"user": {
"type": "string"
},
"valid": {
"type": "string"
},
"scope": {
"type": "string",
"pattern": "^[rw?!-]{9}$"
},
"expires_at": {
"type": "string"
},
"remotes": {
"type": "array",
"items": {
"$ref": "#/$defs/remote"
}
"scope": {
"$ref": "#/$defs/scope_permissions"
},
"org_perm": {
"$ref": "#/$defs/org_permissions"
},
"repo_perm": {
"$ref": "#/$defs/repo_permissions"
}
}
}