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

Unified Diff: luci_config/common/cfgtypes/config_set.go

Issue 2626433004: Move "common/config" common types into cfgtypes. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « logdog/server/service/service.go ('k') | luci_config/common/cfgtypes/config_set_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: luci_config/common/cfgtypes/config_set.go
diff --git a/luci_config/common/cfgtypes/config_set.go b/luci_config/common/cfgtypes/config_set.go
new file mode 100644
index 0000000000000000000000000000000000000000..b2a61aa9a364dd0256b2f6332fe89f265ba98b47
--- /dev/null
+++ b/luci_config/common/cfgtypes/config_set.go
@@ -0,0 +1,75 @@
+// 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 cfgtypes
+
+import (
+ "strings"
+)
+
+// ConfigSet is a configuration service Config Set string.
+//
+// A config set consists of a domain and a series of path components:
+// domain/target/refs...
+//
+// - Service config sets are config sets in the "services" domain, with the
+// service name as the target.
+// - Project config sets are config sets in the "projects" domain. The target
+// is the project name.
+type ConfigSet string
+
+// ServiceConfigSet returns the name of a config set for the specified service.
+func ServiceConfigSet(name string) ConfigSet { return ConfigSet("services/" + name) }
+
+// ProjectConfigSet returns the config set for the specified project.
+func ProjectConfigSet(name ProjectName) ConfigSet { return RefConfigSet(name, "") }
+
+// RefConfigSet returns the config set for the specified project and ref. If ref
+// is empty, this will equal the ProjectConfigSet value.
+func RefConfigSet(name ProjectName, ref string) ConfigSet {
+ if ref == "" {
+ return ConfigSet("projects/" + string(name))
+ }
+ return ConfigSet(strings.Join([]string{"projects", string(name), ref}, "/"))
+}
+
+// Split splits a ConfigSet into its domain, target, and ref components.
+func (cs ConfigSet) Split() (domain, target, ref string) {
+ switch p := strings.SplitN(string(cs), "/", 3); len(p) {
+ case 1:
+ return p[0], "", ""
+ case 2:
+ return p[0], p[1], ""
+ default:
+ return p[0], p[1], p[2]
+ }
+}
+
+// SplitProject splits a project-rooted config set (projects/<name>[/...]) into
+// its project name, project config set, and ref 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"
+// - ref: "bar/baz"
+//
+// If configSet is not a project config set, empty strings will be returned.
+func (cs ConfigSet) SplitProject() (project ProjectName, projectConfigSet ConfigSet, ref string) {
+ parts := strings.SplitN(string(cs), "/", 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 = ProjectName(parts[1])
+
+ // Re-assemble the project part of the config set ("projects/foo").
+ projectConfigSet = cs[:len("projects/")+len(project)]
+ if len(parts) > 2 {
+ ref = parts[2]
+ }
+ return
+}
« no previous file with comments | « logdog/server/service/service.go ('k') | luci_config/common/cfgtypes/config_set_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698