Chromium Code Reviews| Index: milo/appengine/common/config.go |
| diff --git a/milo/appengine/common/config.go b/milo/appengine/common/config.go |
| index 72e3a2ad5c47bf85a46d587c4d50f2d1ad7d721a..a0c7364d22a7fb1d7a3fdf5b3abeaefe813dbdb2 100644 |
| --- a/milo/appengine/common/config.go |
| +++ b/milo/appengine/common/config.go |
| @@ -5,9 +5,10 @@ |
| package common |
| import ( |
| + "errors" |
| "fmt" |
| - ds "github.com/luci/gae/service/datastore" |
| + "github.com/luci/gae/service/datastore" |
| "github.com/luci/gae/service/info" |
| "github.com/luci/luci-go/common/logging" |
| "github.com/luci/luci-go/luci_config/server/cfgclient" |
| @@ -29,10 +30,32 @@ type Project struct { |
| Data []byte `gae:",noindex"` |
| } |
| -// Update internal configuration based off luci-cfg. |
| +var errNotConfigured = errors.New("milo instance is missing settings.cfg") |
| + |
| +// GetServiceConfig returns the service (aka global) config for the current |
| +// instance of Milo. |
| +func GetSettings(c context.Context) (*config.Settings, error) { |
| + cs := cfgclient.CurrentServiceConfigSet(c) |
| + var content string |
| + // Our global config name is called settings.cfg. |
| + err := cfgclient.Get(c, cfgclient.AsService, cs, "settings.cfg", cfgclient.String(&content), nil) |
|
nodir
2017/03/20 21:41:32
this API call should be used in serving path. Luci
hinoka
2017/03/20 22:19:26
Done.
|
| + switch err { |
| + case cfgclient.ErrNoConfig: |
| + return nil, errNotConfigured |
|
nodir
2017/03/20 21:41:32
this will cause http500s on all requests, I assume
hinoka
2017/03/20 22:19:26
Done.
|
| + case nil: |
| + // continue |
| + default: |
| + return nil, err |
| + } |
| + msg := &config.Settings{} |
| + err = proto.UnmarshalText(content, msg) |
|
nodir
2017/03/20 21:41:32
make sure the config is stored in binary so we can
hinoka
2017/03/20 22:19:26
Done.
|
| + return msg, err |
| +} |
| + |
| +// UpdateProjectConfigs internal project configuration based off luci-cfg. |
| // update updates Milo's configuration based off luci config. This includes |
| // scanning through all project and extract all console configs. |
| -func Update(c context.Context) error { |
| +func UpdateProjectConfigs(c context.Context) error { |
| cfgName := info.AppID(c) + ".cfg" |
| var ( |
| @@ -72,32 +95,32 @@ func Update(c context.Context) error { |
| for _, proj := range projects { |
| projs = append(projs, proj) |
| } |
| - if err := ds.Put(c, projs); err != nil { |
| + if err := datastore.Put(c, projs); err != nil { |
| return err |
| } |
| // Delete entries that no longer exist. |
| - q := ds.NewQuery("Project").KeysOnly(true) |
| + q := datastore.NewQuery("Project").KeysOnly(true) |
| allProjs := []Project{} |
| - ds.GetAll(c, q, &allProjs) |
| + datastore.GetAll(c, q, &allProjs) |
| toDelete := []Project{} |
| for _, proj := range allProjs { |
| if _, ok := projects[proj.ID]; !ok { |
| toDelete = append(toDelete, proj) |
| } |
| } |
| - ds.Delete(c, toDelete) |
| + datastore.Delete(c, toDelete) |
| return nil |
| } |
| // GetAllProjects returns all registered projects. |
| func GetAllProjects(c context.Context) ([]*config.Project, error) { |
| - q := ds.NewQuery("Project") |
| + q := datastore.NewQuery("Project") |
| q.Order("ID") |
| ps := []*Project{} |
| - err := ds.GetAll(c, q, &ps) |
| + err := datastore.GetAll(c, q, &ps) |
| if err != nil { |
| return nil, err |
| } |
| @@ -115,7 +138,7 @@ func GetAllProjects(c context.Context) ([]*config.Project, error) { |
| func GetProject(c context.Context, projName string) (*config.Project, error) { |
| // Next, Try datastore |
| p := Project{ID: projName} |
| - if err := ds.Get(c, &p); err != nil { |
| + if err := datastore.Get(c, &p); err != nil { |
| return nil, err |
| } |
| mp := config.Project{} |