mirror of
https://github.com/rancher/norman.git
synced 2025-09-19 18:16:15 +00:00
Update action generation code
Problem: Action generation code does not account for a resource action that does not have an output Solution: Update template to output all actions
This commit is contained in:
committed by
Darren Shepherd
parent
719d3af64f
commit
e6973cb055
@@ -115,7 +115,11 @@ func getTypeMap(schema *types.Schema, schemas *types.Schemas) map[string]fieldIn
|
|||||||
func getResourceActions(schema *types.Schema, schemas *types.Schemas) map[string]types.Action {
|
func getResourceActions(schema *types.Schema, schemas *types.Schemas) map[string]types.Action {
|
||||||
result := map[string]types.Action{}
|
result := map[string]types.Action{}
|
||||||
for name, action := range schema.ResourceActions {
|
for name, action := range schema.ResourceActions {
|
||||||
if schemas.Schema(&schema.Version, action.Output) != nil {
|
if action.Output != "" {
|
||||||
|
if schemas.Schema(&schema.Version, action.Output) != nil {
|
||||||
|
result[name] = action
|
||||||
|
}
|
||||||
|
} else {
|
||||||
result[name] = action
|
result[name] = action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,22 +42,26 @@ type {{.schema.CodeName}}Operations interface {
|
|||||||
Update(existing *{{.schema.CodeName}}, updates interface{}) (*{{.schema.CodeName}}, error)
|
Update(existing *{{.schema.CodeName}}, updates interface{}) (*{{.schema.CodeName}}, error)
|
||||||
ByID(id string) (*{{.schema.CodeName}}, error)
|
ByID(id string) (*{{.schema.CodeName}}, error)
|
||||||
Delete(container *{{.schema.CodeName}}) error
|
Delete(container *{{.schema.CodeName}}) error
|
||||||
{{range $key, $value := .resourceActions}}
|
{{range $key, $value := .resourceActions}}
|
||||||
{{if eq $value.Input "" }}
|
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
||||||
Action{{$key | capitalize}} (*{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error)
|
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (error)
|
||||||
{{else}}
|
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
||||||
Action{{$key | capitalize}} (*{{$.schema.CodeName}}, *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error)
|
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error)
|
||||||
{{end}}
|
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
||||||
|
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (error)
|
||||||
|
{{else}}
|
||||||
|
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error)
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{range $key, $value := .collectionActions}}
|
{{range $key, $value := .collectionActions}}
|
||||||
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
||||||
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (error)
|
CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (error)
|
||||||
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
||||||
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error)
|
CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error)
|
||||||
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
||||||
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (error)
|
CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (error)
|
||||||
{{else}}
|
{{else}}
|
||||||
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error)
|
CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error)
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
@@ -108,41 +112,48 @@ func (c *{{.schema.CodeName}}Client) Delete(container *{{.schema.CodeName}}) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
{{range $key, $value := .resourceActions}}
|
{{range $key, $value := .resourceActions}}
|
||||||
{{if eq $value.Input "" }}
|
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
||||||
|
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (error) {
|
||||||
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, nil)
|
||||||
|
return err
|
||||||
|
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error) {
|
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error) {
|
||||||
|
resp := &{{.Output | capitalize}}{}
|
||||||
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, resp)
|
||||||
|
return resp, err
|
||||||
|
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
||||||
|
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (error) {
|
||||||
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, nil)
|
||||||
|
return err
|
||||||
{{else}}
|
{{else}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error) {
|
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error) {
|
||||||
{{end}}
|
resp := &{{.Output | capitalize}}{}
|
||||||
resp := &{{.Output | capitalize}}{}
|
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, resp)
|
||||||
{{if eq $value.Input "" }}
|
return resp, err
|
||||||
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, resp)
|
{{- end -}}
|
||||||
{{else}}
|
|
||||||
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, resp)
|
|
||||||
{{end}}
|
|
||||||
return resp, err
|
|
||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{range $key, $value := .collectionActions}}
|
{{range $key, $value := .collectionActions}}
|
||||||
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (error) {
|
func (c *{{$.schema.CodeName}}Client) CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (error) {
|
||||||
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, nil, nil)
|
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, nil, nil)
|
||||||
return err
|
return err
|
||||||
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {
|
func (c *{{$.schema.CodeName}}Client) CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {
|
||||||
resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{}
|
resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{}
|
||||||
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, nil, resp)
|
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, nil, resp)
|
||||||
return resp, err
|
return resp, err
|
||||||
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
{{else if (and (ne $value.Input "") (eq $value.Output ""))}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (error) {
|
func (c *{{$.schema.CodeName}}Client) CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (error) {
|
||||||
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, input, nil)
|
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, input, nil)
|
||||||
return err
|
return err
|
||||||
{{else}}
|
{{else}}
|
||||||
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {
|
func (c *{{$.schema.CodeName}}Client) CollectionAction{{$key | capitalize}} (resource *{{$.schema.CodeName}}Collection, input *{{$value.Input | capitalize}}) (*{{getCollectionOutput $value.Output $.schema.CodeName}}, error) {
|
||||||
resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{}
|
resp := &{{getCollectionOutput $value.Output $.schema.CodeName}}{}
|
||||||
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, input, resp)
|
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, input, resp)
|
||||||
return resp, err
|
return resp, err
|
||||||
{{end}}
|
{{- end -}}
|
||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}`
|
{{end}}`
|
||||||
|
Reference in New Issue
Block a user