diff --git a/api/groups/group.gen.go b/api/groups/group.gen.go index d0b8c1ced1..037d66d34d 100644 --- a/api/groups/group.gen.go +++ b/api/groups/group.gen.go @@ -287,8 +287,11 @@ func (c *Client) AddMembers(ctx context.Context, groupId string, version uint32, if groupId == "" { return nil, nil, fmt.Errorf("empty groupId value passed into AddMembers request") } + if len(memberIds) == 0 { + return nil, nil, errors.New("empty memberIds passed into AddMembers request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -311,10 +314,7 @@ func (c *Client) AddMembers(ctx context.Context, groupId string, version uint32, } opts.postMap["version"] = version - - if len(memberIds) > 0 { - opts.postMap["member_ids"] = memberIds - } + opts.postMap["member_ids"] = memberIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:add-members", groupId), opts.postMap, apiOpts...) if err != nil { @@ -349,8 +349,9 @@ func (c *Client) SetMembers(ctx context.Context, groupId string, version uint32, if groupId == "" { return nil, nil, fmt.Errorf("empty groupId value passed into SetMembers request") } + if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -373,13 +374,7 @@ func (c *Client) SetMembers(ctx context.Context, groupId string, version uint32, } opts.postMap["version"] = version - - if len(memberIds) > 0 { - opts.postMap["member_ids"] = memberIds - } else if memberIds != nil { - // In this function, a non-nil but empty list means clear out - opts.postMap["member_ids"] = nil - } + opts.postMap["member_ids"] = memberIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:set-members", groupId), opts.postMap, apiOpts...) if err != nil { @@ -414,8 +409,11 @@ func (c *Client) RemoveMembers(ctx context.Context, groupId string, version uint if groupId == "" { return nil, nil, fmt.Errorf("empty groupId value passed into RemoveMembers request") } + if len(memberIds) == 0 { + return nil, nil, errors.New("empty memberIds passed into RemoveMembers request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -438,10 +436,7 @@ func (c *Client) RemoveMembers(ctx context.Context, groupId string, version uint } opts.postMap["version"] = version - - if len(memberIds) > 0 { - opts.postMap["member_ids"] = memberIds - } + opts.postMap["member_ids"] = memberIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:remove-members", groupId), opts.postMap, apiOpts...) if err != nil { diff --git a/api/hostsets/host_set.gen.go b/api/hostsets/host_set.gen.go index 1d4babe5f0..4d21e406f3 100644 --- a/api/hostsets/host_set.gen.go +++ b/api/hostsets/host_set.gen.go @@ -288,8 +288,11 @@ func (c *Client) AddHosts(ctx context.Context, hostSetId string, version uint32, if hostSetId == "" { return nil, nil, fmt.Errorf("empty hostSetId value passed into AddHosts request") } + if len(hostIds) == 0 { + return nil, nil, errors.New("empty hostIds passed into AddHosts request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -312,10 +315,7 @@ func (c *Client) AddHosts(ctx context.Context, hostSetId string, version uint32, } opts.postMap["version"] = version - - if len(hostIds) > 0 { - opts.postMap["host_ids"] = hostIds - } + opts.postMap["host_ids"] = hostIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-sets/%s:add-hosts", hostSetId), opts.postMap, apiOpts...) if err != nil { @@ -350,8 +350,9 @@ func (c *Client) SetHosts(ctx context.Context, hostSetId string, version uint32, if hostSetId == "" { return nil, nil, fmt.Errorf("empty hostSetId value passed into SetHosts request") } + if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -374,13 +375,7 @@ func (c *Client) SetHosts(ctx context.Context, hostSetId string, version uint32, } opts.postMap["version"] = version - - if len(hostIds) > 0 { - opts.postMap["host_ids"] = hostIds - } else if hostIds != nil { - // In this function, a non-nil but empty list means clear out - opts.postMap["host_ids"] = nil - } + opts.postMap["host_ids"] = hostIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-sets/%s:set-hosts", hostSetId), opts.postMap, apiOpts...) if err != nil { @@ -415,8 +410,11 @@ func (c *Client) RemoveHosts(ctx context.Context, hostSetId string, version uint if hostSetId == "" { return nil, nil, fmt.Errorf("empty hostSetId value passed into RemoveHosts request") } + if len(hostIds) == 0 { + return nil, nil, errors.New("empty hostIds passed into RemoveHosts request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -439,10 +437,7 @@ func (c *Client) RemoveHosts(ctx context.Context, hostSetId string, version uint } opts.postMap["version"] = version - - if len(hostIds) > 0 { - opts.postMap["host_ids"] = hostIds - } + opts.postMap["host_ids"] = hostIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-sets/%s:remove-hosts", hostSetId), opts.postMap, apiOpts...) if err != nil { diff --git a/api/internal/genapi/templates.go b/api/internal/genapi/templates.go index a33823632b..84bed5a312 100644 --- a/api/internal/genapi/templates.go +++ b/api/internal/genapi/templates.go @@ -472,8 +472,11 @@ func (c *Client) {{ $fullName }}(ctx context.Context, {{ $input.ResourceFunction if {{ $input.ResourceFunctionArg }} == "" { return nil, nil, fmt.Errorf("empty {{ $input.ResourceFunctionArg }} value passed into {{ $fullName }} request") } + {{ if ( not ( eq $op "Set" ) ) }}if len({{ $value }}) == 0 { + return nil, nil, errors.New("empty {{ $value }} passed into {{ $fullName }} request") + }{{ end }} if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -497,14 +500,7 @@ func (c *Client) {{ $fullName }}(ctx context.Context, {{ $input.ResourceFunction } {{ end }} opts.postMap["version"] = version - - if len({{ $value }}) > 0 { - opts.postMap["{{ snakeCase $value }}"] = {{ $value }} - }{{ if ( eq $op "Set" ) }} else if {{ $value }} != nil { - // In this function, a non-nil but empty list means clear out - opts.postMap["{{ snakeCase $value }}"] = nil - } - {{ end }} + opts.postMap["{{ snakeCase $value }}"] = {{ $value }} req, err := c.client.NewRequest(ctx, "POST", {{ $resPath }}, opts.postMap, apiOpts...) if err != nil { diff --git a/api/roles/role.gen.go b/api/roles/role.gen.go index a2ebd9fed6..b39163eb9d 100644 --- a/api/roles/role.gen.go +++ b/api/roles/role.gen.go @@ -290,8 +290,11 @@ func (c *Client) AddGrants(ctx context.Context, roleId string, version uint32, g if roleId == "" { return nil, nil, fmt.Errorf("empty roleId value passed into AddGrants request") } + if len(grantStrings) == 0 { + return nil, nil, errors.New("empty grantStrings passed into AddGrants request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -314,10 +317,7 @@ func (c *Client) AddGrants(ctx context.Context, roleId string, version uint32, g } opts.postMap["version"] = version - - if len(grantStrings) > 0 { - opts.postMap["grant_strings"] = grantStrings - } + opts.postMap["grant_strings"] = grantStrings req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:add-grants", roleId), opts.postMap, apiOpts...) if err != nil { @@ -352,8 +352,11 @@ func (c *Client) AddPrincipals(ctx context.Context, roleId string, version uint3 if roleId == "" { return nil, nil, fmt.Errorf("empty roleId value passed into AddPrincipals request") } + if len(principalIds) == 0 { + return nil, nil, errors.New("empty principalIds passed into AddPrincipals request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -376,10 +379,7 @@ func (c *Client) AddPrincipals(ctx context.Context, roleId string, version uint3 } opts.postMap["version"] = version - - if len(principalIds) > 0 { - opts.postMap["principal_ids"] = principalIds - } + opts.postMap["principal_ids"] = principalIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:add-principals", roleId), opts.postMap, apiOpts...) if err != nil { @@ -414,8 +414,9 @@ func (c *Client) SetGrants(ctx context.Context, roleId string, version uint32, g if roleId == "" { return nil, nil, fmt.Errorf("empty roleId value passed into SetGrants request") } + if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -438,13 +439,7 @@ func (c *Client) SetGrants(ctx context.Context, roleId string, version uint32, g } opts.postMap["version"] = version - - if len(grantStrings) > 0 { - opts.postMap["grant_strings"] = grantStrings - } else if grantStrings != nil { - // In this function, a non-nil but empty list means clear out - opts.postMap["grant_strings"] = nil - } + opts.postMap["grant_strings"] = grantStrings req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:set-grants", roleId), opts.postMap, apiOpts...) if err != nil { @@ -479,8 +474,9 @@ func (c *Client) SetPrincipals(ctx context.Context, roleId string, version uint3 if roleId == "" { return nil, nil, fmt.Errorf("empty roleId value passed into SetPrincipals request") } + if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -503,13 +499,7 @@ func (c *Client) SetPrincipals(ctx context.Context, roleId string, version uint3 } opts.postMap["version"] = version - - if len(principalIds) > 0 { - opts.postMap["principal_ids"] = principalIds - } else if principalIds != nil { - // In this function, a non-nil but empty list means clear out - opts.postMap["principal_ids"] = nil - } + opts.postMap["principal_ids"] = principalIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:set-principals", roleId), opts.postMap, apiOpts...) if err != nil { @@ -544,8 +534,11 @@ func (c *Client) RemoveGrants(ctx context.Context, roleId string, version uint32 if roleId == "" { return nil, nil, fmt.Errorf("empty roleId value passed into RemoveGrants request") } + if len(grantStrings) == 0 { + return nil, nil, errors.New("empty grantStrings passed into RemoveGrants request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -568,10 +561,7 @@ func (c *Client) RemoveGrants(ctx context.Context, roleId string, version uint32 } opts.postMap["version"] = version - - if len(grantStrings) > 0 { - opts.postMap["grant_strings"] = grantStrings - } + opts.postMap["grant_strings"] = grantStrings req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:remove-grants", roleId), opts.postMap, apiOpts...) if err != nil { @@ -606,8 +596,11 @@ func (c *Client) RemovePrincipals(ctx context.Context, roleId string, version ui if roleId == "" { return nil, nil, fmt.Errorf("empty roleId value passed into RemovePrincipals request") } + if len(principalIds) == 0 { + return nil, nil, errors.New("empty principalIds passed into RemovePrincipals request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -630,10 +623,7 @@ func (c *Client) RemovePrincipals(ctx context.Context, roleId string, version ui } opts.postMap["version"] = version - - if len(principalIds) > 0 { - opts.postMap["principal_ids"] = principalIds - } + opts.postMap["principal_ids"] = principalIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:remove-principals", roleId), opts.postMap, apiOpts...) if err != nil { diff --git a/api/targets/target.gen.go b/api/targets/target.gen.go index d210947a57..79f466c8f2 100644 --- a/api/targets/target.gen.go +++ b/api/targets/target.gen.go @@ -294,8 +294,11 @@ func (c *Client) AddHostSets(ctx context.Context, targetId string, version uint3 if targetId == "" { return nil, nil, fmt.Errorf("empty targetId value passed into AddHostSets request") } + if len(hostSetIds) == 0 { + return nil, nil, errors.New("empty hostSetIds passed into AddHostSets request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -318,10 +321,7 @@ func (c *Client) AddHostSets(ctx context.Context, targetId string, version uint3 } opts.postMap["version"] = version - - if len(hostSetIds) > 0 { - opts.postMap["host_set_ids"] = hostSetIds - } + opts.postMap["host_set_ids"] = hostSetIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("targets/%s:add-host-sets", targetId), opts.postMap, apiOpts...) if err != nil { @@ -356,8 +356,9 @@ func (c *Client) SetHostSets(ctx context.Context, targetId string, version uint3 if targetId == "" { return nil, nil, fmt.Errorf("empty targetId value passed into SetHostSets request") } + if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -380,13 +381,7 @@ func (c *Client) SetHostSets(ctx context.Context, targetId string, version uint3 } opts.postMap["version"] = version - - if len(hostSetIds) > 0 { - opts.postMap["host_set_ids"] = hostSetIds - } else if hostSetIds != nil { - // In this function, a non-nil but empty list means clear out - opts.postMap["host_set_ids"] = nil - } + opts.postMap["host_set_ids"] = hostSetIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("targets/%s:set-host-sets", targetId), opts.postMap, apiOpts...) if err != nil { @@ -421,8 +416,11 @@ func (c *Client) RemoveHostSets(ctx context.Context, targetId string, version ui if targetId == "" { return nil, nil, fmt.Errorf("empty targetId value passed into RemoveHostSets request") } + if len(hostSetIds) == 0 { + return nil, nil, errors.New("empty hostSetIds passed into RemoveHostSets request") + } if c.client == nil { - return nil, nil, fmt.Errorf("nil client") + return nil, nil, errors.New("nil client") } opts, apiOpts := getOpts(opt...) @@ -445,10 +443,7 @@ func (c *Client) RemoveHostSets(ctx context.Context, targetId string, version ui } opts.postMap["version"] = version - - if len(hostSetIds) > 0 { - opts.postMap["host_set_ids"] = hostSetIds - } + opts.postMap["host_set_ids"] = hostSetIds req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("targets/%s:remove-host-sets", targetId), opts.postMap, apiOpts...) if err != nil {