OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package cloud | |
6 | |
7 import ( | |
8 "errors" | |
9 "time" | |
10 | |
11 infoS "github.com/luci/gae/service/info" | |
12 | |
13 "golang.org/x/net/context" | |
14 ) | |
15 | |
16 var errNotImplemented = errors.New("not implemented") | |
17 | |
18 // cloudInfo is a reconstruction of the info service for the cloud API. | |
19 // | |
20 // It will return information sufficent for datastore operation. | |
21 type infoState struct { | |
22 // namespace is the current namesapce, or the empty string for no namesp ace. | |
23 namespace string | |
24 } | |
25 | |
26 var infoStateKey = "*cloud.infoState" | |
27 | |
28 func getInfoState(c context.Context) *infoState { | |
29 if is, ok := c.Value(&infoStateKey).(*infoState); ok { | |
30 return is | |
31 } | |
32 panic("no info state in Context") | |
33 } | |
34 | |
35 func (ci *infoState) use(c context.Context) context.Context { | |
36 return context.WithValue(c, &infoStateKey, ci) | |
37 } | |
38 | |
39 func (ci *infoState) derive(mutate func(*infoState)) *infoState { | |
40 dci := *ci | |
41 mutate(&dci) | |
42 return &dci | |
43 } | |
44 | |
45 type infoService struct { | |
46 *infoState | |
47 | |
48 ic context.Context | |
49 } | |
50 | |
51 func useInfo(c context.Context) context.Context { | |
52 var baseInfoState infoState | |
53 c = baseInfoState.use(c) | |
54 | |
55 return infoS.SetFactory(c, func(ic context.Context) infoS.Interface { | |
56 return &infoService{ | |
57 infoState: getInfoState(ic), | |
58 ic: ic, | |
59 } | |
60 }) | |
61 } | |
62 | |
63 func (i *infoService) AppID() string { return "" } | |
64 func (i *infoService) FullyQualifiedAppID() string { return "" } | |
65 func (i *infoService) GetNamespace() (string, bool) { return i.namespace, (i.nam espace != "") } | |
66 | |
67 func (i *infoService) Datacenter() string { return "" } | |
68 func (i *infoService) DefaultVersionHostname() string { return "" } | |
69 func (i *infoService) InstanceID() string { return "" } | |
70 func (i *infoService) IsDevAppServer() bool { return false } | |
71 func (i *infoService) IsOverQuota(err error) bool { return false } | |
72 func (i *infoService) IsTimeoutError(err error) bool { return false } | |
73 func (i *infoService) ModuleHostname(module, version, instance string) (string, error) { | |
74 return "", errNotImplemented | |
75 } | |
76 func (i *infoService) ModuleName() string { return "" } | |
77 func (i *infoService) RequestID() string { return "" } | |
78 func (i *infoService) ServerSoftware() string { return "" } | |
79 func (i *infoService) ServiceAccount() (string, error) { return "", errNotImplem ented } | |
80 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
| |
81 | |
82 func (i *infoService) Namespace(namespace string) (context.Context, error) { | |
83 return i.MustNamespace(namespace), nil | |
84 } | |
85 | |
86 func (i *infoService) MustNamespace(namespace string) context.Context { | |
87 return i.derive(func(ci *infoState) { | |
88 ci.namespace = namespace | |
89 }).use(i.ic) | |
90 } | |
91 | |
92 func (i *infoService) AccessToken(scopes ...string) (token string, expiry time.T ime, err error) { | |
93 return "", time.Time{}, errNotImplemented | |
94 } | |
95 | |
96 func (i *infoService) PublicCertificates() ([]infoS.Certificate, error) { | |
97 return nil, errNotImplemented | |
98 } | |
99 | |
100 func (i *infoService) SignBytes(bytes []byte) (keyName string, signature []byte, err error) { | |
101 return "", nil, errNotImplemented | |
102 } | |
103 | |
104 func (i *infoService) Testable() infoS.Testable { return nil } | |
OLD | NEW |