diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d92a44e1..232edfbfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ### Bug Fixes +* cli: When `output-curl-string` is used with `update` or `add-/remove-/set-` + commands and automatic versioning is being used (that is, no `-version` flag + is given), it will now display the final call instead of the `GET` that + fetches the current version + ([Issue](https://github.com/hashicorp/boundary/issues/856)) + ([PR](https://github.com/hashicorp/boundary/pull/858)) * db: Fix panic in `database init` when controller config block is missing ([Issue](https://github.com/hashicorp/boundary/issues/819)) ([PR](https://github.com/hashicorp/boundary/pull/851)) diff --git a/Makefile b/Makefile index f9a87ced4..65ccfbfc4 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ CGO_ENABLED?=0 export GEN_BASEPATH := $(shell pwd) -api: +api: apigen fmt +apigen: $(MAKE) --environment-overrides -C internal/api/genapi api tools: diff --git a/api/accounts/account.gen.go b/api/accounts/account.gen.go index 6cd5baf72..b644417d9 100644 --- a/api/accounts/account.gen.go +++ b/api/accounts/account.gen.go @@ -176,7 +176,7 @@ func (c *Client) Read(ctx context.Context, accountId string, opt ...Option) (*Ac req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -208,7 +208,7 @@ func (c *Client) Update(ctx context.Context, accountId string, version uint32, o if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, accountId, opt...) + existingTarget, existingErr := c.Read(ctx, accountId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/accounts/option.gen.go b/api/accounts/option.gen.go index 23251470b..72976a3fe 100644 --- a/api/accounts/option.gen.go +++ b/api/accounts/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithAttributes(inAttributes map[string]interface{}) Option { return func(o *options) { o.postMap["attributes"] = inAttributes diff --git a/api/authmethods/authmethods.gen.go b/api/authmethods/authmethods.gen.go index 25df6290a..b8ee11c99 100644 --- a/api/authmethods/authmethods.gen.go +++ b/api/authmethods/authmethods.gen.go @@ -181,7 +181,7 @@ func (c *Client) Read(ctx context.Context, authMethodId string, opt ...Option) ( req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -213,7 +213,7 @@ func (c *Client) Update(ctx context.Context, authMethodId string, version uint32 if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, authMethodId, opt...) + existingTarget, existingErr := c.Read(ctx, authMethodId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/authmethods/option.gen.go b/api/authmethods/option.gen.go index d21ff3ade..6334be764 100644 --- a/api/authmethods/option.gen.go +++ b/api/authmethods/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithAttributes(inAttributes map[string]interface{}) Option { return func(o *options) { o.postMap["attributes"] = inAttributes diff --git a/api/authtokens/authtokens.gen.go b/api/authtokens/authtokens.gen.go index e27e57b1b..cd1930955 100644 --- a/api/authtokens/authtokens.gen.go +++ b/api/authtokens/authtokens.gen.go @@ -132,7 +132,7 @@ func (c *Client) Read(ctx context.Context, authTokenId string, opt ...Option) (* req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } diff --git a/api/authtokens/option.gen.go b/api/authtokens/option.gen.go index c553a16c6..8c27f4dc5 100644 --- a/api/authtokens/option.gen.go +++ b/api/authtokens/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -44,3 +48,11 @@ func WithAutomaticVersioning(enable bool) Option { o.withAutomaticVersioning = enable } } + +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} diff --git a/api/client.go b/api/client.go index 321d5d653..18d6126f9 100644 --- a/api/client.go +++ b/api/client.go @@ -680,14 +680,17 @@ func (c *Client) NewRequest(ctx context.Context, method, requestPath string, bod ret := &retryablehttp.Request{ Request: req, } - ret.SetBody(rawBody) + if err := ret.SetBody(rawBody); err != nil { + return nil, fmt.Errorf("error setting the raw body of the request: %w", err) + } return ret, nil } // Do takes a properly configured request and applies client configuration to // it, returning the response. -func (c *Client) Do(r *retryablehttp.Request) (*Response, error) { +func (c *Client) Do(r *retryablehttp.Request, opt ...Option) (*Response, error) { + opts := getOpts(opt...) c.modifyLock.RLock() limiter := c.config.Limiter maxRetries := c.config.MaxRetries @@ -697,13 +700,15 @@ func (c *Client) Do(r *retryablehttp.Request) (*Response, error) { timeout := c.config.Timeout token := c.config.Token recoveryKmsWrapper := c.config.RecoveryKmsWrapper - outputCurlString := c.config.OutputCurlString + outputCurlString := c.config.OutputCurlString && !opts.withSkipCurlOuptut c.modifyLock.RUnlock() ctx := r.Context() if limiter != nil { - limiter.Wait(ctx) + if err := limiter.Wait(ctx); err != nil { + return nil, fmt.Errorf("error waiting on rate limiter: %w", err) + } } // Sanity check the token before potentially erroring from the API diff --git a/api/groups/group.gen.go b/api/groups/group.gen.go index 6b1d67a2f..e051ee388 100644 --- a/api/groups/group.gen.go +++ b/api/groups/group.gen.go @@ -176,7 +176,7 @@ func (c *Client) Read(ctx context.Context, groupId string, opt ...Option) (*Grou req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -208,7 +208,7 @@ func (c *Client) Update(ctx context.Context, groupId string, version uint32, opt if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, groupId, opt...) + existingTarget, existingErr := c.Read(ctx, groupId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -357,7 +357,7 @@ func (c *Client) AddMembers(ctx context.Context, groupId string, version uint32, if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into AddMembers request") } - existingTarget, existingErr := c.Read(ctx, groupId, opt...) + existingTarget, existingErr := c.Read(ctx, groupId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -422,7 +422,7 @@ func (c *Client) SetMembers(ctx context.Context, groupId string, version uint32, if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into SetMembers request") } - existingTarget, existingErr := c.Read(ctx, groupId, opt...) + existingTarget, existingErr := c.Read(ctx, groupId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -489,7 +489,7 @@ func (c *Client) RemoveMembers(ctx context.Context, groupId string, version uint if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into RemoveMembers request") } - existingTarget, existingErr := c.Read(ctx, groupId, opt...) + existingTarget, existingErr := c.Read(ctx, groupId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/groups/option.gen.go b/api/groups/option.gen.go index 96420d58b..e4a8d604e 100644 --- a/api/groups/option.gen.go +++ b/api/groups/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithDescription(inDescription string) Option { return func(o *options) { o.postMap["description"] = inDescription diff --git a/api/hostcatalogs/host_catalog.gen.go b/api/hostcatalogs/host_catalog.gen.go index 104e07711..bbaaf3857 100644 --- a/api/hostcatalogs/host_catalog.gen.go +++ b/api/hostcatalogs/host_catalog.gen.go @@ -181,7 +181,7 @@ func (c *Client) Read(ctx context.Context, hostCatalogId string, opt ...Option) req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -213,7 +213,7 @@ func (c *Client) Update(ctx context.Context, hostCatalogId string, version uint3 if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, hostCatalogId, opt...) + existingTarget, existingErr := c.Read(ctx, hostCatalogId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/hostcatalogs/option.gen.go b/api/hostcatalogs/option.gen.go index 883ff83c1..77e6af11c 100644 --- a/api/hostcatalogs/option.gen.go +++ b/api/hostcatalogs/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithAttributes(inAttributes map[string]interface{}) Option { return func(o *options) { o.postMap["attributes"] = inAttributes diff --git a/api/hosts/host.gen.go b/api/hosts/host.gen.go index 72f83fce3..27a5f117f 100644 --- a/api/hosts/host.gen.go +++ b/api/hosts/host.gen.go @@ -177,7 +177,7 @@ func (c *Client) Read(ctx context.Context, hostId string, opt ...Option) (*HostR req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -209,7 +209,7 @@ func (c *Client) Update(ctx context.Context, hostId string, version uint32, opt if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, hostId, opt...) + existingTarget, existingErr := c.Read(ctx, hostId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/hosts/option.gen.go b/api/hosts/option.gen.go index 6ea514da3..24bc93ddf 100644 --- a/api/hosts/option.gen.go +++ b/api/hosts/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithStaticHostAddress(inAddress string) Option { return func(o *options) { raw, ok := o.postMap["attributes"] diff --git a/api/hostsets/host_set.gen.go b/api/hostsets/host_set.gen.go index 4be35aec8..2f4b639d3 100644 --- a/api/hostsets/host_set.gen.go +++ b/api/hostsets/host_set.gen.go @@ -177,7 +177,7 @@ func (c *Client) Read(ctx context.Context, hostSetId string, opt ...Option) (*Ho req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -209,7 +209,7 @@ func (c *Client) Update(ctx context.Context, hostSetId string, version uint32, o if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, hostSetId, opt...) + existingTarget, existingErr := c.Read(ctx, hostSetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -358,7 +358,7 @@ func (c *Client) AddHosts(ctx context.Context, hostSetId string, version uint32, if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into AddHosts request") } - existingTarget, existingErr := c.Read(ctx, hostSetId, opt...) + existingTarget, existingErr := c.Read(ctx, hostSetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -423,7 +423,7 @@ func (c *Client) SetHosts(ctx context.Context, hostSetId string, version uint32, if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into SetHosts request") } - existingTarget, existingErr := c.Read(ctx, hostSetId, opt...) + existingTarget, existingErr := c.Read(ctx, hostSetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -490,7 +490,7 @@ func (c *Client) RemoveHosts(ctx context.Context, hostSetId string, version uint if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into RemoveHosts request") } - existingTarget, existingErr := c.Read(ctx, hostSetId, opt...) + existingTarget, existingErr := c.Read(ctx, hostSetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/hostsets/option.gen.go b/api/hostsets/option.gen.go index 12f651cfb..73280f76b 100644 --- a/api/hostsets/option.gen.go +++ b/api/hostsets/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithDescription(inDescription string) Option { return func(o *options) { o.postMap["description"] = inDescription diff --git a/api/options.go b/api/options.go index c40a7ecfb..b29dd4a51 100644 --- a/api/options.go +++ b/api/options.go @@ -12,8 +12,18 @@ func getOpts(opt ...Option) options { type Option func(*options) // options = how options are represented -type options struct{} +type options struct { + withSkipCurlOuptut bool +} func getDefaultOptions() options { return options{} } + +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOuptut = true + } +} diff --git a/api/roles/option.gen.go b/api/roles/option.gen.go index fd1d72b6f..a80c23c92 100644 --- a/api/roles/option.gen.go +++ b/api/roles/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithDescription(inDescription string) Option { return func(o *options) { o.postMap["description"] = inDescription diff --git a/api/roles/role.gen.go b/api/roles/role.gen.go index e840f0bb6..51db5f7a3 100644 --- a/api/roles/role.gen.go +++ b/api/roles/role.gen.go @@ -179,7 +179,7 @@ func (c *Client) Read(ctx context.Context, roleId string, opt ...Option) (*RoleR req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -211,7 +211,7 @@ func (c *Client) Update(ctx context.Context, roleId string, version uint32, opt if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, roleId, opt...) + existingTarget, existingErr := c.Read(ctx, roleId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -360,7 +360,7 @@ func (c *Client) AddGrants(ctx context.Context, roleId string, version uint32, g if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into AddGrants request") } - existingTarget, existingErr := c.Read(ctx, roleId, opt...) + existingTarget, existingErr := c.Read(ctx, roleId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -427,7 +427,7 @@ func (c *Client) AddPrincipals(ctx context.Context, roleId string, version uint3 if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into AddPrincipals request") } - existingTarget, existingErr := c.Read(ctx, roleId, opt...) + existingTarget, existingErr := c.Read(ctx, roleId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -492,7 +492,7 @@ func (c *Client) SetGrants(ctx context.Context, roleId string, version uint32, g if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into SetGrants request") } - existingTarget, existingErr := c.Read(ctx, roleId, opt...) + existingTarget, existingErr := c.Read(ctx, roleId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -557,7 +557,7 @@ func (c *Client) SetPrincipals(ctx context.Context, roleId string, version uint3 if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into SetPrincipals request") } - existingTarget, existingErr := c.Read(ctx, roleId, opt...) + existingTarget, existingErr := c.Read(ctx, roleId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -624,7 +624,7 @@ func (c *Client) RemoveGrants(ctx context.Context, roleId string, version uint32 if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into RemoveGrants request") } - existingTarget, existingErr := c.Read(ctx, roleId, opt...) + existingTarget, existingErr := c.Read(ctx, roleId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -691,7 +691,7 @@ func (c *Client) RemovePrincipals(ctx context.Context, roleId string, version ui if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into RemovePrincipals request") } - existingTarget, existingErr := c.Read(ctx, roleId, opt...) + existingTarget, existingErr := c.Read(ctx, roleId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/scopes/option.gen.go b/api/scopes/option.gen.go index 10b11ed5d..e75986358 100644 --- a/api/scopes/option.gen.go +++ b/api/scopes/option.gen.go @@ -19,6 +19,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -34,6 +35,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -47,6 +51,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithDescription(inDescription string) Option { return func(o *options) { o.postMap["description"] = inDescription diff --git a/api/scopes/scope.gen.go b/api/scopes/scope.gen.go index 9f59d3c41..6ff81c340 100644 --- a/api/scopes/scope.gen.go +++ b/api/scopes/scope.gen.go @@ -174,7 +174,7 @@ func (c *Client) Read(ctx context.Context, scopeId string, opt ...Option) (*Scop req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -206,7 +206,7 @@ func (c *Client) Update(ctx context.Context, scopeId string, version uint32, opt if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, scopeId, opt...) + existingTarget, existingErr := c.Read(ctx, scopeId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/sessions/option.gen.go b/api/sessions/option.gen.go index f3716ca53..c084f5f59 100644 --- a/api/sessions/option.gen.go +++ b/api/sessions/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -44,3 +48,11 @@ func WithAutomaticVersioning(enable bool) Option { o.withAutomaticVersioning = enable } } + +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} diff --git a/api/sessions/session.gen.go b/api/sessions/session.gen.go index cf454470c..3bb30ac86 100644 --- a/api/sessions/session.gen.go +++ b/api/sessions/session.gen.go @@ -140,7 +140,7 @@ func (c *Client) Read(ctx context.Context, sessionId string, opt ...Option) (*Se req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } diff --git a/api/targets/option.gen.go b/api/targets/option.gen.go index 305b3d182..fe410d36f 100644 --- a/api/targets/option.gen.go +++ b/api/targets/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithAttributes(inAttributes map[string]interface{}) Option { return func(o *options) { o.postMap["attributes"] = inAttributes diff --git a/api/targets/target.gen.go b/api/targets/target.gen.go index 75b0ecb1c..03941b088 100644 --- a/api/targets/target.gen.go +++ b/api/targets/target.gen.go @@ -185,7 +185,7 @@ func (c *Client) Read(ctx context.Context, targetId string, opt ...Option) (*Tar req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -217,7 +217,7 @@ func (c *Client) Update(ctx context.Context, targetId string, version uint32, op if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, targetId, opt...) + existingTarget, existingErr := c.Read(ctx, targetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -366,7 +366,7 @@ func (c *Client) AddHostSets(ctx context.Context, targetId string, version uint3 if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into AddHostSets request") } - existingTarget, existingErr := c.Read(ctx, targetId, opt...) + existingTarget, existingErr := c.Read(ctx, targetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -431,7 +431,7 @@ func (c *Client) SetHostSets(ctx context.Context, targetId string, version uint3 if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into SetHostSets request") } - existingTarget, existingErr := c.Read(ctx, targetId, opt...) + existingTarget, existingErr := c.Read(ctx, targetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -498,7 +498,7 @@ func (c *Client) RemoveHostSets(ctx context.Context, targetId string, version ui if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into RemoveHostSets request") } - existingTarget, existingErr := c.Read(ctx, targetId, opt...) + existingTarget, existingErr := c.Read(ctx, targetId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/api/users/option.gen.go b/api/users/option.gen.go index 3f5072cd1..25ae4a13c 100644 --- a/api/users/option.gen.go +++ b/api/users/option.gen.go @@ -17,6 +17,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -32,6 +33,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -45,6 +49,14 @@ func WithAutomaticVersioning(enable bool) Option { } } +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + func WithDescription(inDescription string) Option { return func(o *options) { o.postMap["description"] = inDescription diff --git a/api/users/user.gen.go b/api/users/user.gen.go index ddda2dd53..7cf461da4 100644 --- a/api/users/user.gen.go +++ b/api/users/user.gen.go @@ -176,7 +176,7 @@ func (c *Client) Read(ctx context.Context, userId string, opt ...Option) (*UserR req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -208,7 +208,7 @@ func (c *Client) Update(ctx context.Context, userId string, version uint32, opt if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, userId, opt...) + existingTarget, existingErr := c.Read(ctx, userId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -357,7 +357,7 @@ func (c *Client) AddAccounts(ctx context.Context, userId string, version uint32, if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into AddAccounts request") } - existingTarget, existingErr := c.Read(ctx, userId, opt...) + existingTarget, existingErr := c.Read(ctx, userId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -422,7 +422,7 @@ func (c *Client) SetAccounts(ctx context.Context, userId string, version uint32, if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into SetAccounts request") } - existingTarget, existingErr := c.Read(ctx, userId, opt...) + existingTarget, existingErr := c.Read(ctx, userId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -489,7 +489,7 @@ func (c *Client) RemoveAccounts(ctx context.Context, userId string, version uint if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into RemoveAccounts request") } - existingTarget, existingErr := c.Read(ctx, userId, opt...) + existingTarget, existingErr := c.Read(ctx, userId, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) diff --git a/internal/api/genapi/templates.go b/internal/api/genapi/templates.go index c44a9276f..af725eb69 100644 --- a/internal/api/genapi/templates.go +++ b/internal/api/genapi/templates.go @@ -249,7 +249,7 @@ func (c *Client) Read(ctx context.Context, {{ .ResourceFunctionArg }} string, op req.URL.RawQuery = q.Encode() } - resp, err := c.client.Do(req) + resp, err := c.client.Do(req, apiOpts...) if err != nil { return nil, fmt.Errorf("error performing client request during Read call: %w", err) } @@ -385,7 +385,7 @@ func (c *Client) Update(ctx context.Context, {{ .ResourceFunctionArg }} string, if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into Update request and automatic versioning not specified") } - existingTarget, existingErr := c.Read(ctx, {{ .ResourceFunctionArg }}, opt...) + existingTarget, existingErr := c.Read(ctx, {{ .ResourceFunctionArg }}, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -468,7 +468,7 @@ func (c *Client) {{ $fullName }}(ctx context.Context, {{ $input.ResourceFunction if !opts.withAutomaticVersioning { return nil, errors.New("zero version number passed into {{ $fullName }} request") } - existingTarget, existingErr := c.Read(ctx, {{ $input.ResourceFunctionArg }}, opt...) + existingTarget, existingErr := c.Read(ctx, {{ $input.ResourceFunctionArg }}, append([]Option{WithSkipCurlOutput(true)}, opt...)...) if existingErr != nil { if api.AsServerError(existingErr) != nil { return nil, fmt.Errorf("error from controller when performing initial check-and-set read: %w", existingErr) @@ -655,6 +655,7 @@ type options struct { postMap map[string]interface{} queryMap map[string]string withAutomaticVersioning bool + withSkipCurlOutput bool } func getDefaultOptions() options { @@ -670,6 +671,9 @@ func getOpts(opt ...Option) (options, []api.Option) { o(&opts) } var apiOpts []api.Option + if opts.withSkipCurlOutput { + apiOpts = append(apiOpts, api.WithSkipCurlOutput(true)) + } return opts, apiOpts } @@ -682,6 +686,15 @@ func WithAutomaticVersioning(enable bool) Option { o.withAutomaticVersioning = enable } } + +// WithSkipCurlOutput tells the API to not use the current call for cURL output. +// Useful for when we need to look up versions. +func WithSkipCurlOutput(skip bool) Option { + return func(o *options) { + o.withSkipCurlOutput = true + } +} + {{ range .Fields }} func With{{ .SubtypeName }}{{ .Name }}(in{{ .Name }} {{ .FieldType }}) Option { return func(o *options) { {{ if ( not ( eq .SubtypeName "" ) ) }}