1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-18 16:35:19 +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:
Dan Ramich
2018-04-26 12:11:53 -07:00
committed by Darren Shepherd
parent 719d3af64f
commit e6973cb055
2 changed files with 40 additions and 25 deletions

View File

@@ -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 {
result := map[string]types.Action{}
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
}
}

View File

@@ -42,22 +42,26 @@ type {{.schema.CodeName}}Operations interface {
Update(existing *{{.schema.CodeName}}, updates interface{}) (*{{.schema.CodeName}}, error)
ByID(id string) (*{{.schema.CodeName}}, error)
Delete(container *{{.schema.CodeName}}) error
{{range $key, $value := .resourceActions}}
{{if eq $value.Input "" }}
Action{{$key | capitalize}} (*{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error)
{{else}}
Action{{$key | capitalize}} (*{{$.schema.CodeName}}, *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error)
{{end}}
{{range $key, $value := .resourceActions}}
{{if (and (eq $value.Input "") (eq $value.Output ""))}}
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (error)
{{else if (and (eq $value.Input "") (ne $value.Output ""))}}
Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}) (*{{.Output | capitalize}}, error)
{{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}}
{{range $key, $value := .collectionActions}}
{{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 ""))}}
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 ""))}}
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}}
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}}
}
@@ -108,41 +112,48 @@ func (c *{{.schema.CodeName}}Client) Delete(container *{{.schema.CodeName}}) err
}
{{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) {
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}}
func (c *{{$.schema.CodeName}}Client) Action{{$key | capitalize}} (resource *{{$.schema.CodeName}}, input *{{$value.Input | capitalize}}) (*{{.Output | capitalize}}, error) {
{{end}}
resp := &{{.Output | capitalize}}{}
{{if eq $value.Input "" }}
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, nil, resp)
{{else}}
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, resp)
{{end}}
return resp, err
resp := &{{.Output | capitalize}}{}
err := c.apiClient.Ops.DoAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Resource, input, resp)
return resp, err
{{- end -}}
}
{{end}}
{{range $key, $value := .collectionActions}}
{{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)
return err
{{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}}{}
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, 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}}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)
return err
{{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}}{}
err := c.apiClient.Ops.DoCollectionAction({{$.schema.CodeName}}Type, "{{$key}}", &resource.Collection, input, resp)
return resp, err
{{end}}
{{- end -}}
}
{{end}}
{{end}}`