Add ability to skip role creation on scope create (#308)
* Initial work on scope creation skipping * Fix things
This commit is contained in:
1 parent
e4da5e9ab5
commit
490be8a7e4
27 files changed
+962
-304
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
@@ -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
@@ -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
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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
@@ -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)
|
||||
|
||||
@@ -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
@@ -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 {
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
@@ -21,6 +21,8 @@ type Command struct {
|
||||
*base.Command
|
||||
|
||||
Func string
|
||||
|
||||
flagSkipRoleCreation bool
|
||||
}
|
||||
|
||||
func (c *Command) Synopsis() string {
|
||||
@@ -28,7 +30,7 @@ func (c *Command) Synopsis() string {
|
||||
}
|
||||
|
||||
var flagsMap = map[string][]string{
|
||||
"create": {"name", "description"},
|
||||
"create": {"name", "description", "skip-role-creation"},
|
||||
"update": {"id", "name", "description", "version"},
|
||||
"read": {"id"},
|
||||
"delete": {"id"},
|
||||
@@ -48,6 +50,13 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
if len(flagsMap[c.Func]) > 0 {
|
||||
f := set.NewFlagSet("Command Options")
|
||||
common.PopulateCommonFlags(c.Command, f, resource.Scope.String(), flagsMap[c.Func])
|
||||
if c.Func == "create" {
|
||||
f.BoolVar(&base.BoolVar{
|
||||
Name: "skip-role-creation",
|
||||
Target: &c.flagSkipRoleCreation,
|
||||
Usage: "If set, a role granting the current user access to administer the newly-created scope will not automatically be created",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return set
|
||||
@@ -102,6 +111,8 @@ func (c *Command) Run(args []string) int {
|
||||
opts = append(opts, scopes.WithDescription(c.FlagDescription))
|
||||
}
|
||||
|
||||
opts = append(opts, scopes.WithSkipRoleCreation(c.flagSkipRoleCreation))
|
||||
|
||||
scopeClient := scopes.NewScopesClient(client)
|
||||
|
||||
// Perform check-and-set when needed
|
||||
|
||||
@@ -71,6 +71,13 @@
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "skip_role_creation",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "boolean",
|
||||
"format": "boolean"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
|
||||
@@ -242,8 +242,9 @@ type CreateScopeRequest struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ScopeId string `protobuf:"bytes,1,opt,name=scope_id,json=scopeId,proto3" json:"scope_id,omitempty"`
|
||||
Item *scopes.Scope `protobuf:"bytes,2,opt,name=item,proto3" json:"item,omitempty"`
|
||||
ScopeId string `protobuf:"bytes,1,opt,name=scope_id,json=scopeId,proto3" json:"scope_id,omitempty"`
|
||||
SkipRoleCreation bool `protobuf:"varint,2,opt,name=skip_role_creation,json=skipRoleCreation,proto3" json:"skip_role_creation,omitempty"`
|
||||
Item *scopes.Scope `protobuf:"bytes,3,opt,name=item,proto3" json:"item,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CreateScopeRequest) Reset() {
|
||||
@@ -285,6 +286,13 @@ func (x *CreateScopeRequest) GetScopeId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CreateScopeRequest) GetSkipRoleCreation() bool {
|
||||
if x != nil {
|
||||
return x.SkipRoleCreation
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *CreateScopeRequest) GetItem() *scopes.Scope {
|
||||
if x != nil {
|
||||
return x.Item
|
||||
@@ -587,101 +595,104 @@ var file_controller_api_services_v1_scope_service_proto_rawDesc = []byte{
|
||||
0x29, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69,
|
||||
0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d,
|
||||
0x73, 0x22, 0x6e, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x49, 0x64, 0x12, 0x3d, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x73, 0x22, 0x9c, 0x01, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x49, 0x64, 0x12, 0x2c, 0x0a, 0x12, 0x73, 0x6b, 0x69, 0x70, 0x5f, 0x72, 0x6f, 0x6c, 0x65,
|
||||
0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52,
|
||||
0x10, 0x73, 0x6b, 0x69, 0x70, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x12, 0x3d, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x29, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69,
|
||||
0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d,
|
||||
0x22, 0x66, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52,
|
||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, 0x12, 0x3d, 0x0a, 0x04, 0x69, 0x74, 0x65,
|
||||
0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63,
|
||||
0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f,
|
||||
0x70, 0x65, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x22, 0xa0, 0x01, 0x0a, 0x12, 0x55, 0x70, 0x64,
|
||||
0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
|
||||
0x3d, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e,
|
||||
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72,
|
||||
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2e,
|
||||
0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x12, 0x3b,
|
||||
0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4d, 0x61, 0x73, 0x6b, 0x52,
|
||||
0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x61, 0x73, 0x6b, 0x22, 0x54, 0x0a, 0x13, 0x55,
|
||||
0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x12, 0x3d, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70,
|
||||
0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x04, 0x69, 0x74, 0x65,
|
||||
0x6d, 0x22, 0x66, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, 0x12, 0x3d, 0x0a, 0x04, 0x69, 0x74,
|
||||
0x65, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72,
|
||||
0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72,
|
||||
0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63,
|
||||
0x6f, 0x70, 0x65, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x22, 0xa0, 0x01, 0x0a, 0x12, 0x55, 0x70,
|
||||
0x64, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64,
|
||||
0x12, 0x3d, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29,
|
||||
0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
||||
0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73,
|
||||
0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x12,
|
||||
0x3b, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4d, 0x61, 0x73, 0x6b,
|
||||
0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x61, 0x73, 0x6b, 0x22, 0x54, 0x0a, 0x13,
|
||||
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x12, 0x3d, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x0b, 0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61,
|
||||
0x70, 0x69, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x2e, 0x73, 0x63, 0x6f,
|
||||
0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x04, 0x69, 0x74,
|
||||
0x65, 0x6d, 0x22, 0x24, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2f, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65,
|
||||
0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x18, 0x0a, 0x07, 0x65, 0x78, 0x69, 0x73, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08,
|
||||
0x52, 0x07, 0x65, 0x78, 0x69, 0x73, 0x74, 0x65, 0x64, 0x32, 0xe9, 0x06, 0x0a, 0x0c, 0x53, 0x63,
|
||||
0x6f, 0x70, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x9c, 0x01, 0x0a, 0x08, 0x47,
|
||||
0x65, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x73, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65,
|
||||
0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76,
|
||||
0x31, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x22, 0x35, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x12, 0x0f, 0x2f, 0x76, 0x31, 0x2f,
|
||||
0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x62, 0x04, 0x69, 0x74, 0x65,
|
||||
0x6d, 0x92, 0x41, 0x15, 0x12, 0x13, 0x47, 0x65, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x69, 0x6e,
|
||||
0x67, 0x6c, 0x65, 0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0xc5, 0x01, 0x0a, 0x0a, 0x4c, 0x69,
|
||||
0x73, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x12, 0x2d, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72,
|
||||
0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
|
||||
0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x73,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6d, 0x22, 0x24, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2f, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74,
|
||||
0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18,
|
||||
0x0a, 0x07, 0x65, 0x78, 0x69, 0x73, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52,
|
||||
0x07, 0x65, 0x78, 0x69, 0x73, 0x74, 0x65, 0x64, 0x32, 0xe9, 0x06, 0x0a, 0x0c, 0x53, 0x63, 0x6f,
|
||||
0x70, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x9c, 0x01, 0x0a, 0x08, 0x47, 0x65,
|
||||
0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73,
|
||||
0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72,
|
||||
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31,
|
||||
0x2e, 0x47, 0x65, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x22, 0x35, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x12, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x73,
|
||||
0x63, 0x6f, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x62, 0x04, 0x69, 0x74, 0x65, 0x6d,
|
||||
0x92, 0x41, 0x15, 0x12, 0x13, 0x47, 0x65, 0x74, 0x73, 0x20, 0x61, 0x20, 0x73, 0x69, 0x6e, 0x67,
|
||||
0x6c, 0x65, 0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0xc5, 0x01, 0x0a, 0x0a, 0x4c, 0x69, 0x73,
|
||||
0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x12, 0x2d, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x52,
|
||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x58, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0c, 0x12,
|
||||
0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x92, 0x41, 0x43, 0x12, 0x41,
|
||||
0x4c, 0x69, 0x73, 0x74, 0x73, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x73,
|
||||
0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x20, 0x6d,
|
||||
0x61, 0x6b, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x12, 0xa9, 0x01, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x12, 0x2e, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61,
|
||||
0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43,
|
||||
0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x1a, 0x2f, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61,
|
||||
0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43,
|
||||
0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x22, 0x39, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x22, 0x0a, 0x2f, 0x76, 0x31, 0x2f,
|
||||
0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x3a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x62, 0x04, 0x69, 0x74,
|
||||
0x65, 0x6d, 0x92, 0x41, 0x18, 0x12, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x73, 0x20, 0x61,
|
||||
0x20, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0xa7, 0x01,
|
||||
0x0a, 0x0b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x2e, 0x2e,
|
||||
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74,
|
||||
0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e,
|
||||
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74,
|
||||
0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x37,
|
||||
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1d, 0x32, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x63, 0x6f, 0x70,
|
||||
0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x3a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x62, 0x04, 0x69,
|
||||
0x74, 0x65, 0x6d, 0x92, 0x41, 0x11, 0x12, 0x0f, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x20,
|
||||
0x61, 0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x9b, 0x01, 0x0a, 0x0b, 0x44, 0x65, 0x6c, 0x65,
|
||||
0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x2e, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11,
|
||||
0x2a, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64,
|
||||
0x7d, 0x92, 0x41, 0x11, 0x12, 0x0f, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x73, 0x20, 0x61, 0x20,
|
||||
0x53, 0x63, 0x6f, 0x70, 0x65, 0x42, 0x4d, 0x5a, 0x4b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
|
||||
0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f,
|
||||
0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f,
|
||||
0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x3b, 0x73, 0x65, 0x72, 0x76,
|
||||
0x69, 0x63, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73,
|
||||
0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x58, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0c, 0x12, 0x0a,
|
||||
0x2f, 0x76, 0x31, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x92, 0x41, 0x43, 0x12, 0x41, 0x4c,
|
||||
0x69, 0x73, 0x74, 0x73, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x20,
|
||||
0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x20, 0x6d, 0x61,
|
||||
0x6b, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x68, 0x65, 0x20, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x12, 0xa9, 0x01, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x12, 0x2e, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70,
|
||||
0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72,
|
||||
0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x1a, 0x2f, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70,
|
||||
0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72,
|
||||
0x65, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x22, 0x39, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x22, 0x0a, 0x2f, 0x76, 0x31, 0x2f, 0x73,
|
||||
0x63, 0x6f, 0x70, 0x65, 0x73, 0x3a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x62, 0x04, 0x69, 0x74, 0x65,
|
||||
0x6d, 0x92, 0x41, 0x18, 0x12, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x73, 0x20, 0x61, 0x20,
|
||||
0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0xa7, 0x01, 0x0a,
|
||||
0x0b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x2e, 0x2e, 0x63,
|
||||
0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65,
|
||||
0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
|
||||
0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x63,
|
||||
0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65,
|
||||
0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
|
||||
0x53, 0x63, 0x6f, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x37, 0x82,
|
||||
0xd3, 0xe4, 0x93, 0x02, 0x1d, 0x32, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65,
|
||||
0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x3a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x62, 0x04, 0x69, 0x74,
|
||||
0x65, 0x6d, 0x92, 0x41, 0x11, 0x12, 0x0f, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x20, 0x61,
|
||||
0x20, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x9b, 0x01, 0x0a, 0x0b, 0x44, 0x65, 0x6c, 0x65, 0x74,
|
||||
0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x2e, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73,
|
||||
0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x6c, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73,
|
||||
0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x52,
|
||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, 0x2a,
|
||||
0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d,
|
||||
0x92, 0x41, 0x11, 0x12, 0x0f, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x73, 0x20, 0x61, 0x20, 0x53,
|
||||
0x63, 0x6f, 0x70, 0x65, 0x42, 0x4d, 0x5a, 0x4b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
|
||||
0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75,
|
||||
0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67,
|
||||
0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2f, 0x61, 0x70,
|
||||
0x69, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69,
|
||||
0x63, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
+19
-10
@@ -16,16 +16,17 @@ type Option func(*options)
|
||||
|
||||
// options = how options are represented
|
||||
type options struct {
|
||||
withPublicId string
|
||||
withName string
|
||||
withDescription string
|
||||
withGroupGrants bool
|
||||
withLimit int
|
||||
withAutoVivify bool
|
||||
withGrantScopeId string
|
||||
withSkipVetForWrite bool
|
||||
withDisassociate bool
|
||||
withRandomReader io.Reader
|
||||
withPublicId string
|
||||
withName string
|
||||
withDescription string
|
||||
withGroupGrants bool
|
||||
withLimit int
|
||||
withAutoVivify bool
|
||||
withGrantScopeId string
|
||||
withSkipVetForWrite bool
|
||||
withDisassociate bool
|
||||
withSkipRoleCreation bool
|
||||
withRandomReader io.Reader
|
||||
}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
@@ -110,6 +111,14 @@ func WithDisassociate(enable bool) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithSkipRoleCreation provides an option to disable the automatic creation of
|
||||
// a role when a new scope is created.
|
||||
func WithSkipRoleCreation(enable bool) Option {
|
||||
return func(o *options) {
|
||||
o.withSkipRoleCreation = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithRandomReader provides and option to specify a random reader.
|
||||
func WithRandomReader(reader io.Reader) Option {
|
||||
return func(o *options) {
|
||||
|
||||
@@ -86,8 +86,12 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
var roleMetadata oplog.Metadata
|
||||
var role *Role
|
||||
var roleRaw interface{}
|
||||
switch userId {
|
||||
case "", "u_anon", "u_auth", "u_recovery":
|
||||
switch {
|
||||
case userId == "",
|
||||
userId == "u_anon",
|
||||
userId == "u_auth",
|
||||
userId == "u_recovery",
|
||||
opts.withSkipRoleCreation:
|
||||
// TODO: Cause a log entry. The repo doesn't have a logger right now,
|
||||
// and ideally we will be using context to pass around log info scoped
|
||||
// to this request for grouped display in the server log. The only
|
||||
|
||||
@@ -23,6 +23,7 @@ func Test_Repository_Scope_Create(t *testing.T) {
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
repo := TestRepo(t, conn, wrapper)
|
||||
user := TestUser(t, repo, "global")
|
||||
|
||||
t.Run("valid-scope", func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
@@ -103,6 +104,31 @@ func Test_Repository_Scope_Create(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.Nil(p2)
|
||||
})
|
||||
for _, skipCreate := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("skipping-role-creation-%t", skipCreate), func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
id := testId(t)
|
||||
s, err := NewOrg(WithName(id))
|
||||
require.NoError(err)
|
||||
s, err = repo.CreateScope(context.Background(), s, user.GetPublicId(), WithSkipRoleCreation(skipCreate))
|
||||
require.NoError(err)
|
||||
require.NotNil(s)
|
||||
assert.NotEmpty(s.GetPublicId())
|
||||
assert.Equal(s.GetName(), id)
|
||||
|
||||
foundScope, err := repo.LookupScope(context.Background(), s.PublicId)
|
||||
require.NoError(err)
|
||||
assert.True(proto.Equal(foundScope, s))
|
||||
|
||||
foundRoles, err := repo.ListRoles(context.Background(), foundScope.GetPublicId())
|
||||
require.NoError(err)
|
||||
numFound := 1
|
||||
if skipCreate {
|
||||
numFound = 0
|
||||
}
|
||||
assert.Len(foundRoles, numFound)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Repository_Scope_Update(t *testing.T) {
|
||||
|
||||
@@ -106,7 +106,8 @@ message ListScopesResponse {
|
||||
|
||||
message CreateScopeRequest {
|
||||
string scope_id = 1;
|
||||
resources.scopes.v1.Scope item = 2;
|
||||
bool skip_role_creation = 2;
|
||||
resources.scopes.v1.Scope item = 3;
|
||||
}
|
||||
|
||||
message CreateScopeResponse {
|
||||
|
||||
@@ -106,7 +106,8 @@ func (s Service) CreateScope(ctx context.Context, req *pbs.CreateScopeRequest) (
|
||||
if err := validateCreateRequest(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p, err := s.createInRepo(ctx, authResults, req.GetItem())
|
||||
|
||||
p, err := s.createInRepo(ctx, authResults, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -162,7 +163,8 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.Scope, error)
|
||||
return ToProto(p), nil
|
||||
}
|
||||
|
||||
func (s Service) createInRepo(ctx context.Context, authResults auth.VerifyResults, item *pb.Scope) (*pb.Scope, error) {
|
||||
func (s Service) createInRepo(ctx context.Context, authResults auth.VerifyResults, req *pbs.CreateScopeRequest) (*pb.Scope, error) {
|
||||
item := req.GetItem()
|
||||
var opts []iam.Option
|
||||
if item.GetName() != nil {
|
||||
opts = append(opts, iam.WithName(item.GetName().GetValue()))
|
||||
@@ -170,6 +172,7 @@ func (s Service) createInRepo(ctx context.Context, authResults auth.VerifyResult
|
||||
if item.GetDescription() != nil {
|
||||
opts = append(opts, iam.WithDescription(item.GetDescription().GetValue()))
|
||||
}
|
||||
opts = append(opts, iam.WithSkipRoleCreation(req.GetSkipRoleCreation()))
|
||||
|
||||
parentScope := authResults.Scope
|
||||
var iamScope *iam.Scope
|
||||
@@ -187,7 +190,7 @@ func (s Service) createInRepo(ctx context.Context, authResults auth.VerifyResult
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := repo.CreateScope(ctx, iamScope, authResults.UserId)
|
||||
out, err := repo.CreateScope(ctx, iamScope, authResults.UserId, opts...)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Unable to create scope: %v.", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user