| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package prod | 5 package prod |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "time" | 8 "time" |
| 9 | 9 |
| 10 "github.com/luci/gae/service/info" | 10 "github.com/luci/gae/service/info" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 func (g giImpl) AccessToken(scopes ...string) (token string, expiry time.Time, e
rr error) { | 34 func (g giImpl) AccessToken(scopes ...string) (token string, expiry time.Time, e
rr error) { |
| 35 return appengine.AccessToken(g.aeCtx, scopes...) | 35 return appengine.AccessToken(g.aeCtx, scopes...) |
| 36 } | 36 } |
| 37 func (g giImpl) AppID() string { | 37 func (g giImpl) AppID() string { |
| 38 return appengine.AppID(g.aeCtx) | 38 return appengine.AppID(g.aeCtx) |
| 39 } | 39 } |
| 40 func (g giImpl) FullyQualifiedAppID() string { | 40 func (g giImpl) FullyQualifiedAppID() string { |
| 41 return getProbeCache(g.usrCtx).fqaid | 41 return getProbeCache(g.usrCtx).fqaid |
| 42 } | 42 } |
| 43 func (g giImpl) GetNamespace() string { | 43 func (g giImpl) GetNamespace() (string, bool) { |
| 44 » return getProbeCache(g.usrCtx).namespace | 44 » pc := getProbeCache(g.usrCtx) |
| 45 » if ns := pc.namespace; ns != nil { |
| 46 » » return *ns, true |
| 47 » } |
| 48 » return "", false |
| 45 } | 49 } |
| 46 func (g giImpl) Datacenter() string { | 50 func (g giImpl) Datacenter() string { |
| 47 return appengine.Datacenter(g.aeCtx) | 51 return appengine.Datacenter(g.aeCtx) |
| 48 } | 52 } |
| 49 func (g giImpl) DefaultVersionHostname() string { | 53 func (g giImpl) DefaultVersionHostname() string { |
| 50 return appengine.DefaultVersionHostname(g.aeCtx) | 54 return appengine.DefaultVersionHostname(g.aeCtx) |
| 51 } | 55 } |
| 52 func (g giImpl) InstanceID() string { | 56 func (g giImpl) InstanceID() string { |
| 53 return appengine.InstanceID() | 57 return appengine.InstanceID() |
| 54 } | 58 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 func (g giImpl) ModuleName() (name string) { | 71 func (g giImpl) ModuleName() (name string) { |
| 68 return appengine.ModuleName(g.aeCtx) | 72 return appengine.ModuleName(g.aeCtx) |
| 69 } | 73 } |
| 70 func (g giImpl) Namespace(namespace string) (context.Context, error) { | 74 func (g giImpl) Namespace(namespace string) (context.Context, error) { |
| 71 aeCtx, err := appengine.Namespace(g.aeCtx, namespace) | 75 aeCtx, err := appengine.Namespace(g.aeCtx, namespace) |
| 72 if err != nil { | 76 if err != nil { |
| 73 return g.usrCtx, err | 77 return g.usrCtx, err |
| 74 } | 78 } |
| 75 usrCtx := context.WithValue(g.usrCtx, prodContextKey, aeCtx) | 79 usrCtx := context.WithValue(g.usrCtx, prodContextKey, aeCtx) |
| 76 pc := *getProbeCache(usrCtx) | 80 pc := *getProbeCache(usrCtx) |
| 77 » pc.namespace = namespace | 81 » pc.namespace = &namespace |
| 78 return withProbeCache(usrCtx, &pc), nil | 82 return withProbeCache(usrCtx, &pc), nil |
| 79 } | 83 } |
| 80 func (g giImpl) MustNamespace(ns string) context.Context { | 84 func (g giImpl) MustNamespace(ns string) context.Context { |
| 81 ret, err := g.Namespace(ns) | 85 ret, err := g.Namespace(ns) |
| 82 if err != nil { | 86 if err != nil { |
| 83 panic(err) | 87 panic(err) |
| 84 } | 88 } |
| 85 return ret | 89 return ret |
| 86 } | 90 } |
| 87 func (g giImpl) PublicCertificates() ([]info.Certificate, error) { | 91 func (g giImpl) PublicCertificates() ([]info.Certificate, error) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 109 } | 113 } |
| 110 func (g giImpl) VersionID() string { | 114 func (g giImpl) VersionID() string { |
| 111 return appengine.VersionID(g.aeCtx) | 115 return appengine.VersionID(g.aeCtx) |
| 112 } | 116 } |
| 113 | 117 |
| 114 func (g giImpl) Testable() info.Testable { | 118 func (g giImpl) Testable() info.Testable { |
| 115 return nil | 119 return nil |
| 116 } | 120 } |
| 117 | 121 |
| 118 type infoProbeCache struct { | 122 type infoProbeCache struct { |
| 119 » namespace string | 123 » namespace *string |
| 120 fqaid string | 124 fqaid string |
| 121 } | 125 } |
| 122 | 126 |
| 123 func probe(aeCtx context.Context) *infoProbeCache { | 127 func probe(aeCtx context.Context) *infoProbeCache { |
| 124 probeKey := datastore.NewKey(aeCtx, "Kind", "id", 0, nil) | 128 probeKey := datastore.NewKey(aeCtx, "Kind", "id", 0, nil) |
| 125 » return &infoProbeCache{ | 129 » namespace := probeKey.Namespace() |
| 126 » » namespace: probeKey.Namespace(), | 130 » ipb := infoProbeCache{ |
| 127 » » fqaid: probeKey.AppID(), | 131 » » fqaid: probeKey.AppID(), |
| 128 } | 132 } |
| 133 if namespace != "" { |
| 134 ipb.namespace = &namespace |
| 135 } |
| 136 return &ipb |
| 129 } | 137 } |
| 130 | 138 |
| 131 func getProbeCache(c context.Context) *infoProbeCache { | 139 func getProbeCache(c context.Context) *infoProbeCache { |
| 132 if pc, ok := c.Value(probeCacheKey).(*infoProbeCache); ok { | 140 if pc, ok := c.Value(probeCacheKey).(*infoProbeCache); ok { |
| 133 return pc | 141 return pc |
| 134 } | 142 } |
| 135 return nil | 143 return nil |
| 136 } | 144 } |
| 137 | 145 |
| 138 func withProbeCache(c context.Context, pc *infoProbeCache) context.Context { | 146 func withProbeCache(c context.Context, pc *infoProbeCache) context.Context { |
| 139 return context.WithValue(c, probeCacheKey, pc) | 147 return context.WithValue(c, probeCacheKey, pc) |
| 140 } | 148 } |
| OLD | NEW |