installer-api: include config in app
diff --git a/core/installer/app_manager.go b/core/installer/app_manager.go
index f2e4369..fbf69d1 100644
--- a/core/installer/app_manager.go
+++ b/core/installer/app_manager.go
@@ -3,6 +3,7 @@
import (
"fmt"
"io/fs"
+ "io/ioutil"
"net"
"time"
@@ -50,6 +51,25 @@
return config, nil
}
+func (m *AppManager) AppConfig(name string) (map[string]any, error) {
+ wt, err := m.repo.Worktree()
+ if err != nil {
+ return nil, err
+ }
+ configF, err := wt.Filesystem.Open(wt.Filesystem.Join(appDirName, name, configFileName))
+ if err != nil {
+ return nil, err
+ }
+ defer configF.Close()
+ var cfg map[string]any
+ contents, err := ioutil.ReadAll(configF)
+ if err != nil {
+ return cfg, err
+ }
+ err = yaml.UnmarshalStrict(contents, &cfg)
+ return cfg, err
+}
+
func (m *AppManager) Install(app App, config map[string]any) error {
wt, err := m.repo.Worktree()
if err != nil {
diff --git a/core/installer/cmd/app_manager.go b/core/installer/cmd/app_manager.go
index 249dcfb..b1e8135 100644
--- a/core/installer/cmd/app_manager.go
+++ b/core/installer/cmd/app_manager.go
@@ -101,9 +101,10 @@
}
type app struct {
- Name string `json:"name"`
- Slug string `json:"slug"`
- Schema string `json:"schema"`
+ Name string `json:"name"`
+ Slug string `json:"slug"`
+ Schema string `json:"schema"`
+ Config map[string]any `json:"config"`
}
func (s *server) handleAppRepo(c echo.Context) error {
@@ -113,7 +114,8 @@
}
resp := make([]app, len(all))
for i, a := range all {
- resp[i] = app{a.Name, a.Name, a.Schema}
+ config, _ := s.m.AppConfig(a.Name) // TODO(gio): handle error
+ resp[i] = app{a.Name, a.Name, a.Schema, config}
}
return c.JSON(http.StatusOK, resp)
}
@@ -124,7 +126,8 @@
if err != nil {
return err
}
- return c.JSON(http.StatusOK, app{a.Name, a.Name, a.Schema})
+ config, _ := s.m.AppConfig(a.Name) // TODO(gio): handle error
+ return c.JSON(http.StatusOK, app{a.Name, a.Name, a.Schema, config})
}
type file struct {