Skip curl output when using automatic versioning and reading (#858)

This makes it so that the actual output is the update/delete.

Fixes #856
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-01-08 17:30:41 -05:00
1 parent 31ece74a92
commit 9de928318d
29 files changed
+228 -49

No files matched your search

+6
View File
@@ -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))
+2 -1
View File
@@ -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:
+2 -2
View File
@@ -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)
+12
View File
@@ -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
+2 -2
View File
@@ -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)
+12
View File
@@ -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
+1 -1
View File
@@ -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)
}
+12
View File
@@ -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
}
}
+9 -4
View File
@@ -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
+5 -5
View File
@@ -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)
+12
View File
@@ -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
+2 -2
View File
@@ -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)
+12
View File
@@ -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
+2 -2
View File
@@ -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)
+12
View File
@@ -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"]
+5 -5
View File
@@ -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)
+12
View File
@@ -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
+11 -1
View File
@@ -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
}
}
+12
View File
@@ -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
+8 -8
View File
@@ -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)
+12
View File
@@ -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
+2 -2
View File
@@ -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)
+12
View File
@@ -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
}
}
+1 -1
View File
@@ -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)
}
+12
View File
@@ -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
+5 -5
View File
@@ -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)
+12
View File
@@ -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
+5 -5
View File
@@ -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)
+16 -3
View File
@@ -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 "" ) ) }}