go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gae/filter/featureBreaker/gi.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package featureBreaker 16 17 import ( 18 "context" 19 "time" 20 21 "go.chromium.org/luci/gae/service/info" 22 ) 23 24 type infoState struct { 25 *state 26 27 c context.Context 28 info.RawInterface 29 } 30 31 func (g *infoState) ModuleHostname(module, version, instance string) (ret string, err error) { 32 err = g.run(g.c, func() (err error) { 33 ret, err = g.RawInterface.ModuleHostname(module, version, instance) 34 return 35 }) 36 return 37 } 38 39 func (g *infoState) ServiceAccount() (ret string, err error) { 40 err = g.run(g.c, func() (err error) { 41 ret, err = g.RawInterface.ServiceAccount() 42 return 43 }) 44 return 45 } 46 47 func (g *infoState) Namespace(namespace string) (c context.Context, err error) { 48 err = g.run(g.c, func() (err error) { 49 c, err = g.RawInterface.Namespace(namespace) 50 return 51 }) 52 return 53 } 54 55 func (g *infoState) AccessToken(scopes ...string) (token string, expiry time.Time, err error) { 56 err = g.run(g.c, func() (err error) { 57 token, expiry, err = g.RawInterface.AccessToken(scopes...) 58 return 59 }) 60 return 61 } 62 63 func (g *infoState) PublicCertificates() (ret []info.Certificate, err error) { 64 err = g.run(g.c, func() (err error) { 65 ret, err = g.RawInterface.PublicCertificates() 66 return 67 }) 68 return 69 } 70 71 func (g *infoState) SignBytes(bytes []byte) (keyName string, signature []byte, err error) { 72 err = g.run(g.c, func() (err error) { 73 keyName, signature, err = g.RawInterface.SignBytes(bytes) 74 return 75 }) 76 return 77 } 78 79 // FilterGI installs a featureBreaker info filter in the context. 80 func FilterGI(c context.Context, defaultError error) (context.Context, FeatureBreaker) { 81 state := newState(defaultError) 82 return info.AddFilters(c, func(ic context.Context, i info.RawInterface) info.RawInterface { 83 return &infoState{state, ic, i} 84 }), state 85 }