Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: milo/appengine/common/config.go

Issue 2748073006: Milo Refactor: Remove theme support (Closed)
Patch Set: Review Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package settings 5 package common
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 9
10 ds "github.com/luci/gae/service/datastore" 10 ds "github.com/luci/gae/service/datastore"
11 "github.com/luci/gae/service/info" 11 "github.com/luci/gae/service/info"
12 "github.com/luci/luci-go/common/logging" 12 "github.com/luci/luci-go/common/logging"
13 "github.com/luci/luci-go/luci_config/server/cfgclient" 13 "github.com/luci/luci-go/luci_config/server/cfgclient"
14 "github.com/luci/luci-go/luci_config/server/cfgclient/textproto" 14 "github.com/luci/luci-go/luci_config/server/cfgclient/textproto"
15 » milocfg "github.com/luci/luci-go/milo/common/config" 15 » "github.com/luci/luci-go/milo/common/config"
16 "github.com/luci/luci-go/server/router" 16 "github.com/luci/luci-go/server/router"
17 17
18 "github.com/golang/protobuf/proto" 18 "github.com/golang/protobuf/proto"
19 "golang.org/x/net/context" 19 "golang.org/x/net/context"
20 ) 20 )
21 21
22 // Project is a LUCI project. 22 // Project is a LUCI project.
23 type Project struct { 23 type Project struct {
24 // The ID of the project, as per self defined. This is not the luci-cfg 24 // The ID of the project, as per self defined. This is not the luci-cfg
25 // name. 25 // name.
(...skipping 16 matching lines...) Expand all
42 h.WriteHeader(200) 42 h.WriteHeader(200)
43 } 43 }
44 44
45 // Update internal configuration based off luci-cfg. 45 // Update internal configuration based off luci-cfg.
46 // update updates Milo's configuration based off luci config. This includes 46 // update updates Milo's configuration based off luci config. This includes
47 // scanning through all project and extract all console configs. 47 // scanning through all project and extract all console configs.
48 func Update(c context.Context) error { 48 func Update(c context.Context) error {
49 cfgName := info.AppID(c) + ".cfg" 49 cfgName := info.AppID(c) + ".cfg"
50 50
51 var ( 51 var (
52 » » configs []*milocfg.Project 52 » » configs []*config.Project
53 metas []*cfgclient.Meta 53 metas []*cfgclient.Meta
54 ) 54 )
55 if err := cfgclient.Projects(c, cfgclient.AsService, cfgName, textproto. Slice(&configs), &metas); err != nil { 55 if err := cfgclient.Projects(c, cfgclient.AsService, cfgName, textproto. Slice(&configs), &metas); err != nil {
56 logging.WithError(err).Errorf(c, "Encountered error while gettin g project config for %s", cfgName) 56 logging.WithError(err).Errorf(c, "Encountered error while gettin g project config for %s", cfgName)
57 return err 57 return err
58 } 58 }
59 59
60 // A map of project ID to project. 60 // A map of project ID to project.
61 projects := map[string]*Project{} 61 projects := map[string]*Project{}
62 for i, proj := range configs { 62 for i, proj := range configs {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if _, ok := projects[proj.ID]; !ok { 98 if _, ok := projects[proj.ID]; !ok {
99 toDelete = append(toDelete, proj) 99 toDelete = append(toDelete, proj)
100 } 100 }
101 } 101 }
102 ds.Delete(c, toDelete) 102 ds.Delete(c, toDelete)
103 103
104 return nil 104 return nil
105 } 105 }
106 106
107 // GetAllProjects returns all registered projects. 107 // GetAllProjects returns all registered projects.
108 func GetAllProjects(c context.Context) ([]*milocfg.Project, error) { 108 func GetAllProjects(c context.Context) ([]*config.Project, error) {
109 q := ds.NewQuery("Project") 109 q := ds.NewQuery("Project")
110 q.Order("ID") 110 q.Order("ID")
111 111
112 ps := []*Project{} 112 ps := []*Project{}
113 err := ds.GetAll(c, q, &ps) 113 err := ds.GetAll(c, q, &ps)
114 if err != nil { 114 if err != nil {
115 return nil, err 115 return nil, err
116 } 116 }
117 » results := make([]*milocfg.Project, len(ps)) 117 » results := make([]*config.Project, len(ps))
118 for i, p := range ps { 118 for i, p := range ps {
119 » » results[i] = &milocfg.Project{} 119 » » results[i] = &config.Project{}
120 if err := proto.Unmarshal(p.Data, results[i]); err != nil { 120 if err := proto.Unmarshal(p.Data, results[i]); err != nil {
121 return nil, err 121 return nil, err
122 } 122 }
123 } 123 }
124 return results, nil 124 return results, nil
125 } 125 }
126 126
127 // GetProject returns the requested project. 127 // GetProject returns the requested project.
128 func GetProject(c context.Context, projName string) (*milocfg.Project, error) { 128 func GetProject(c context.Context, projName string) (*config.Project, error) {
129 // Next, Try datastore 129 // Next, Try datastore
130 p := Project{ID: projName} 130 p := Project{ID: projName}
131 if err := ds.Get(c, &p); err != nil { 131 if err := ds.Get(c, &p); err != nil {
132 return nil, err 132 return nil, err
133 } 133 }
134 » mp := milocfg.Project{} 134 » mp := config.Project{}
135 if err := proto.Unmarshal(p.Data, &mp); err != nil { 135 if err := proto.Unmarshal(p.Data, &mp); err != nil {
136 return nil, err 136 return nil, err
137 } 137 }
138 138
139 return &mp, nil 139 return &mp, nil
140 } 140 }
141 141
142 // GetConsole returns the requested console instance. 142 // GetConsole returns the requested console instance.
143 func GetConsole(c context.Context, projName, consoleName string) (*milocfg.Conso le, error) { 143 func GetConsole(c context.Context, projName, consoleName string) (*config.Consol e, error) {
144 p, err := GetProject(c, projName) 144 p, err := GetProject(c, projName)
145 if err != nil { 145 if err != nil {
146 return nil, err 146 return nil, err
147 } 147 }
148 for _, cs := range p.Consoles { 148 for _, cs := range p.Consoles {
149 if cs.Name == consoleName { 149 if cs.Name == consoleName {
150 return cs, nil 150 return cs, nil
151 } 151 }
152 } 152 }
153 return nil, fmt.Errorf("Console %s not found in project %s", consoleName , projName) 153 return nil, fmt.Errorf("Console %s not found in project %s", consoleName , projName)
154 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698