Add ability to skip role creation on scope create (#308)

* Initial work on scope creation skipping

* Fix things
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-08-26 23:27:25 -04:00
1 parent e4da5e9ab5
commit 490be8a7e4
27 files changed
+962 -304

No files matched your search

+47 -6
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -43,11 +44,19 @@ func (c *AccountsClient) Create(ctx context.Context, authMethodId string, opt ..
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("auth-methods/%s/accounts", authMethodId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("auth-methods/%s/accounts", authMethodId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -77,13 +86,21 @@ func (c *AccountsClient) Read(ctx context.Context, authMethodId string, accountI
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -130,13 +147,21 @@ func (c *AccountsClient) Update(ctx context.Context, authMethodId string, accoun
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -166,13 +191,21 @@ func (c *AccountsClient) Delete(ctx context.Context, authMethodId string, accoun
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -201,13 +234,21 @@ func (c *AccountsClient) List(ctx context.Context, authMethodId string, opt ...O
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-methods/%s/accounts", authMethodId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
+48 -7
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -41,14 +42,22 @@ func (c *AuthMethodsClient) Create(ctx context.Context, resourceType string, opt
if resourceType == "" {
return nil, nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.valueMap["type"] = resourceType
opts.postMap["type"] = resourceType
}
req, err := c.client.NewRequest(ctx, "POST", "auth-methods", opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", "auth-methods", opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -74,13 +83,21 @@ func (c *AuthMethodsClient) Read(ctx context.Context, authMethodId string, opt .
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-methods/%s", authMethodId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -124,13 +141,21 @@ func (c *AuthMethodsClient) Update(ctx context.Context, authMethodId string, ver
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s", authMethodId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s", authMethodId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -156,13 +181,21 @@ func (c *AuthMethodsClient) Delete(ctx context.Context, authMethodId string, opt
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("auth-methods/%s", authMethodId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -187,13 +220,21 @@ func (c *AuthMethodsClient) List(ctx context.Context, opt ...Option) ([]*AuthMet
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "auth-methods", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
+26 -24
View File
@@ -14,14 +14,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -55,132 +57,132 @@ func WithAutomaticVersioning() Option {
func WithAttributes(inAttributes map[string]interface{}) Option {
return func(o *options) {
o.valueMap["attributes"] = inAttributes
o.postMap["attributes"] = inAttributes
}
}
func DefaultAttributes() Option {
return func(o *options) {
o.valueMap["attributes"] = nil
o.postMap["attributes"] = nil
}
}
func WithDescription(inDescription string) Option {
return func(o *options) {
o.valueMap["description"] = inDescription
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.valueMap["description"] = nil
o.postMap["description"] = nil
}
}
func WithPasswordAccountLoginName(inLoginName string) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["login_name"] = inLoginName
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAccountLoginName() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["login_name"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func WithPasswordAuthMethodMinLoginNameLength(inMinLoginNameLength uint32) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_login_name_length"] = inMinLoginNameLength
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAuthMethodMinLoginNameLength() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_login_name_length"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func WithPasswordAuthMethodMinPasswordLength(inMinPasswordLength uint32) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_password_length"] = inMinPasswordLength
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAuthMethodMinPasswordLength() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_password_length"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.valueMap["name"] = nil
o.postMap["name"] = nil
}
}
func WithPasswordAccountPassword(inPassword string) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["password"] = inPassword
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAccountPassword() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["password"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
+28 -3
View File
@@ -4,6 +4,7 @@ package authtokens
import (
"context"
"fmt"
"net/url"
"time"
"github.com/hashicorp/boundary/api"
@@ -39,13 +40,21 @@ func (c *AuthTokensClient) Read(ctx context.Context, authTokenId string, opt ...
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-tokens/%s", authTokenId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -71,13 +80,21 @@ func (c *AuthTokensClient) Delete(ctx context.Context, authTokenId string, opt .
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("auth-tokens/%s", authTokenId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -102,13 +119,21 @@ func (c *AuthTokensClient) List(ctx context.Context, opt ...Option) ([]*AuthToke
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "auth-tokens", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
+4 -2
View File
@@ -14,14 +14,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
+81 -16
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -39,11 +40,19 @@ func (c *GroupsClient) Create(ctx context.Context, opt ...Option) (*Group, *api.
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", "groups", opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", "groups", opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -69,13 +78,21 @@ func (c *GroupsClient) Read(ctx context.Context, groupId string, opt ...Option)
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("groups/%s", groupId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -119,13 +136,21 @@ func (c *GroupsClient) Update(ctx context.Context, groupId string, version uint3
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("groups/%s", groupId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("groups/%s", groupId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -151,13 +176,21 @@ func (c *GroupsClient) Delete(ctx context.Context, groupId string, opt ...Option
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("groups/%s", groupId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -182,13 +215,21 @@ func (c *GroupsClient) List(ctx context.Context, opt ...Option) ([]*Group, *api.
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "groups", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
@@ -235,17 +276,25 @@ func (c *GroupsClient) AddMembers(ctx context.Context, groupId string, version u
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(memberIds) > 0 {
opts.valueMap["member_ids"] = memberIds
opts.postMap["member_ids"] = memberIds
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:add-members", groupId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:add-members", groupId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating AddMembers request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during AddMembers call: %w", err)
@@ -289,20 +338,28 @@ func (c *GroupsClient) SetMembers(ctx context.Context, groupId string, version u
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(memberIds) > 0 {
opts.valueMap["member_ids"] = memberIds
opts.postMap["member_ids"] = memberIds
} else if memberIds != nil {
// In this function, a non-nil but empty list means clear out
opts.valueMap["member_ids"] = nil
opts.postMap["member_ids"] = nil
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:set-members", groupId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:set-members", groupId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating SetMembers request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during SetMembers call: %w", err)
@@ -346,17 +403,25 @@ func (c *GroupsClient) RemoveMembers(ctx context.Context, groupId string, versio
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(memberIds) > 0 {
opts.valueMap["member_ids"] = memberIds
opts.postMap["member_ids"] = memberIds
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:remove-members", groupId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups/%s:remove-members", groupId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating RemoveMembers request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during RemoveMembers call: %w", err)
+8 -6
View File
@@ -14,14 +14,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -55,24 +57,24 @@ func WithAutomaticVersioning() Option {
func WithDescription(inDescription string) Option {
return func(o *options) {
o.valueMap["description"] = inDescription
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.valueMap["description"] = nil
o.postMap["description"] = nil
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.valueMap["name"] = nil
o.postMap["name"] = nil
}
}
+47 -6
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -44,11 +45,19 @@ func (c *HostsClient) Create(ctx context.Context, hostCatalogId string, opt ...O
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/hosts", hostCatalogId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/hosts", hostCatalogId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -78,13 +87,21 @@ func (c *HostsClient) Read(ctx context.Context, hostCatalogId string, hostId str
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("host-catalogs/%s/hosts/%s", hostCatalogId, hostId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -131,13 +148,21 @@ func (c *HostsClient) Update(ctx context.Context, hostCatalogId string, hostId s
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("host-catalogs/%s/hosts/%s", hostCatalogId, hostId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("host-catalogs/%s/hosts/%s", hostCatalogId, hostId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -167,13 +192,21 @@ func (c *HostsClient) Delete(ctx context.Context, hostCatalogId string, hostId s
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("host-catalogs/%s/hosts/%s", hostCatalogId, hostId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -202,13 +235,21 @@ func (c *HostsClient) List(ctx context.Context, hostCatalogId string, opt ...Opt
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("host-catalogs/%s/hosts", hostCatalogId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
+48 -7
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -41,14 +42,22 @@ func (c *HostCatalogsClient) Create(ctx context.Context, resourceType string, op
if resourceType == "" {
return nil, nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.valueMap["type"] = resourceType
opts.postMap["type"] = resourceType
}
req, err := c.client.NewRequest(ctx, "POST", "host-catalogs", opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", "host-catalogs", opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -74,13 +83,21 @@ func (c *HostCatalogsClient) Read(ctx context.Context, hostCatalogId string, opt
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("host-catalogs/%s", hostCatalogId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -124,13 +141,21 @@ func (c *HostCatalogsClient) Update(ctx context.Context, hostCatalogId string, v
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("host-catalogs/%s", hostCatalogId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("host-catalogs/%s", hostCatalogId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -156,13 +181,21 @@ func (c *HostCatalogsClient) Delete(ctx context.Context, hostCatalogId string, o
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("host-catalogs/%s", hostCatalogId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -187,13 +220,21 @@ func (c *HostCatalogsClient) List(ctx context.Context, opt ...Option) ([]*HostCa
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "host-catalogs", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
+81 -16
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -44,11 +45,19 @@ func (c *HostSetsClient) Create(ctx context.Context, hostCatalogId string, opt .
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets", hostCatalogId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets", hostCatalogId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -78,13 +87,21 @@ func (c *HostSetsClient) Read(ctx context.Context, hostCatalogId string, hostSet
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("host-catalogs/%s/host-sets/%s", hostCatalogId, hostSetId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -131,13 +148,21 @@ func (c *HostSetsClient) Update(ctx context.Context, hostCatalogId string, hostS
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("host-catalogs/%s/host-sets/%s", hostCatalogId, hostSetId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("host-catalogs/%s/host-sets/%s", hostCatalogId, hostSetId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -167,13 +192,21 @@ func (c *HostSetsClient) Delete(ctx context.Context, hostCatalogId string, hostS
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("host-catalogs/%s/host-sets/%s", hostCatalogId, hostSetId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -202,13 +235,21 @@ func (c *HostSetsClient) List(ctx context.Context, hostCatalogId string, opt ...
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("host-catalogs/%s/host-sets", hostCatalogId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
@@ -258,17 +299,25 @@ func (c *HostSetsClient) AddHosts(ctx context.Context, hostCatalogId string, hos
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(hostIds) > 0 {
opts.valueMap["host_ids"] = hostIds
opts.postMap["host_ids"] = hostIds
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets/%s:add-hosts", hostCatalogId, hostSetId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets/%s:add-hosts", hostCatalogId, hostSetId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating AddHosts request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during AddHosts call: %w", err)
@@ -315,20 +364,28 @@ func (c *HostSetsClient) SetHosts(ctx context.Context, hostCatalogId string, hos
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(hostIds) > 0 {
opts.valueMap["host_ids"] = hostIds
opts.postMap["host_ids"] = hostIds
} else if hostIds != nil {
// In this function, a non-nil but empty list means clear out
opts.valueMap["host_ids"] = nil
opts.postMap["host_ids"] = nil
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets/%s:set-hosts", hostCatalogId, hostSetId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets/%s:set-hosts", hostCatalogId, hostSetId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating SetHosts request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during SetHosts call: %w", err)
@@ -375,17 +432,25 @@ func (c *HostSetsClient) RemoveHosts(ctx context.Context, hostCatalogId string,
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(hostIds) > 0 {
opts.valueMap["host_ids"] = hostIds
opts.postMap["host_ids"] = hostIds
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets/%s:remove-hosts", hostCatalogId, hostSetId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("host-catalogs/%s/host-sets/%s:remove-hosts", hostCatalogId, hostSetId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating RemoveHosts request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during RemoveHosts call: %w", err)
+14 -12
View File
@@ -14,14 +14,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -55,60 +57,60 @@ func WithAutomaticVersioning() Option {
func WithStaticHostAddress(inAddress string) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["address"] = inAddress
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultStaticHostAddress() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["address"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func WithAttributes(inAttributes map[string]interface{}) Option {
return func(o *options) {
o.valueMap["attributes"] = inAttributes
o.postMap["attributes"] = inAttributes
}
}
func DefaultAttributes() Option {
return func(o *options) {
o.valueMap["attributes"] = nil
o.postMap["attributes"] = nil
}
}
func WithDescription(inDescription string) Option {
return func(o *options) {
o.valueMap["description"] = inDescription
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.valueMap["description"] = nil
o.postMap["description"] = nil
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.valueMap["name"] = nil
o.postMap["name"] = nil
}
}
+15 -1
View File
@@ -26,6 +26,7 @@ type fieldInfo struct {
FieldType string
GenerateSdkOption bool
SubtypeName string
Query bool
}
type structInfo struct {
@@ -66,6 +67,11 @@ type structInfo struct {
// typeOnCreate indicates that create will be creating a concrete
// implementation of an abstract type and thus a type field is necessary
typeOnCreate bool
// extraOptions allows specifying extra options that will be created for a
// given type, e.g. arguments only valid for one call or purpose and not
// conveyed within the item itself
extraOptions []fieldInfo
}
var inputStructs = []*structInfo{
@@ -101,7 +107,15 @@ var inputStructs = []*structInfo{
deleteTemplate,
listTemplate,
},
pathArgs: []string{"scope"},
pathArgs: []string{"scope"},
extraOptions: []fieldInfo{
{
Name: "SkipRoleCreation",
ProtoName: "skip_role_creation",
FieldType: "bool",
Query: true,
},
},
versionEnabled: true,
},
// User related resources
+84 -25
View File
@@ -69,6 +69,7 @@ type templateInput struct {
CollectionPath string
ResourcePath string
SliceSubTypes map[string]string
ExtraOptions []fieldInfo
VersionEnabled bool
TypeOnCreate bool
}
@@ -83,6 +84,7 @@ func fillTemplates() {
Package: in.generatedStructure.pkg,
Fields: in.generatedStructure.fields,
PathArgs: in.pathArgs,
ExtraOptions: in.extraOptions,
VersionEnabled: in.versionEnabled,
TypeOnCreate: in.typeOnCreate,
}
@@ -129,6 +131,17 @@ func fillTemplates() {
}
optionsMap[input.Package] = optionMap
}
// Add in extra defined options
if len(in.extraOptions) > 0 {
optionMap := optionsMap[input.Package]
if optionMap == nil {
optionMap = map[string]fieldInfo{}
}
for _, val := range in.extraOptions {
optionMap[val.Name] = val
}
optionsMap[input.Package] = optionMap
}
outFile, err := filepath.Abs(fmt.Sprintf("%s/%s", os.Getenv("API_GEN_BASEPATH"), in.outFile))
if err != nil {
@@ -196,17 +209,22 @@ func (c *{{ .ClientName }}Client) List(ctx context.Context, {{ range .Collection
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", {{ .CollectionPath }}, nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
{{ if ( eq .CollectionPath "\"scopes\"" ) }}
q := url.Values{}
q.Add("scope_id", scopeId)
req.URL.RawQuery = q.Encode()
opts.queryMap["scope_id"] = scopeId
{{ end }}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
@@ -238,13 +256,21 @@ func (c *{{ .ClientName }}Client) Read(ctx context.Context, {{ range .ResourceFu
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", {{ .ResourcePath }}, nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -272,13 +298,21 @@ func (c *{{ .ClientName }}Client) Delete(ctx context.Context, {{ range .Resource
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", {{ .ResourcePath }}, nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -311,18 +345,23 @@ func (c *{{ .ClientName }}Client) Create(ctx context.Context, {{ if .TypeOnCreat
{{ if .TypeOnCreate }} if resourceType == "" {
return nil, nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.valueMap["type"] = resourceType
opts.postMap["type"] = resourceType
}{{ end }}
req, err := c.client.NewRequest(ctx, "POST", {{ .CollectionPath }}, opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", {{ .CollectionPath }}, opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
{{ if ( eq .CollectionPath "\"scopes\"" ) }}
q := url.Values{}
q.Add("scope_id", scopeId)
req.URL.RawQuery = q.Encode()
opts.queryMap["scope_id"] = scopeId
{{ end }}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
@@ -371,13 +410,21 @@ func (c *{{ .ClientName }}Client) Update(ctx context.Context, {{ range .Resource
}
{{ end }}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", {{ .ResourcePath }}, opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", {{ .ResourcePath }}, opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -437,21 +484,29 @@ func (c *{{ $input.ClientName }}Client) {{ $fullName }}(ctx context.Context, {{
version = existingTarget.Version
}
{{ end }}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len({{ $value }}) > 0 {
opts.valueMap["{{ snakeCase $value }}"] = {{ $value }}
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.valueMap["{{ snakeCase $value }}"] = nil
opts.postMap["{{ snakeCase $value }}"] = nil
}
{{ end }}
req, err := c.client.NewRequest(ctx, "POST", {{ $resPath }}, opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", {{ $resPath }}, opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating {{ $fullName }} request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during {{ $fullName }} call: %w", err)
@@ -522,14 +577,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -563,29 +620,31 @@ func WithAutomaticVersioning() Option {
{{ range .Fields }}
func With{{ .SubtypeName }}{{ .Name }}(in{{ .Name }} {{ .FieldType }}) Option {
return func(o *options) { {{ if ( not ( eq .SubtypeName "" ) ) }}
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["{{ .ProtoName }}"] = in{{ .Name }}
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
{{ else if .Query }}
o.queryMap["{{ .ProtoName }}"] = fmt.Sprintf("%v", in{{ .Name }})
{{ else }}
o.valueMap["{{ .ProtoName }}"] = in{{ .Name }}
o.postMap["{{ .ProtoName }}"] = in{{ .Name }}
{{ end }} }
}
func Default{{ .SubtypeName }}{{ .Name }}() Option {
return func(o *options) { {{ if ( not ( eq .SubtypeName "" ) ) }}
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["{{ .ProtoName }}"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
{{ else }}
o.valueMap["{{ .ProtoName }}"] = nil
o.postMap["{{ .ProtoName }}"] = nil
{{ end }} }
}
{{ end }}
+10 -8
View File
@@ -14,14 +14,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -55,36 +57,36 @@ func WithAutomaticVersioning() Option {
func WithDescription(inDescription string) Option {
return func(o *options) {
o.valueMap["description"] = inDescription
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.valueMap["description"] = nil
o.postMap["description"] = nil
}
}
func WithGrantScopeId(inGrantScopeId string) Option {
return func(o *options) {
o.valueMap["grant_scope_id"] = inGrantScopeId
o.postMap["grant_scope_id"] = inGrantScopeId
}
}
func DefaultGrantScopeId() Option {
return func(o *options) {
o.valueMap["grant_scope_id"] = nil
o.postMap["grant_scope_id"] = nil
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.valueMap["name"] = nil
o.postMap["name"] = nil
}
}
+115 -26
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -42,11 +43,19 @@ func (c *RolesClient) Create(ctx context.Context, opt ...Option) (*Role, *api.Er
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", "roles", opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", "roles", opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -72,13 +81,21 @@ func (c *RolesClient) Read(ctx context.Context, roleId string, opt ...Option) (*
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("roles/%s", roleId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -122,13 +139,21 @@ func (c *RolesClient) Update(ctx context.Context, roleId string, version uint32,
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("roles/%s", roleId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("roles/%s", roleId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -154,13 +179,21 @@ func (c *RolesClient) Delete(ctx context.Context, roleId string, opt ...Option)
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("roles/%s", roleId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -185,13 +218,21 @@ func (c *RolesClient) List(ctx context.Context, opt ...Option) ([]*Role, *api.Er
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "roles", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
@@ -238,17 +279,25 @@ func (c *RolesClient) AddGrants(ctx context.Context, roleId string, version uint
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(grantStrings) > 0 {
opts.valueMap["grant_strings"] = grantStrings
opts.postMap["grant_strings"] = grantStrings
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:add-grants", roleId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:add-grants", roleId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating AddGrants request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during AddGrants call: %w", err)
@@ -292,17 +341,25 @@ func (c *RolesClient) AddPrincipals(ctx context.Context, roleId string, version
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(principalIds) > 0 {
opts.valueMap["principal_ids"] = principalIds
opts.postMap["principal_ids"] = principalIds
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:add-principals", roleId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:add-principals", roleId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating AddPrincipals request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during AddPrincipals call: %w", err)
@@ -346,20 +403,28 @@ func (c *RolesClient) SetGrants(ctx context.Context, roleId string, version uint
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(grantStrings) > 0 {
opts.valueMap["grant_strings"] = grantStrings
opts.postMap["grant_strings"] = grantStrings
} else if grantStrings != nil {
// In this function, a non-nil but empty list means clear out
opts.valueMap["grant_strings"] = nil
opts.postMap["grant_strings"] = nil
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:set-grants", roleId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:set-grants", roleId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating SetGrants request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during SetGrants call: %w", err)
@@ -403,20 +468,28 @@ func (c *RolesClient) SetPrincipals(ctx context.Context, roleId string, version
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(principalIds) > 0 {
opts.valueMap["principal_ids"] = principalIds
opts.postMap["principal_ids"] = principalIds
} else if principalIds != nil {
// In this function, a non-nil but empty list means clear out
opts.valueMap["principal_ids"] = nil
opts.postMap["principal_ids"] = nil
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:set-principals", roleId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:set-principals", roleId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating SetPrincipals request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during SetPrincipals call: %w", err)
@@ -460,17 +533,25 @@ func (c *RolesClient) RemoveGrants(ctx context.Context, roleId string, version u
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(grantStrings) > 0 {
opts.valueMap["grant_strings"] = grantStrings
opts.postMap["grant_strings"] = grantStrings
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:remove-grants", roleId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:remove-grants", roleId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating RemoveGrants request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during RemoveGrants call: %w", err)
@@ -514,17 +595,25 @@ func (c *RolesClient) RemovePrincipals(ctx context.Context, roleId string, versi
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
if len(principalIds) > 0 {
opts.valueMap["principal_ids"] = principalIds
opts.postMap["principal_ids"] = principalIds
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:remove-principals", roleId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:remove-principals", roleId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating RemovePrincipals request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during RemovePrincipals call: %w", err)
+22 -6
View File
@@ -1,6 +1,8 @@
package scopes
import (
"fmt"
"github.com/hashicorp/boundary/api"
)
@@ -14,14 +16,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -55,24 +59,36 @@ func WithAutomaticVersioning() Option {
func WithDescription(inDescription string) Option {
return func(o *options) {
o.valueMap["description"] = inDescription
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.valueMap["description"] = nil
o.postMap["description"] = nil
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.valueMap["name"] = nil
o.postMap["name"] = nil
}
}
func WithSkipRoleCreation(inSkipRoleCreation bool) Option {
return func(o *options) {
o.queryMap["skip_role_creation"] = fmt.Sprintf("%v", inSkipRoleCreation)
}
}
func DefaultSkipRoleCreation() Option {
return func(o *options) {
o.postMap["skip_role_creation"] = nil
}
}
+48 -12
View File
@@ -40,14 +40,20 @@ func (c *ScopesClient) Create(ctx context.Context, scopeId string, opt ...Option
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", "scopes", opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", "scopes", opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
q := url.Values{}
q.Add("scope_id", scopeId)
req.URL.RawQuery = q.Encode()
opts.queryMap["scope_id"] = scopeId
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
@@ -74,13 +80,21 @@ func (c *ScopesClient) Read(ctx context.Context, scopeId string, opt ...Option)
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("scopes/%s", scopeId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -124,13 +138,21 @@ func (c *ScopesClient) Update(ctx context.Context, scopeId string, version uint3
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("scopes/%s", scopeId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("scopes/%s", scopeId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -156,13 +178,21 @@ func (c *ScopesClient) Delete(ctx context.Context, scopeId string, opt ...Option
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("scopes/%s", scopeId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -191,16 +221,22 @@ func (c *ScopesClient) List(ctx context.Context, scopeId string, opt ...Option)
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "scopes", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
q := url.Values{}
q.Add("scope_id", scopeId)
req.URL.RawQuery = q.Encode()
opts.queryMap["scope_id"] = scopeId
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
+8 -6
View File
@@ -14,14 +14,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -55,24 +57,24 @@ func WithAutomaticVersioning() Option {
func WithDescription(inDescription string) Option {
return func(o *options) {
o.valueMap["description"] = inDescription
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.valueMap["description"] = nil
o.postMap["description"] = nil
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.valueMap["name"] = nil
o.postMap["name"] = nil
}
}
+47 -6
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -37,11 +38,19 @@ func (c *UsersClient) Create(ctx context.Context, opt ...Option) (*User, *api.Er
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", "users", opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", "users", opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -67,13 +76,21 @@ func (c *UsersClient) Read(ctx context.Context, userId string, opt ...Option) (*
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("users/%s", userId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -117,13 +134,21 @@ func (c *UsersClient) Update(ctx context.Context, userId string, version uint32,
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("users/%s", userId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("users/%s", userId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -149,13 +174,21 @@ func (c *UsersClient) Delete(ctx context.Context, userId string, opt ...Option)
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("users/%s", userId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -180,13 +213,21 @@ func (c *UsersClient) List(ctx context.Context, opt ...Option) ([]*User, *api.Er
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "users", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)