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

Side by Side Diff: appengine/logdog/coordinator/config/projects.go

Issue 1971623002: LogDog: Enable Coordinator to load project configs (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-config
Patch Set: Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package config 5 package config
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "strings" 9 "strings"
10 10
11 "github.com/golang/protobuf/proto" 11 "github.com/golang/protobuf/proto"
12 "github.com/luci/luci-go/common/config" 12 "github.com/luci/luci-go/common/config"
13 "github.com/luci/luci-go/common/errors" 13 "github.com/luci/luci-go/common/errors"
14 log "github.com/luci/luci-go/common/logging" 14 log "github.com/luci/luci-go/common/logging"
15 "github.com/luci/luci-go/common/parallel" 15 "github.com/luci/luci-go/common/parallel"
16 configProto "github.com/luci/luci-go/common/proto/config" 16 configProto "github.com/luci/luci-go/common/proto/config"
17 "github.com/luci/luci-go/common/proto/logdog/svcconfig"
17 "github.com/luci/luci-go/server/auth" 18 "github.com/luci/luci-go/server/auth"
18 "github.com/luci/luci-go/server/auth/identity" 19 "github.com/luci/luci-go/server/auth/identity"
19 "golang.org/x/net/context" 20 "golang.org/x/net/context"
20 ) 21 )
21 22
22 const maxProjectWorkers = 32 23 const maxProjectWorkers = 32
23 24
24 // ErrNoAccess is returned if the user has no access to the requested project. 25 // ErrNoAccess is returned if the user has no access to the requested project.
25 var ErrNoAccess = errors.New("no access") 26 var ErrNoAccess = errors.New("no access")
26 27
28 // ProjectConfigPath returns the config set and path for project-specific
29 // configuration.
30 func ProjectConfigPath(project config.ProjectName) (string, string) {
31 return fmt.Sprintf("projects/%s", project), svcconfig.ProjectConfigFilen ame
32 }
33
34 // ProjectConfig loads the the project config protobuf from the config service.
nodir 2016/05/18 16:05:35 the the
dnj (Google) 2016/05/18 16:46:06 Done.
35 //
36 // If the configuration was not present, config.ErrNoConfig will be returned.
37 func ProjectConfig(c context.Context, project config.ProjectName) (*svcconfig.Pr ojectConfig, error) {
38 configSet, configPath := ProjectConfigPath(project)
39 cfg, err := config.Get(c).GetConfig(configSet, configPath, false)
40 if err != nil {
41 return nil, err
42 }
43
44 var pcfg svcconfig.ProjectConfig
45 if err := proto.UnmarshalText(cfg.Content, &pcfg); err != nil {
46 log.Fields{
47 log.ErrorKey: err,
48 "contentHash": cfg.ContentHash,
49 "path": cfg.Path,
50 "configSet": cfg.ConfigSet,
nodir 2016/05/18 16:05:35 somewhat sort keys?
dnj (Google) 2016/05/18 16:46:06 I'll put them in a logically-useful order, so in t
51 }.Errorf(c, "Failed to unmarshal project configuration.")
52 return nil, ErrInvalidConfig
53 }
54
55 return &pcfg, nil
56 }
57
27 // Projects lists the registered LogDog projects. 58 // Projects lists the registered LogDog projects.
28 func Projects(c context.Context) ([]string, error) { 59 func Projects(c context.Context) ([]string, error) {
29 projects, err := config.Get(c).GetProjects() 60 projects, err := config.Get(c).GetProjects()
30 if err != nil { 61 if err != nil {
31 log.WithError(err).Errorf(c, "Failed to list 'luci-config' proje cts.") 62 log.WithError(err).Errorf(c, "Failed to list 'luci-config' proje cts.")
32 return nil, err 63 return nil, err
33 } 64 }
34 65
35 // TODO(dnj): Filter this list to projects with active LogDog configs, o nce we 66 // TODO(dnj): Filter this list to projects with active LogDog configs, o nce we
36 // move to project-specific configurations. 67 // move to project-specific configurations.
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 252
222 return false, nil 253 return false, nil
223 } 254 }
224 255
225 func trimPrefix(s, p string) (string, bool) { 256 func trimPrefix(s, p string) (string, bool) {
226 if strings.HasPrefix(s, p) { 257 if strings.HasPrefix(s, p) {
227 return s[len(p):], true 258 return s[len(p):], true
228 } 259 }
229 return s, false 260 return s, false
230 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698