[gce provider] More wrappers for alpha/beta backend service

pull/8/head
Zihong Zheng 2018-05-29 20:16:02 -07:00
parent c6e0a225f9
commit fdc58eb891
3 changed files with 72 additions and 12 deletions

View File

@ -3420,6 +3420,7 @@ type AlphaBackendServices interface {
List(ctx context.Context, fl *filter.F) ([]*alpha.BackendService, error) List(ctx context.Context, fl *filter.F) ([]*alpha.BackendService, error)
Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error Insert(ctx context.Context, key *meta.Key, obj *alpha.BackendService) error
Delete(ctx context.Context, key *meta.Key) error Delete(ctx context.Context, key *meta.Key) error
SetSecurityPolicy(context.Context, *meta.Key, *alpha.SecurityPolicyReference) error
Update(context.Context, *meta.Key, *alpha.BackendService) error Update(context.Context, *meta.Key, *alpha.BackendService) error
} }
@ -3460,6 +3461,7 @@ type MockAlphaBackendServices struct {
ListHook func(ctx context.Context, fl *filter.F, m *MockAlphaBackendServices) (bool, []*alpha.BackendService, error) ListHook func(ctx context.Context, fl *filter.F, m *MockAlphaBackendServices) (bool, []*alpha.BackendService, error)
InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.BackendService, m *MockAlphaBackendServices) (bool, error) InsertHook func(ctx context.Context, key *meta.Key, obj *alpha.BackendService, m *MockAlphaBackendServices) (bool, error)
DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaBackendServices) (bool, error) DeleteHook func(ctx context.Context, key *meta.Key, m *MockAlphaBackendServices) (bool, error)
SetSecurityPolicyHook func(context.Context, *meta.Key, *alpha.SecurityPolicyReference, *MockAlphaBackendServices) error
UpdateHook func(context.Context, *meta.Key, *alpha.BackendService, *MockAlphaBackendServices) error UpdateHook func(context.Context, *meta.Key, *alpha.BackendService, *MockAlphaBackendServices) error
// X is extra state that can be used as part of the mock. Generated code // X is extra state that can be used as part of the mock. Generated code
@ -3606,6 +3608,14 @@ func (m *MockAlphaBackendServices) Obj(o *alpha.BackendService) *MockBackendServ
return &MockBackendServicesObj{o} return &MockBackendServicesObj{o}
} }
// SetSecurityPolicy is a mock for the corresponding method.
func (m *MockAlphaBackendServices) SetSecurityPolicy(ctx context.Context, key *meta.Key, arg0 *alpha.SecurityPolicyReference) error {
if m.SetSecurityPolicyHook != nil {
return m.SetSecurityPolicyHook(ctx, key, arg0, m)
}
return nil
}
// Update is a mock for the corresponding method. // Update is a mock for the corresponding method.
func (m *MockAlphaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error { func (m *MockAlphaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error {
if m.UpdateHook != nil { if m.UpdateHook != nil {
@ -3756,6 +3766,39 @@ func (g *GCEAlphaBackendServices) Delete(ctx context.Context, key *meta.Key) err
return err return err
} }
// SetSecurityPolicy is a method on GCEAlphaBackendServices.
func (g *GCEAlphaBackendServices) SetSecurityPolicy(ctx context.Context, key *meta.Key, arg0 *alpha.SecurityPolicyReference) error {
glog.V(5).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): called", ctx, key)
if !key.Valid() {
glog.V(2).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
return fmt.Errorf("invalid GCE key (%+v)", key)
}
projectID := g.s.ProjectRouter.ProjectID(ctx, "alpha", "BackendServices")
rk := &RateLimitKey{
ProjectID: projectID,
Operation: "SetSecurityPolicy",
Version: meta.Version("alpha"),
Service: "BackendServices",
}
glog.V(5).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
glog.V(4).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
return err
}
call := g.s.Alpha.BackendServices.SetSecurityPolicy(projectID, key.Name, arg0)
call.Context(ctx)
op, err := call.Do()
if err != nil {
glog.V(4).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...) = %+v", ctx, key, err)
return err
}
err = g.s.WaitForCompletion(ctx, op)
glog.V(4).Infof("GCEAlphaBackendServices.SetSecurityPolicy(%v, %v, ...) = %+v", ctx, key, err)
return err
}
// Update is a method on GCEAlphaBackendServices. // Update is a method on GCEAlphaBackendServices.
func (g *GCEAlphaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error { func (g *GCEAlphaBackendServices) Update(ctx context.Context, key *meta.Key, arg0 *alpha.BackendService) error {
glog.V(5).Infof("GCEAlphaBackendServices.Update(%v, %v, ...): called", ctx, key) glog.V(5).Infof("GCEAlphaBackendServices.Update(%v, %v, ...): called", ctx, key)

View File

@ -125,7 +125,10 @@ var AllServices = []*ServiceInfo{
version: VersionAlpha, version: VersionAlpha,
keyType: Global, keyType: Global,
serviceType: reflect.TypeOf(&alpha.BackendServicesService{}), serviceType: reflect.TypeOf(&alpha.BackendServicesService{}),
additionalMethods: []string{"Update"}, additionalMethods: []string{
"Update",
"SetSecurityPolicy",
},
}, },
{ {
Object: "BackendService", Object: "BackendService",

View File

@ -42,6 +42,13 @@ func (gce *GCECloud) GetGlobalBackendService(name string) (*compute.BackendServi
return v, mc.Observe(err) return v, mc.Observe(err)
} }
// GetBetaGlobalBackendService retrieves beta backend by name.
func (gce *GCECloud) GetBetaGlobalBackendService(name string) (*computebeta.BackendService, error) {
mc := newBackendServiceMetricContextWithVersion("get", "", computeBetaVersion)
v, err := gce.c.BetaBackendServices().Get(context.Background(), meta.GlobalKey(name))
return v, mc.Observe(err)
}
// GetAlphaGlobalBackendService retrieves alpha backend by name. // GetAlphaGlobalBackendService retrieves alpha backend by name.
func (gce *GCECloud) GetAlphaGlobalBackendService(name string) (*computealpha.BackendService, error) { func (gce *GCECloud) GetAlphaGlobalBackendService(name string) (*computealpha.BackendService, error) {
mc := newBackendServiceMetricContextWithVersion("get", "", computeAlphaVersion) mc := newBackendServiceMetricContextWithVersion("get", "", computeAlphaVersion)
@ -147,3 +154,10 @@ func (gce *GCECloud) SetSecurityPolicyForBetaGlobalBackendService(backendService
mc := newBackendServiceMetricContextWithVersion("set_security_policy", "", computeBetaVersion) mc := newBackendServiceMetricContextWithVersion("set_security_policy", "", computeBetaVersion)
return mc.Observe(gce.c.BetaBackendServices().SetSecurityPolicy(context.Background(), meta.GlobalKey(backendServiceName), securityPolicyReference)) return mc.Observe(gce.c.BetaBackendServices().SetSecurityPolicy(context.Background(), meta.GlobalKey(backendServiceName), securityPolicyReference))
} }
// SetSecurityPolicyForAlphaGlobalBackendService sets the given
// SecurityPolicyReference for the BackendService identified by the given name.
func (gce *GCECloud) SetSecurityPolicyForAlphaGlobalBackendService(backendServiceName string, securityPolicyReference *computealpha.SecurityPolicyReference) error {
mc := newBackendServiceMetricContextWithVersion("set_security_policy", "", computeAlphaVersion)
return mc.Observe(gce.c.AlphaBackendServices().SetSecurityPolicy(context.Background(), meta.GlobalKey(backendServiceName), securityPolicyReference))
}