refactor(zli): add typed ~/.zot config layer and strict validation (#4030)

feat(cli): add typed ~/.zot config layer and strict validation

Introduce pkg/cli/client/config.go with ZliConfigFile/ZliConfig and
ReadZliConfigFile, replacing the loose map[string]any load/save path in
config_cmd.go.

Parsing now rejects malformed JSON with ErrCliBadConfig and requires a
non-null configs array (ErrCliMissingConfigsField when wrapped). Each
profile must have non-empty _name and url.

Config commands delegate to typed helpers (Find, AddEntry, RemoveEntry,
GetVar/SetVar/ResetVar, FormatNames, WriteFile). Fresh or minimal files
still behave as empty via isFreshCliRead (ErrEmptyJSON or missing configs).

Tests: prefer t.Setenv("HOME", t.TempDir()) where CLI resolution uses --url
only; align CVE/client/search tests with mandatory profile URL and HOME
isolation.

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
Andrei Aaron
2026-05-05 08:52:59 +03:00
committed by GitHub
parent 7ec34a9520
commit fa92366009
11 changed files with 1060 additions and 404 deletions
+1
View File
@@ -49,6 +49,7 @@ func GetDetails(err error) map[string]string {
var (
ErrBadConfig = errors.New("invalid server config")
ErrCliBadConfig = errors.New("invalid cli config")
ErrCliMissingConfigsField = errors.New(`missing or null "configs" field`)
ErrRepoNotFound = errors.New("repository not found")
ErrRepoBadVersion = errors.New("unsupported repository layout version")
ErrRepoBadLayout = errors.New("invalid repository layout")