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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: server/config/naming.go
diff --git a/server/config/naming.go b/server/config/naming.go
new file mode 100644
index 0000000000000000000000000000000000000000..5c7075a8824f46b87eee64929977725bfcecbe88
--- /dev/null
+++ b/server/config/naming.go
@@ -0,0 +1,61 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package config
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/luci/gae/service/info"
+ "github.com/luci/luci-go/common/config"
+
+ "golang.org/x/net/context"
+)
+
+// ProjectConfigPath is the path of a project's project-wide configuration file.
+const ProjectConfigPath = "project.cfg"
+
+// ServiceConfigSet returns the name of a config set for the specified service.
+func ServiceConfigSet(name string) string { return fmt.Sprintf("services/%s", name) }
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,
+
+// CurrentServiceName returns the current service name, as used to identify it
+// in configurations. This is based on the current App ID.
+func CurrentServiceName(c context.Context) string { return info.TrimmedAppID(c) }
+
+// CurrentServiceConfigSet returns the config set for the current AppEngine
+// service, based on its current service name.
+func CurrentServiceConfigSet(c context.Context) string { return ServiceConfigSet(CurrentServiceName(c)) }
+
+// ProjectConfigSet returns the name of a config set for the specified project.
+func ProjectConfigSet(project config.ProjectName) string { return fmt.Sprintf("projects/%s", project) }
+
+// ParseProjectConfigSet parses a project-rooted config set
+// (projects/<name>[/...]) into its project name, project config set, and tail
+// components.
+//
+// For example, "projects/foo/bar/baz" is a config set that belongs to project
+// "foo". It will be parsed into:
+// - project: "foo"
+// - projectConfigSet: "projects/foo"
+// - tail: "bar/baz"
+//
+// If configSet is not a project config set, empty strings will be returned.
+func ParseProjectConfigSet(configSet string) (project config.ProjectName, projectConfigSet, tail string) {
+ parts := strings.SplitN(configSet, "/", 3)
+ if len(parts) < 2 || parts[0] != "projects" {
+ // Not a project config set, so neither remaining Authority can access.
+ return
+ }
+
+ // The project is the first part.
+ project = config.ProjectName(parts[1])
+
+ // Re-assemble the project part of the config set ("projects/foo").
+ projectConfigSet = configSet[:len("projects/")+len(project)]
+ if len(parts) > 2 {
+ tail = parts[2]
+ }
+ return
+}

Powered by Google App Engine
This is Rietveld 408576698