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

Unified Diff: impl/cloud/info.go

Issue 1957953002: Add cloud datastore implementation. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 7 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: impl/cloud/info.go
diff --git a/impl/cloud/info.go b/impl/cloud/info.go
new file mode 100644
index 0000000000000000000000000000000000000000..7d2b72503ab4a557119639443b30211dc3fe7432
--- /dev/null
+++ b/impl/cloud/info.go
@@ -0,0 +1,104 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package cloud
+
+import (
+ "errors"
+ "time"
+
+ infoS "github.com/luci/gae/service/info"
+
+ "golang.org/x/net/context"
+)
+
+var errNotImplemented = errors.New("not implemented")
+
+// cloudInfo is a reconstruction of the info service for the cloud API.
+//
+// It will return information sufficent for datastore operation.
+type infoState struct {
+ // namespace is the current namesapce, or the empty string for no namespace.
+ namespace string
+}
+
+var infoStateKey = "*cloud.infoState"
+
+func getInfoState(c context.Context) *infoState {
+ if is, ok := c.Value(&infoStateKey).(*infoState); ok {
+ return is
+ }
+ panic("no info state in Context")
+}
+
+func (ci *infoState) use(c context.Context) context.Context {
+ return context.WithValue(c, &infoStateKey, ci)
+}
+
+func (ci *infoState) derive(mutate func(*infoState)) *infoState {
+ dci := *ci
+ mutate(&dci)
+ return &dci
+}
+
+type infoService struct {
+ *infoState
+
+ ic context.Context
+}
+
+func useInfo(c context.Context) context.Context {
+ var baseInfoState infoState
+ c = baseInfoState.use(c)
+
+ return infoS.SetFactory(c, func(ic context.Context) infoS.Interface {
+ return &infoService{
+ infoState: getInfoState(ic),
+ ic: ic,
+ }
+ })
+}
+
+func (i *infoService) AppID() string { return "" }
+func (i *infoService) FullyQualifiedAppID() string { return "" }
+func (i *infoService) GetNamespace() (string, bool) { return i.namespace, (i.namespace != "") }
+
+func (i *infoService) Datacenter() string { return "" }
+func (i *infoService) DefaultVersionHostname() string { return "" }
+func (i *infoService) InstanceID() string { return "" }
+func (i *infoService) IsDevAppServer() bool { return false }
+func (i *infoService) IsOverQuota(err error) bool { return false }
+func (i *infoService) IsTimeoutError(err error) bool { return false }
+func (i *infoService) ModuleHostname(module, version, instance string) (string, error) {
+ return "", errNotImplemented
+}
+func (i *infoService) ModuleName() string { return "" }
+func (i *infoService) RequestID() string { return "" }
+func (i *infoService) ServerSoftware() string { return "" }
+func (i *infoService) ServiceAccount() (string, error) { return "", errNotImplemented }
+func (i *infoService) VersionID() string { return "" }
iannucci 2016/05/23 21:53:06 let's return dummy values and/or panic; I'd rather
dnj (Google) 2016/07/01 02:25:56 Done I left FullyQualifiedAppID implemented and bl
+
+func (i *infoService) Namespace(namespace string) (context.Context, error) {
+ return i.MustNamespace(namespace), nil
+}
+
+func (i *infoService) MustNamespace(namespace string) context.Context {
+ return i.derive(func(ci *infoState) {
+ ci.namespace = namespace
+ }).use(i.ic)
+}
+
+func (i *infoService) AccessToken(scopes ...string) (token string, expiry time.Time, err error) {
+ return "", time.Time{}, errNotImplemented
+}
+
+func (i *infoService) PublicCertificates() ([]infoS.Certificate, error) {
+ return nil, errNotImplemented
+}
+
+func (i *infoService) SignBytes(bytes []byte) (keyName string, signature []byte, err error) {
+ return "", nil, errNotImplemented
+}
+
+func (i *infoService) Testable() infoS.Testable { return nil }

Powered by Google App Engine
This is Rietveld 408576698