Skip to content

Commit

Permalink
Fix cozy-stack config ls-contexts (#4209)
Browse files Browse the repository at this point in the history
When the default context has no configuration, it should still be listed
with the `cozy-stack config ls-contexts` command. It has a list of
registries.
  • Loading branch information
nono authored Nov 7, 2023
2 parents 9c4c1a0 + 5339a77 commit 906f44d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions web/instances/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ func showContext(c echo.Context) error {
contexts := config.GetConfig().Contexts
cfg, ok := contexts[contextName].(map[string]interface{})
if !ok {
return c.NoContent(http.StatusNotFound)
registries := config.GetConfig().Registries
_, ok := registries[contextName]
if !ok {
return c.NoContent(http.StatusNotFound)
}
}
return c.JSON(http.StatusOK, getContextAPI(contextName, cfg))
}

func lsContexts(c echo.Context) error {
contexts := config.GetConfig().Contexts

result := []contextAPI{}
for contextName, ctx := range contexts {
cfg, ok := ctx.(map[string]interface{})
Expand All @@ -42,6 +45,11 @@ func lsContexts(c echo.Context) error {
}
result = append(result, getContextAPI(contextName, cfg))
}
for contextName := range config.GetConfig().Registries {
if _, ok := contexts[contextName]; !ok {
result = append(result, getContextAPI(contextName, nil))
}
}
return c.JSON(http.StatusOK, result)
}

Expand Down

0 comments on commit 906f44d

Please sign in to comment.