Auth methods CLI (#277)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-08-18 17:46:34 -04:00
1 parent 041e1f9fd3
commit adfc5681be
41 files changed
+951 -192

No files matched your search

+1 -3
View File
@@ -39,13 +39,11 @@ func (c *AccountsClient) Create(ctx context.Context, authMethodId string, opt ..
if authMethodId == "" {
return nil, nil, fmt.Errorf("empty authMethodId value passed into Create request")
}
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("auth-methods/%s/accounts", authMethodId), opts.valueMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
+7 -3
View File
@@ -34,12 +34,16 @@ func NewAuthMethodsClient(c *api.Client) *AuthMethodsClient {
return &AuthMethodsClient{client: c}
}
func (c *AuthMethodsClient) Create(ctx context.Context, opt ...Option) (*AuthMethod, *api.Error, error) {
func (c *AuthMethodsClient) Create(ctx context.Context, resourceType string, opt ...Option) (*AuthMethod, *api.Error, error) {
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
if resourceType == "" {
return nil, nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.valueMap["type"] = resourceType
}
req, err := c.client.NewRequest(ctx, "POST", "auth-methods", opts.valueMap, apiOpts...)
if err != nil {
+1 -2
View File
@@ -35,12 +35,11 @@ func NewGroupsClient(c *api.Client) *GroupsClient {
}
func (c *GroupsClient) Create(ctx context.Context, opt ...Option) (*Group, *api.Error, error) {
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "POST", "groups", opts.valueMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
+1 -3
View File
@@ -38,13 +38,11 @@ func (c *HostsClient) Create(ctx context.Context, hostCatalogId string, opt ...O
if hostCatalogId == "" {
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Create request")
}
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/hosts", hostCatalogId), opts.valueMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
+7 -3
View File
@@ -34,12 +34,16 @@ func NewHostCatalogsClient(c *api.Client) *HostCatalogsClient {
return &HostCatalogsClient{client: c}
}
func (c *HostCatalogsClient) Create(ctx context.Context, opt ...Option) (*HostCatalog, *api.Error, error) {
func (c *HostCatalogsClient) Create(ctx context.Context, resourceType string, opt ...Option) (*HostCatalog, *api.Error, error) {
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
if resourceType == "" {
return nil, nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.valueMap["type"] = resourceType
}
req, err := c.client.NewRequest(ctx, "POST", "host-catalogs", opts.valueMap, apiOpts...)
if err != nil {
+1 -3
View File
@@ -39,13 +39,11 @@ func (c *HostSetsClient) Create(ctx context.Context, hostCatalogId string, opt .
if hostCatalogId == "" {
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Create request")
}
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets", hostCatalogId), opts.valueMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
+6
View File
@@ -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,
},
{
+9 -4
View File
@@ -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 {
+1 -1
View File
@@ -47,7 +47,7 @@ func (d *OutputStringError) parseRequest() {
for k, v := range d.Request.Header {
for _, h := range v {
if strings.ToLower(k) == "authorization" {
h = `Bearer: <token>`
h = `Bearer <token>`
}
d.parsedCurlString = fmt.Sprintf("%s-H \"%s: %s\" ", d.parsedCurlString, k, h)
}
+1 -2
View File
@@ -38,12 +38,11 @@ func NewRolesClient(c *api.Client) *RolesClient {
}
func (c *RolesClient) Create(ctx context.Context, opt ...Option) (*Role, *api.Error, error) {
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "POST", "roles", opts.valueMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
+1 -3
View File
@@ -35,13 +35,11 @@ func (c *ScopesClient) Create(ctx context.Context, scopeId string, opt ...Option
if scopeId == "" {
return nil, nil, fmt.Errorf("empty scopeId value passed into Create request")
}
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "POST", "scopes", opts.valueMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
+1 -2
View File
@@ -33,12 +33,11 @@ func NewUsersClient(c *api.Client) *UsersClient {
}
func (c *UsersClient) Create(ctx context.Context, opt ...Option) (*User, *api.Error, error) {
opts, apiOpts := getOpts(opt...)
if c.client == nil {
return nil, nil, fmt.Errorf("nil client")
}
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "POST", "users", opts.valueMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)