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

Unified Diff: appengine/logdog/coordinator/context.go

Issue 1910633006: LogDog: Support per-namespace expired archival. (Closed) Base URL: https://github.com/luci/luci-go@logdog-coordinator-svcdec
Patch Set: Switch to Tumble delayed mutations. Created 4 years, 8 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
Index: appengine/logdog/coordinator/context.go
diff --git a/appengine/logdog/coordinator/context.go b/appengine/logdog/coordinator/context.go
index 7f212b02e4a0beba918918253ef66c7dce043d4f..04a66d3d9e15a2afc8280cab6e228487c2644de0 100644
--- a/appengine/logdog/coordinator/context.go
+++ b/appengine/logdog/coordinator/context.go
@@ -5,6 +5,11 @@
package coordinator
import (
+ "fmt"
+
+ "github.com/luci/gae/service/info"
+ "github.com/luci/luci-go/common/config"
+ log "github.com/luci/luci-go/common/logging"
"golang.org/x/net/context"
)
@@ -25,3 +30,63 @@ func GetServices(c context.Context) Services {
}
return s
}
+
+// WithProjectNamespace sets the current namespace to the project name.
+//
+// It will fail if either the project name or the project's namespace is
+// invalid. In the event of an error, the original Context will be returned for
+// convenience.
iannucci 2016/04/29 20:09:42 the original Context will not be modified or inval
dnj 2016/04/29 23:04:20 Done.
+func WithProjectNamespace(c *context.Context, project config.ProjectName) error {
+ // TODO(dnj): REQUIRE this to be non-empty once namespacing is mandatory.
+ if project == "" {
+ log.Debugf(*c, "Using default namespace.")
+ return nil
+ }
+
+ if err := project.Validate(); err != nil {
+ log.Fields{
+ log.ErrorKey: err,
+ "project": project,
+ }.Errorf(*c, "Project name is invalid.")
+ return err
+ }
+
+ pns := ProjectNamespace(project)
+ nc, err := info.Get(*c).Namespace(pns)
+ if err != nil {
+ log.Fields{
+ log.ErrorKey: err,
+ "project": project,
+ "namespace": pns,
+ }.Errorf(*c, "Failed to set namespace.")
+ return err
+ }
+
+ log.Fields{
+ "project": project,
+ }.Debugf(*c, "Using project namespace.")
+ *c = nc
+ return nil
+}
+
+// Project returns the current project installed in the supplied Context's
+// namespace.
+//
+// This function is called with the expectation that the Context is in a
+// namespace conforming to ProjectNamespace. If this is not the case, this
+// method will panic.
+func Project(c context.Context) config.ProjectName {
+ ns, _ := info.Get(c).GetNamespace()
+
+ // TODO(dnj): Remove the empty namespace/project exception once we no longer
+ // support that.
+ if ns == "" {
+ return ""
+ }
+
+ project := ProjectFromNamespace(ns)
+ if project != "" {
+ return project
+ }
+ panic(fmt.Errorf("current namespace %q does not begin with project namespace prefix (%q)", ns, projectNamespacePrefix))
+}

Powered by Google App Engine
This is Rietveld 408576698