Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(721)

Unified Diff: dashboard/app/build/key.go

Issue 12180043: code review 12180043: go.tools: add dashboard
Patch Set: diff -r 79ec8d3bcf1d https://code.google.com/p/go/ Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dashboard/app/build/init.go ('k') | dashboard/app/build/notify.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dashboard/app/build/key.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/dashboard/app/build/key.go
@@ -0,0 +1,64 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build appengine
+
+package build
+
+import (
+ "sync"
+
+ "appengine"
+ "appengine/datastore"
+)
+
+var theKey struct {
+ sync.RWMutex
+ BuilderKey
+}
+
+type BuilderKey struct {
+ Secret string
+}
+
+func (k *BuilderKey) Key(c appengine.Context) *datastore.Key {
+ return datastore.NewKey(c, "BuilderKey", "root", 0, nil)
+}
+
+func secretKey(c appengine.Context) string {
+ // check with rlock
+ theKey.RLock()
+ k := theKey.Secret
+ theKey.RUnlock()
+ if k != "" {
+ return k
+ }
+
+ // prepare to fill; check with lock and keep lock
+ theKey.Lock()
+ defer theKey.Unlock()
+ if theKey.Secret != "" {
+ return theKey.Secret
+ }
+
+ // fill
+ if err := datastore.Get(c, theKey.Key(c), &theKey.BuilderKey); err != nil {
+ if err == datastore.ErrNoSuchEntity {
+ // If the key is not stored in datastore, write it.
+ // This only happens at the beginning of a new deployment.
+ // The code is left here for SDK use and in case a fresh
+ // deployment is ever needed. "gophers rule" is not the
+ // real key.
+ if !appengine.IsDevAppServer() {
+ panic("lost key from datastore")
+ }
+ theKey.Secret = "gophers rule"
+ datastore.Put(c, theKey.Key(c), &theKey.BuilderKey)
+ return theKey.Secret
+ }
+ panic("cannot load builder key: " + err.Error())
+ }
+
+ return theKey.Secret
+}
« no previous file with comments | « dashboard/app/build/init.go ('k') | dashboard/app/build/notify.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b