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

Side by Side Diff: luci_config/server/cfgclient/backend/client/client.go

Issue 2801463002: Milo: Use custom config caching layer (Closed)
Patch Set: Review: Remove double logging Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // Package client implements a config client backend for a configuration client. 5 // Package client implements a config client backend for a configuration client.
6 package client 6 package client
7 7
8 import ( 8 import (
9 "fmt" 9 "fmt"
10 "net/http" 10 "net/http"
(...skipping 25 matching lines...) Expand all
36 Provider Provider 36 Provider Provider
37 } 37 }
38 38
39 var _ backend.B = (*Backend)(nil) 39 var _ backend.B = (*Backend)(nil)
40 40
41 // ServiceURL implements backend.B. 41 // ServiceURL implements backend.B.
42 func (be *Backend) ServiceURL(c context.Context) url.URL { return be.Provider.Ge tServiceURL() } 42 func (be *Backend) ServiceURL(c context.Context) url.URL { return be.Provider.Ge tServiceURL() }
43 43
44 // ConfigSetURL implements backend.B. 44 // ConfigSetURL implements backend.B.
45 func (be *Backend) ConfigSetURL(c context.Context, configSet string, p backend.P arams) (url.URL, error) { 45 func (be *Backend) ConfigSetURL(c context.Context, configSet string, p backend.P arams) (url.URL, error) {
46 » u, err := be.getIface(c, p.Authority).GetConfigSetLocation(c, configSet) 46 » u, err := be.GetConfigInterface(c, p.Authority).GetConfigSetLocation(c, configSet)
47 if err != nil || u == nil { 47 if err != nil || u == nil {
48 return url.URL{}, err 48 return url.URL{}, err
49 } 49 }
50 return *u, nil 50 return *u, nil
51 } 51 }
52 52
53 // Get implements backend.B. 53 // Get implements backend.B.
54 func (be *Backend) Get(c context.Context, configSet, path string, p backend.Para ms) (*backend.Item, error) { 54 func (be *Backend) Get(c context.Context, configSet, path string, p backend.Para ms) (*backend.Item, error) {
55 » svc := be.getIface(c, p.Authority) 55 » svc := be.GetConfigInterface(c, p.Authority)
56 56
57 cfg, err := svc.GetConfig(c, configSet, path, !p.Content) 57 cfg, err := svc.GetConfig(c, configSet, path, !p.Content)
58 if err != nil { 58 if err != nil {
59 return nil, translateConfigErr(err) 59 return nil, translateConfigErr(err)
60 } 60 }
61 61
62 return makeItem(cfg), nil 62 return makeItem(cfg), nil
63 } 63 }
64 64
65 // GetAll implements backend.B. 65 // GetAll implements backend.B.
66 func (be *Backend) GetAll(c context.Context, t backend.GetAllTarget, path string , p backend.Params) ( 66 func (be *Backend) GetAll(c context.Context, t backend.GetAllTarget, path string , p backend.Params) (
67 []*backend.Item, error) { 67 []*backend.Item, error) {
68 68
69 » svc := be.getIface(c, p.Authority) 69 » svc := be.GetConfigInterface(c, p.Authority)
70 70
71 var fn func(context.Context, string, bool) ([]config.Config, error) 71 var fn func(context.Context, string, bool) ([]config.Config, error)
72 switch t { 72 switch t {
73 case backend.GetAllProject: 73 case backend.GetAllProject:
74 fn = svc.GetProjectConfigs 74 fn = svc.GetProjectConfigs
75 case backend.GetAllRef: 75 case backend.GetAllRef:
76 fn = svc.GetRefConfigs 76 fn = svc.GetRefConfigs
77 default: 77 default:
78 return nil, errors.Reason("unknown GetAllType: %(type)q").D("typ e", t).Err() 78 return nil, errors.Reason("unknown GetAllType: %(type)q").D("typ e", t).Err()
79 } 79 }
80 80
81 cfgs, err := fn(c, path, !p.Content) 81 cfgs, err := fn(c, path, !p.Content)
82 if err != nil || len(cfgs) == 0 { 82 if err != nil || len(cfgs) == 0 {
83 return nil, translateConfigErr(err) 83 return nil, translateConfigErr(err)
84 } 84 }
85 85
86 items := make([]*backend.Item, len(cfgs)) 86 items := make([]*backend.Item, len(cfgs))
87 for i := range cfgs { 87 for i := range cfgs {
88 items[i] = makeItem(&cfgs[i]) 88 items[i] = makeItem(&cfgs[i])
89 } 89 }
90 return items, nil 90 return items, nil
91 } 91 }
92 92
93 func (be *Backend) getIface(c context.Context, a backend.Authority) config.Inter face { 93 func (be *Backend) GetConfigInterface(c context.Context, a backend.Authority) co nfig.Interface {
94 return be.Provider.GetConfigClient(c, a) 94 return be.Provider.GetConfigClient(c, a)
95 } 95 }
96 96
97 // RemoteProvider is a Provider implementation that binds to 97 // RemoteProvider is a Provider implementation that binds to
98 // a remote configuration service. 98 // a remote configuration service.
99 type RemoteProvider struct { 99 type RemoteProvider struct {
100 // Host is the base host name of the configuration service, e.g., 100 // Host is the base host name of the configuration service, e.g.,
101 // "example.appspot.com". 101 // "example.appspot.com".
102 Host string 102 Host string
103 // Insecure is true if the connection should use HTTP instead of HTTPS. 103 // Insecure is true if the connection should use HTTP instead of HTTPS.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 case backend.AsAnonymous: 190 case backend.AsAnonymous:
191 return auth.NoAuth 191 return auth.NoAuth
192 case backend.AsService: 192 case backend.AsService:
193 return auth.AsSelf 193 return auth.AsSelf
194 case backend.AsUser: 194 case backend.AsUser:
195 return auth.AsUser 195 return auth.AsUser
196 default: 196 default:
197 panic(fmt.Errorf("unknown config Authority (%d)", a)) 197 panic(fmt.Errorf("unknown config Authority (%d)", a))
198 } 198 }
199 } 199 }
OLDNEW
« no previous file with comments | « luci_config/server/cfgclient/backend/backend.go ('k') | luci_config/server/cfgclient/backend/erroring/erroring.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698