mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
GCE: Check that the key is valid for each call
This commit is contained in:
parent
a2b222c94e
commit
aaa3dfd695
File diff suppressed because it is too large
Load Diff
@ -395,6 +395,9 @@ func (m *{{.MockWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObjec
|
|||||||
return obj, err
|
return obj, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ! key.Valid() {
|
||||||
|
return nil, fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
}
|
||||||
|
|
||||||
m.Lock.Lock()
|
m.Lock.Lock()
|
||||||
defer m.Lock.Unlock()
|
defer m.Lock.Unlock()
|
||||||
@ -510,6 +513,9 @@ func (m *{{.MockWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.F
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ! key.Valid() {
|
||||||
|
return fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
}
|
||||||
|
|
||||||
m.Lock.Lock()
|
m.Lock.Lock()
|
||||||
defer m.Lock.Unlock()
|
defer m.Lock.Unlock()
|
||||||
@ -547,6 +553,9 @@ func (m *{{.MockWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ! key.Valid() {
|
||||||
|
return fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
}
|
||||||
|
|
||||||
m.Lock.Lock()
|
m.Lock.Lock()
|
||||||
defer m.Lock.Unlock()
|
defer m.Lock.Unlock()
|
||||||
@ -648,6 +657,9 @@ type {{.GCEWrapType}} struct {
|
|||||||
{{- if .GenerateGet}}
|
{{- if .GenerateGet}}
|
||||||
// Get the {{.Object}} named by key.
|
// Get the {{.Object}} named by key.
|
||||||
func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObjectType}}, error) {
|
func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObjectType}}, error) {
|
||||||
|
if ! key.Valid() {
|
||||||
|
return nil, fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
}
|
||||||
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
||||||
rk := &RateLimitKey{
|
rk := &RateLimitKey{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
@ -720,6 +732,9 @@ rk := &RateLimitKey{
|
|||||||
{{- if .GenerateInsert}}
|
{{- if .GenerateInsert}}
|
||||||
// Insert {{.Object}} with key of value obj.
|
// Insert {{.Object}} with key of value obj.
|
||||||
func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQObjectType}}) error {
|
func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQObjectType}}) error {
|
||||||
|
if ! key.Valid() {
|
||||||
|
return fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
}
|
||||||
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
||||||
rk := &RateLimitKey{
|
rk := &RateLimitKey{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
@ -753,6 +768,9 @@ func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQ
|
|||||||
{{- if .GenerateDelete}}
|
{{- if .GenerateDelete}}
|
||||||
// Delete the {{.Object}} referenced by key.
|
// Delete the {{.Object}} referenced by key.
|
||||||
func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
|
func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
|
||||||
|
if ! key.Valid() {
|
||||||
|
return fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
}
|
||||||
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
||||||
rk := &RateLimitKey{
|
rk := &RateLimitKey{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
@ -820,6 +838,15 @@ func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (ma
|
|||||||
{{- range .}}
|
{{- range .}}
|
||||||
// {{.Name}} is a method on {{.GCEWrapType}}.
|
// {{.Name}} is a method on {{.GCEWrapType}}.
|
||||||
func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
|
func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
|
||||||
|
if ! key.Valid() {
|
||||||
|
{{- if .IsOperation}}
|
||||||
|
return fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
{{- else if .IsGet}}
|
||||||
|
return nil, fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
{{- else if .IsPaged}}
|
||||||
|
return nil, fmt.Errorf("invalid GCE key (%+v)", key)
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
|
||||||
rk := &RateLimitKey{
|
rk := &RateLimitKey{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
|
Loading…
Reference in New Issue
Block a user