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

* Initial work on scope creation skipping

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

No files matched your search

+47 -6
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -43,11 +44,19 @@ func (c *AccountsClient) Create(ctx context.Context, authMethodId string, opt ..
return nil, nil, fmt.Errorf("nil client")
}
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("auth-methods/%s/accounts", authMethodId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("auth-methods/%s/accounts", authMethodId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -77,13 +86,21 @@ func (c *AccountsClient) Read(ctx context.Context, authMethodId string, accountI
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -130,13 +147,21 @@ func (c *AccountsClient) Update(ctx context.Context, authMethodId string, accoun
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -166,13 +191,21 @@ func (c *AccountsClient) Delete(ctx context.Context, authMethodId string, accoun
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("auth-methods/%s/accounts/%s", authMethodId, accountId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -201,13 +234,21 @@ func (c *AccountsClient) List(ctx context.Context, authMethodId string, opt ...O
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-methods/%s/accounts", authMethodId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
+48 -7
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"time"
"github.com/kr/pretty"
@@ -41,14 +42,22 @@ func (c *AuthMethodsClient) Create(ctx context.Context, resourceType string, opt
if resourceType == "" {
return nil, nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.valueMap["type"] = resourceType
opts.postMap["type"] = resourceType
}
req, err := c.client.NewRequest(ctx, "POST", "auth-methods", opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "POST", "auth-methods", opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Create call: %w", err)
@@ -74,13 +83,21 @@ func (c *AuthMethodsClient) Read(ctx context.Context, authMethodId string, opt .
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("auth-methods/%s", authMethodId), nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Read request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Read call: %w", err)
@@ -124,13 +141,21 @@ func (c *AuthMethodsClient) Update(ctx context.Context, authMethodId string, ver
version = existingTarget.Version
}
opts.valueMap["version"] = version
opts.postMap["version"] = version
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s", authMethodId), opts.valueMap, apiOpts...)
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("auth-methods/%s", authMethodId), opts.postMap, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
@@ -156,13 +181,21 @@ func (c *AuthMethodsClient) Delete(ctx context.Context, authMethodId string, opt
return false, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("auth-methods/%s", authMethodId), nil, apiOpts...)
if err != nil {
return false, nil, fmt.Errorf("error creating Delete request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
@@ -187,13 +220,21 @@ func (c *AuthMethodsClient) List(ctx context.Context, opt ...Option) ([]*AuthMet
return nil, nil, fmt.Errorf("nil client")
}
_, apiOpts := getOpts(opt...)
opts, apiOpts := getOpts(opt...)
req, err := c.client.NewRequest(ctx, "GET", "auth-methods", nil, apiOpts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating List request: %w", err)
}
if len(opts.queryMap) > 0 {
q := url.Values{}
for k, v := range opts.queryMap {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
}
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("error performing client request during List call: %w", err)
+26 -24
View File
@@ -14,14 +14,16 @@ import (
type Option func(*options)
type options struct {
valueMap map[string]interface{}
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
valueMap: make(map[string]interface{}),
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
@@ -55,132 +57,132 @@ func WithAutomaticVersioning() Option {
func WithAttributes(inAttributes map[string]interface{}) Option {
return func(o *options) {
o.valueMap["attributes"] = inAttributes
o.postMap["attributes"] = inAttributes
}
}
func DefaultAttributes() Option {
return func(o *options) {
o.valueMap["attributes"] = nil
o.postMap["attributes"] = nil
}
}
func WithDescription(inDescription string) Option {
return func(o *options) {
o.valueMap["description"] = inDescription
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.valueMap["description"] = nil
o.postMap["description"] = nil
}
}
func WithPasswordAccountLoginName(inLoginName string) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["login_name"] = inLoginName
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAccountLoginName() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["login_name"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func WithPasswordAuthMethodMinLoginNameLength(inMinLoginNameLength uint32) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_login_name_length"] = inMinLoginNameLength
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAuthMethodMinLoginNameLength() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_login_name_length"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func WithPasswordAuthMethodMinPasswordLength(inMinPasswordLength uint32) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_password_length"] = inMinPasswordLength
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAuthMethodMinPasswordLength() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["min_password_length"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func WithName(inName string) Option {
return func(o *options) {
o.valueMap["name"] = inName
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.valueMap["name"] = nil
o.postMap["name"] = nil
}
}
func WithPasswordAccountPassword(inPassword string) Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["password"] = inPassword
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}
func DefaultPasswordAccountPassword() Option {
return func(o *options) {
raw, ok := o.valueMap["attributes"]
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["password"] = nil
o.valueMap["attributes"] = val
o.postMap["attributes"] = val
}
}