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

Side by Side Diff: server/config/naming.go

Issue 2580713002: Implement a server-side config service interface. (Closed)
Patch Set: Update MultiResolver interface, add test for MultiError. Created 4 years 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
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package config
6
7 import (
8 "fmt"
9 "strings"
10
11 "github.com/luci/gae/service/info"
12 "github.com/luci/luci-go/common/config"
13
14 "golang.org/x/net/context"
15 )
16
17 // ProjectConfigPath is the path of a project's project-wide configuration file.
18 const ProjectConfigPath = "project.cfg"
19
20 // ServiceConfigSet returns the name of a config set for the specified service.
21 func ServiceConfigSet(name string) string { return fmt.Sprintf("services/%s", na me) }
iannucci 2017/01/07 20:12:16 do you think it would be worth having a small `typ
dnj 2017/01/10 03:25:58 Yep, made "luci_config/common/cfgtypes" for this,
22
23 // CurrentServiceName returns the current service name, as used to identify it
24 // in configurations. This is based on the current App ID.
25 func CurrentServiceName(c context.Context) string { return info.TrimmedAppID(c) }
26
27 // CurrentServiceConfigSet returns the config set for the current AppEngine
28 // service, based on its current service name.
29 func CurrentServiceConfigSet(c context.Context) string { return ServiceConfigSet (CurrentServiceName(c)) }
30
31 // ProjectConfigSet returns the name of a config set for the specified project.
32 func ProjectConfigSet(project config.ProjectName) string { return fmt.Sprintf("p rojects/%s", project) }
33
34 // ParseProjectConfigSet parses a project-rooted config set
35 // (projects/<name>[/...]) into its project name, project config set, and tail
36 // components.
37 //
38 // For example, "projects/foo/bar/baz" is a config set that belongs to project
39 // "foo". It will be parsed into:
40 // - project: "foo"
41 // - projectConfigSet: "projects/foo"
42 // - tail: "bar/baz"
43 //
44 // If configSet is not a project config set, empty strings will be returned.
45 func ParseProjectConfigSet(configSet string) (project config.ProjectName, projec tConfigSet, tail string) {
46 parts := strings.SplitN(configSet, "/", 3)
47 if len(parts) < 2 || parts[0] != "projects" {
48 // Not a project config set, so neither remaining Authority can access.
49 return
50 }
51
52 // The project is the first part.
53 project = config.ProjectName(parts[1])
54
55 // Re-assemble the project part of the config set ("projects/foo").
56 projectConfigSet = configSet[:len("projects/")+len(project)]
57 if len(parts) > 2 {
58 tail = parts[2]
59 }
60 return
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698