Pathing updated to support new and old styles (#323)
This commit is contained in:
1 parent
2a98432143
commit
37e56ab46b
85 files changed
+11689
-4462
No files matched your search
@@ -48,7 +48,6 @@ func (c *Client) Create(ctx context.Context, authMethodId string, opt ...Option)
|
||||
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 {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/accounts"
|
||||
"github.com/hashicorp/boundary/api/authmethods"
|
||||
"github.com/hashicorp/boundary/internal/auth/password"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller"
|
||||
@@ -16,45 +17,45 @@ import (
|
||||
|
||||
func TestAccounts_List(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "ampw_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultLoginName: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
amClient := authmethods.NewClient(client)
|
||||
am, apiErr, err := amClient.Create(tc.Context(), "password")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(am)
|
||||
|
||||
accountClient := accounts.NewClient(client)
|
||||
|
||||
expected, apiErr, err := accountClient.List(tc.Context(), amId)
|
||||
expected, apiErr, err := accountClient.List(tc.Context(), am.Id)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
// A default account is created when a test controller is started.
|
||||
assert.Len(expected, 1)
|
||||
assert.Len(expected, 0)
|
||||
|
||||
expected = append(expected, &accounts.Account{Attributes: map[string]interface{}{"login_name": "loginname1"}})
|
||||
expected = append(expected, &accounts.Account{Attributes: map[string]interface{}{"login_name": "loginname0"}})
|
||||
|
||||
expected[1], apiErr, err = accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName(expected[1].Attributes["login_name"].(string)))
|
||||
expected[0], apiErr, err = accountClient.Create(tc.Context(), am.Id, accounts.WithPasswordAccountLoginName(expected[0].Attributes["login_name"].(string)))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
ul, apiErr, err := accountClient.List(tc.Context(), amId)
|
||||
ul, apiErr, err := accountClient.List(tc.Context(), am.Id)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSlice(expected[:2]), comparableSlice(ul))
|
||||
assert.ElementsMatch(comparableSlice(expected[:1]), comparableSlice(ul))
|
||||
|
||||
for i := 2; i < 10; i++ {
|
||||
newAcct, apiErr, err := accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName(fmt.Sprintf("loginname%d", i)))
|
||||
for i := 1; i < 10; i++ {
|
||||
newAcct, apiErr, err := accountClient.Create(tc.Context(), am.Id, accounts.WithPasswordAccountLoginName(fmt.Sprintf("loginname%d", i)))
|
||||
expected = append(expected, newAcct)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
}
|
||||
ul, apiErr, err = accountClient.List(tc.Context(), amId)
|
||||
ul, apiErr, err = accountClient.List(tc.Context(), am.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSlice(expected), comparableSlice(ul))
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
type AuthMethod struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ScopeId string `json:"scope_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -49,7 +50,6 @@ func (c *Client) Create(ctx context.Context, resourceType string, opt ...Option)
|
||||
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 {
|
||||
|
||||
@@ -5,9 +5,11 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api/accounts"
|
||||
"github.com/hashicorp/boundary/api/authmethods"
|
||||
"github.com/hashicorp/boundary/api/authtokens"
|
||||
"github.com/hashicorp/boundary/internal/authtoken"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -15,16 +17,26 @@ import (
|
||||
|
||||
func TestAuthTokens_List(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "ampw_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultLoginName: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
amClient := authmethods.NewClient(client)
|
||||
am, apiErr, err := amClient.Create(tc.Context(), "password")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(am)
|
||||
amId := am.Id
|
||||
|
||||
acctClient := accounts.NewClient(client)
|
||||
acct, apiErr, err := acctClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName("user"), accounts.WithPasswordAccountPassword("passpass"))
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(acct)
|
||||
|
||||
tokens := authtokens.NewClient(client)
|
||||
methods := authmethods.NewClient(client)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
type AuthToken struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ScopeId string `json:"scope_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
UserId string `json:"user_id,omitempty"`
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
type Group struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ScopeId string `json:"scope_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -44,7 +45,6 @@ func (c *Client) Create(ctx context.Context, opt ...Option) (*Group, *api.Error,
|
||||
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 {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
type HostCatalog struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ScopeId string `json:"scope_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -49,7 +50,6 @@ func (c *Client) Create(ctx context.Context, resourceType string, opt ...Option)
|
||||
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 {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
type Host struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
HostCatalogId string `json:"host_catalog_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -23,7 +24,6 @@ type Host struct {
|
||||
UpdatedTime time.Time `json:"updated_time,omitempty"`
|
||||
Version uint32 `json:"version,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
HostCatalogId string `json:"host_catalog_id,omitempty"`
|
||||
HostSetIds []string `json:"host_set_ids,omitempty"`
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
@@ -49,7 +49,6 @@ func (c *Client) Create(ctx context.Context, hostCatalogId string, opt ...Option
|
||||
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 {
|
||||
|
||||
@@ -49,7 +49,6 @@ func (c *Client) Create(ctx context.Context, hostCatalogId string, opt ...Option
|
||||
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 {
|
||||
|
||||
@@ -570,14 +570,14 @@ func (c *Client) Create(ctx context.Context, {{ if .TypeOnCreate }} resourceType
|
||||
} else {
|
||||
opts.postMap["type"] = resourceType
|
||||
}{{ end }}
|
||||
{{ if ( eq .CollectionPath "\"scopes\"" ) }}
|
||||
opts.postMap["scope_id"] = scopeId
|
||||
{{ end }}
|
||||
|
||||
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\"" ) }}
|
||||
opts.queryMap["scope_id"] = scopeId
|
||||
{{ end }}
|
||||
if len(opts.queryMap) > 0 {
|
||||
q := url.Values{}
|
||||
for k, v := range opts.queryMap {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
type Role struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ScopeId string `json:"scope_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -47,7 +48,6 @@ func (c *Client) Create(ctx context.Context, opt ...Option) (*Role, *api.Error,
|
||||
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 {
|
||||
|
||||
@@ -52,6 +52,7 @@ func comparableSlice(in []*scopes.Scope) []scopes.Scope {
|
||||
for _, i := range in {
|
||||
p := scopes.Scope{
|
||||
Id: i.Id,
|
||||
ScopeId: i.ScopeId,
|
||||
Name: i.Name,
|
||||
Description: i.Description,
|
||||
CreatedTime: i.CreatedTime,
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
type Scope struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ScopeId string `json:"scope_id,omitempty"`
|
||||
Scope *ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -40,13 +41,12 @@ func (c *Client) Create(ctx context.Context, scopeId string, opt ...Option) (*Sc
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
opts.postMap["scope_id"] = scopeId
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
opts.queryMap["scope_id"] = scopeId
|
||||
|
||||
if len(opts.queryMap) > 0 {
|
||||
q := url.Values{}
|
||||
for k, v := range opts.queryMap {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
type User struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ScopeId string `json:"scope_id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
@@ -42,7 +43,6 @@ func (c *Client) Create(ctx context.Context, opt ...Option) (*User, *api.Error,
|
||||
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 {
|
||||
|
||||
Reference in new issue
Block a user