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 featureBreaker | 5 package featureBreaker |
6 | 6 |
7 import ( | 7 import ( |
8 "time" | 8 "time" |
9 | 9 |
10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
11 | 11 |
12 » "github.com/luci/gae" | 12 » "github.com/luci/gae/service/info" |
13 ) | 13 ) |
14 | 14 |
15 type giState struct { | 15 type infoState struct { |
16 *state | 16 *state |
17 | 17 |
18 » gae.GlobalInfo | 18 » info.Interface |
19 } | 19 } |
20 | 20 |
21 func (g *giState) ModuleHostname(module, version, instance string) (ret string,
err error) { | 21 func (g *infoState) ModuleHostname(module, version, instance string) (ret string
, err error) { |
22 err = g.run(func() (err error) { | 22 err = g.run(func() (err error) { |
23 » » ret, err = g.GlobalInfo.ModuleHostname(module, version, instance
) | 23 » » ret, err = g.Interface.ModuleHostname(module, version, instance) |
24 return | 24 return |
25 }) | 25 }) |
26 return | 26 return |
27 } | 27 } |
28 | 28 |
29 func (g *giState) ServiceAccount() (ret string, err error) { | 29 func (g *infoState) ServiceAccount() (ret string, err error) { |
30 err = g.run(func() (err error) { | 30 err = g.run(func() (err error) { |
31 » » ret, err = g.GlobalInfo.ServiceAccount() | 31 » » ret, err = g.Interface.ServiceAccount() |
32 return | 32 return |
33 }) | 33 }) |
34 return | 34 return |
35 } | 35 } |
36 | 36 |
37 func (g *giState) Namespace(namespace string) (ret context.Context, err error) { | 37 func (g *infoState) Namespace(namespace string) (ret context.Context, err error)
{ |
38 err = g.run(func() (err error) { | 38 err = g.run(func() (err error) { |
39 » » ret, err = g.GlobalInfo.Namespace(namespace) | 39 » » ret, err = g.Interface.Namespace(namespace) |
40 return | 40 return |
41 }) | 41 }) |
42 return | 42 return |
43 } | 43 } |
44 | 44 |
45 func (g *giState) AccessToken(scopes ...string) (token string, expiry time.Time,
err error) { | 45 func (g *infoState) AccessToken(scopes ...string) (token string, expiry time.Tim
e, err error) { |
46 err = g.run(func() (err error) { | 46 err = g.run(func() (err error) { |
47 » » token, expiry, err = g.GlobalInfo.AccessToken(scopes...) | 47 » » token, expiry, err = g.Interface.AccessToken(scopes...) |
48 return | 48 return |
49 }) | 49 }) |
50 return | 50 return |
51 } | 51 } |
52 | 52 |
53 func (g *giState) PublicCertificates() (ret []gae.GICertificate, err error) { | 53 func (g *infoState) PublicCertificates() (ret []info.Certificate, err error) { |
54 err = g.run(func() (err error) { | 54 err = g.run(func() (err error) { |
55 » » ret, err = g.GlobalInfo.PublicCertificates() | 55 » » ret, err = g.Interface.PublicCertificates() |
56 return | 56 return |
57 }) | 57 }) |
58 return | 58 return |
59 } | 59 } |
60 | 60 |
61 func (g *giState) SignBytes(bytes []byte) (keyName string, signature []byte, err
error) { | 61 func (g *infoState) SignBytes(bytes []byte) (keyName string, signature []byte, e
rr error) { |
62 err = g.run(func() (err error) { | 62 err = g.run(func() (err error) { |
63 » » keyName, signature, err = g.GlobalInfo.SignBytes(bytes) | 63 » » keyName, signature, err = g.Interface.SignBytes(bytes) |
64 return | 64 return |
65 }) | 65 }) |
66 return | 66 return |
67 } | 67 } |
68 | 68 |
69 // FilterGI installs a counter GlobalInfo filter in the context. | 69 // FilterGI installs a counter info filter in the context. |
70 func FilterGI(c context.Context, defaultError error) (context.Context, FeatureBr
eaker) { | 70 func FilterGI(c context.Context, defaultError error) (context.Context, FeatureBr
eaker) { |
71 state := newState(defaultError) | 71 state := newState(defaultError) |
72 » return gae.AddGIFilters(c, func(ic context.Context, gi gae.GlobalInfo) g
ae.GlobalInfo { | 72 » return info.AddFilters(c, func(ic context.Context, i info.Interface) inf
o.Interface { |
73 » » return &giState{state, gi} | 73 » » return &infoState{state, i} |
74 }), state | 74 }), state |
75 } | 75 } |
OLD | NEW |