Auth methods CLI (#277)
This commit is contained in:
1 parent
041e1f9fd3
commit
adfc5681be
41 files changed
+951
-192
No files matched your search
@@ -62,6 +62,10 @@ type structInfo struct {
|
||||
// operations all values are used for the function argument.
|
||||
// For collection based operations the last value is ignored for generating function argument.
|
||||
pathArgs []string
|
||||
|
||||
// typeOnCreate indicates that create will be creating a concrete
|
||||
// implementation of an abstract type and thus a type field is necessary
|
||||
typeOnCreate bool
|
||||
}
|
||||
|
||||
var inputStructs = []*structInfo{
|
||||
@@ -185,6 +189,7 @@ var inputStructs = []*structInfo{
|
||||
listTemplate,
|
||||
},
|
||||
pathArgs: []string{"auth-method"},
|
||||
typeOnCreate: true,
|
||||
versionEnabled: true,
|
||||
},
|
||||
{
|
||||
@@ -236,6 +241,7 @@ var inputStructs = []*structInfo{
|
||||
listTemplate,
|
||||
},
|
||||
pathArgs: []string{"host-catalog"},
|
||||
typeOnCreate: true,
|
||||
versionEnabled: true,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -70,6 +70,7 @@ type templateInput struct {
|
||||
ResourcePath string
|
||||
SliceSubTypes map[string]string
|
||||
VersionEnabled bool
|
||||
TypeOnCreate bool
|
||||
}
|
||||
|
||||
func fillTemplates() {
|
||||
@@ -83,6 +84,7 @@ func fillTemplates() {
|
||||
Fields: in.generatedStructure.fields,
|
||||
PathArgs: in.pathArgs,
|
||||
VersionEnabled: in.versionEnabled,
|
||||
TypeOnCreate: in.typeOnCreate,
|
||||
}
|
||||
|
||||
if len(in.pathArgs) > 0 {
|
||||
@@ -292,16 +294,19 @@ func (c *{{ .ClientName }}Client) Delete(ctx context.Context, {{ range .Resource
|
||||
`))
|
||||
|
||||
var createTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Create(ctx context.Context, {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
func (c *{{ .ClientName }}Client) Create(ctx context.Context, {{ if .TypeOnCreate }} resourceType string, {{ end }} {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into Create request")
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}opts, apiOpts := getOpts(opt...)
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
{{ if .TypeOnCreate }} if resourceType == "" {
|
||||
return nil, nil, fmt.Errorf("empty resourceType value passed into Create request")
|
||||
} else {
|
||||
opts.valueMap["type"] = resourceType
|
||||
}{{ end }}
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "POST", {{ .CollectionPath }}, opts.valueMap, apiOpts...)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user