Separate accounts/host catalogs/host sets into their own packages (#311)
This commit is contained in:
1 parent
936c970635
commit
17ecb6f2ce
64 files changed
+2298
-2265
No files matched your search
@@ -1,5 +1,5 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package authmethods
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -27,15 +27,15 @@ type Account struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type AccountsClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewAccountsClient(c *api.Client) *AccountsClient {
|
||||
return &AccountsClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *AccountsClient) Create(ctx context.Context, authMethodId string, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, authMethodId string, opt ...Option) (*Account, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into Create request")
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (c *AccountsClient) Create(ctx context.Context, authMethodId string, opt ..
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AccountsClient) Read(ctx context.Context, authMethodId string, accountId string, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, authMethodId string, accountId string, opt ...Option) (*Account, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into Read request")
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (c *AccountsClient) Read(ctx context.Context, authMethodId string, accountI
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AccountsClient) Update(ctx context.Context, authMethodId string, accountId string, version uint32, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, authMethodId string, accountId string, version uint32, opt ...Option) (*Account, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into Update request")
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func (c *AccountsClient) Update(ctx context.Context, authMethodId string, accoun
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AccountsClient) Delete(ctx context.Context, authMethodId string, accountId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, authMethodId string, accountId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return false, nil, fmt.Errorf("empty authMethodId value passed into Delete request")
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func (c *AccountsClient) Delete(ctx context.Context, authMethodId string, accoun
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AccountsClient) List(ctx context.Context, authMethodId string, opt ...Option) ([]*Account, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, authMethodId string, opt ...Option) ([]*Account, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into List request")
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package authmethods_test
|
||||
package accounts_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/authmethods"
|
||||
"github.com/hashicorp/boundary/api/accounts"
|
||||
"github.com/hashicorp/boundary/internal/auth/password"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller"
|
||||
@@ -29,7 +29,7 @@ func TestAccounts_List(t *testing.T) {
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
|
||||
accountClient := authmethods.NewAccountsClient(client)
|
||||
accountClient := accounts.NewClient(client)
|
||||
|
||||
expected, apiErr, err := accountClient.List(tc.Context(), amId)
|
||||
assert.NoError(err)
|
||||
@@ -37,9 +37,9 @@ func TestAccounts_List(t *testing.T) {
|
||||
// A default account is created when a test controller is started.
|
||||
assert.Len(expected, 1)
|
||||
|
||||
expected = append(expected, &authmethods.Account{Attributes: map[string]interface{}{"login_name": "loginname1"}})
|
||||
expected = append(expected, &accounts.Account{Attributes: map[string]interface{}{"login_name": "loginname1"}})
|
||||
|
||||
expected[1], apiErr, err = accountClient.Create(tc.Context(), amId, authmethods.WithPasswordAccountLoginName(expected[1].Attributes["login_name"].(string)))
|
||||
expected[1], apiErr, err = accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName(expected[1].Attributes["login_name"].(string)))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestAccounts_List(t *testing.T) {
|
||||
assert.ElementsMatch(comparableSlice(expected[:2]), comparableSlice(ul))
|
||||
|
||||
for i := 2; i < 10; i++ {
|
||||
newAcct, apiErr, err := accountClient.Create(tc.Context(), amId, authmethods.WithPasswordAccountLoginName(fmt.Sprintf("loginname%d", i)))
|
||||
newAcct, apiErr, err := accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName(fmt.Sprintf("loginname%d", i)))
|
||||
expected = append(expected, newAcct)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
@@ -60,10 +60,10 @@ func TestAccounts_List(t *testing.T) {
|
||||
assert.ElementsMatch(comparableSlice(expected), comparableSlice(ul))
|
||||
}
|
||||
|
||||
func comparableSlice(in []*authmethods.Account) []authmethods.Account {
|
||||
var filtered []authmethods.Account
|
||||
func comparableSlice(in []*accounts.Account) []accounts.Account {
|
||||
var filtered []accounts.Account
|
||||
for _, i := range in {
|
||||
p := authmethods.Account{
|
||||
p := accounts.Account{
|
||||
Id: i.Id,
|
||||
Name: i.Name,
|
||||
Description: i.Description,
|
||||
@@ -91,9 +91,9 @@ func TestAccount_Crud(t *testing.T) {
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
|
||||
accountClient := authmethods.NewAccountsClient(client)
|
||||
accountClient := accounts.NewClient(client)
|
||||
|
||||
checkAccount := func(step string, u *authmethods.Account, apiErr *api.Error, err error, wantedName string, wantedVersion uint32) {
|
||||
checkAccount := func(step string, u *accounts.Account, apiErr *api.Error, err error, wantedName string, wantedVersion uint32) {
|
||||
assert.NoError(err, step)
|
||||
if !assert.Nil(apiErr, step) && apiErr.Message != "" {
|
||||
t.Errorf("ApiError message: %q", apiErr.Message)
|
||||
@@ -107,16 +107,16 @@ func TestAccount_Crud(t *testing.T) {
|
||||
assert.EqualValues(wantedVersion, u.Version)
|
||||
}
|
||||
|
||||
u, apiErr, err := accountClient.Create(tc.Context(), amId, authmethods.WithName("foo"), authmethods.WithPasswordAccountLoginName("loginname"))
|
||||
u, apiErr, err := accountClient.Create(tc.Context(), amId, accounts.WithName("foo"), accounts.WithPasswordAccountLoginName("loginname"))
|
||||
checkAccount("create", u, apiErr, err, "foo", 1)
|
||||
|
||||
u, apiErr, err = accountClient.Read(tc.Context(), amId, u.Id)
|
||||
checkAccount("read", u, apiErr, err, "foo", 1)
|
||||
|
||||
u, apiErr, err = accountClient.Update(tc.Context(), amId, u.Id, u.Version, authmethods.WithName("bar"))
|
||||
u, apiErr, err = accountClient.Update(tc.Context(), amId, u.Id, u.Version, accounts.WithName("bar"))
|
||||
checkAccount("update", u, apiErr, err, "bar", 2)
|
||||
|
||||
u, apiErr, err = accountClient.Update(tc.Context(), amId, u.Id, u.Version, authmethods.DefaultName())
|
||||
u, apiErr, err = accountClient.Update(tc.Context(), amId, u.Id, u.Version, accounts.DefaultName())
|
||||
checkAccount("update", u, apiErr, err, "", 3)
|
||||
|
||||
existed, _, err := accountClient.Delete(tc.Context(), amId, u.Id)
|
||||
@@ -145,7 +145,7 @@ func TestAccount_CustomMethods(t *testing.T) {
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
|
||||
accountClient := authmethods.NewAccountsClient(client)
|
||||
accountClient := accounts.NewClient(client)
|
||||
|
||||
al, apiErr, err := accountClient.List(tc.Context(), amId)
|
||||
require.NoError(err)
|
||||
@@ -182,15 +182,15 @@ func TestAccount_Errors(t *testing.T) {
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
|
||||
accountClient := authmethods.NewAccountsClient(client)
|
||||
accountClient := accounts.NewClient(client)
|
||||
|
||||
u, apiErr, err := accountClient.Create(tc.Context(), amId, authmethods.WithPasswordAccountLoginName("first"))
|
||||
u, apiErr, err := accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName("first"))
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(u)
|
||||
|
||||
// Create another resource with the same name.
|
||||
_, apiErr, err = accountClient.Create(tc.Context(), amId, authmethods.WithPasswordAccountLoginName("first"))
|
||||
_, apiErr, err = accountClient.Create(tc.Context(), amId, accounts.WithPasswordAccountLoginName("first"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package authmethods
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/kr/pretty"
|
||||
)
|
||||
|
||||
func (c *AccountsClient) ChangePassword(ctx context.Context, authMethodId, accountId, oldPassword, newPassword string, version uint32, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *Client) ChangePassword(ctx context.Context, authMethodId, accountId, oldPassword, newPassword string, version uint32, opt ...Option) (*Account, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into ChangePassword request")
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/api"
|
||||
)
|
||||
|
||||
// Option is a func that sets optional attributes for a call. This does not need
|
||||
// to be used directly, but instead option arguments are built from the
|
||||
// functions in this package. WithX options set a value to that given in the
|
||||
// argument; DefaultX options indicate that the value should be set to its
|
||||
// default. When an API call is made options are processed in ther order they
|
||||
// appear in the function call, so for a given argument X, a succession of WithX
|
||||
// or DefaultX calls will result in the last call taking effect.
|
||||
type Option func(*options)
|
||||
|
||||
type options struct {
|
||||
postMap map[string]interface{}
|
||||
queryMap map[string]string
|
||||
withScopeId string
|
||||
withAutomaticVersioning bool
|
||||
}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
return options{
|
||||
postMap: make(map[string]interface{}),
|
||||
queryMap: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func getOpts(opt ...Option) (options, []api.Option) {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
o(&opts)
|
||||
}
|
||||
var apiOpts []api.Option
|
||||
if opts.withScopeId != "" {
|
||||
apiOpts = append(apiOpts, api.WithScopeId(opts.withScopeId))
|
||||
}
|
||||
return opts, apiOpts
|
||||
}
|
||||
|
||||
func WithScopeId(id string) Option {
|
||||
return func(o *options) {
|
||||
o.withScopeId = id
|
||||
}
|
||||
}
|
||||
|
||||
// If set, and if the version is zero during an update, the API will perform a
|
||||
// fetch to get the current version of the resource and populate it during the
|
||||
// update call. This is convenient but opens up the possibility for subtle
|
||||
// order-of-modification issues, so use carefully.
|
||||
func WithAutomaticVersioning() Option {
|
||||
return func(o *options) {
|
||||
o.withAutomaticVersioning = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithAttributes(inAttributes map[string]interface{}) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["attributes"] = inAttributes
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultAttributes() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["attributes"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithDescription(inDescription string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["description"] = inDescription
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultDescription() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["description"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithPasswordAccountLoginName(inLoginName string) Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["login_name"] = inLoginName
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultPasswordAccountLoginName() Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["login_name"] = nil
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
|
||||
func WithName(inName string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["name"] = inName
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultName() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["name"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithPasswordAccountPassword(inPassword string) Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["password"] = inPassword
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultPasswordAccountPassword() Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["password"] = nil
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package authmethods
|
||||
package accounts
|
||||
|
||||
type PasswordAccountAttributes struct {
|
||||
LoginName string `json:"login_name,omitempty"`
|
||||
@@ -1,4 +1,4 @@
|
||||
package authmethods
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/kr/pretty"
|
||||
)
|
||||
|
||||
func (c *AccountsClient) SetPassword(ctx context.Context, authMethodId, accountId, password string, version uint32, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *Client) SetPassword(ctx context.Context, authMethodId, accountId, password string, version uint32, opt ...Option) (*Account, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into SetPassword request")
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
// TODO: This will need to be changed when we add Auth Method API to boundary. We'll also need a better
|
||||
// way to handle different auth method types.
|
||||
func (c *AuthMethodsClient) Authenticate(ctx context.Context, authMethodId, loginName, password string, opt ...Option) (*authtokens.AuthToken, *api.Error, error) {
|
||||
func (c *Client) Authenticate(ctx context.Context, authMethodId, loginName, password string, opt ...Option) (*authtokens.AuthToken, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client in Authenticate request")
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestAuthenticate(t *testing.T) {
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
methods := authmethods.NewAuthMethodsClient(client)
|
||||
methods := authmethods.NewClient(client)
|
||||
|
||||
tok, apiErr, err := methods.Authenticate(tc.Context(), amId, "user", "passpass")
|
||||
require.NoError(err)
|
||||
|
||||
@@ -26,15 +26,15 @@ type AuthMethod struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type AuthMethodsClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewAuthMethodsClient(c *api.Client) *AuthMethodsClient {
|
||||
return &AuthMethodsClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *AuthMethodsClient) Create(ctx context.Context, resourceType string, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, resourceType string, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
@@ -74,7 +74,7 @@ func (c *AuthMethodsClient) Create(ctx context.Context, resourceType string, opt
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AuthMethodsClient) Read(ctx context.Context, authMethodId string, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, authMethodId string, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into Read request")
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (c *AuthMethodsClient) Read(ctx context.Context, authMethodId string, opt .
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AuthMethodsClient) Update(ctx context.Context, authMethodId string, version uint32, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, authMethodId string, version uint32, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authMethodId value passed into Update request")
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (c *AuthMethodsClient) Update(ctx context.Context, authMethodId string, ver
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AuthMethodsClient) Delete(ctx context.Context, authMethodId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, authMethodId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if authMethodId == "" {
|
||||
return false, nil, fmt.Errorf("empty authMethodId value passed into Delete request")
|
||||
}
|
||||
@@ -215,7 +215,7 @@ func (c *AuthMethodsClient) Delete(ctx context.Context, authMethodId string, opt
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AuthMethodsClient) List(ctx context.Context, opt ...Option) ([]*AuthMethod, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, opt ...Option) ([]*AuthMethod, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
@@ -79,30 +79,6 @@ func DefaultDescription() Option {
|
||||
}
|
||||
}
|
||||
|
||||
func WithPasswordAccountLoginName(inLoginName string) Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["login_name"] = inLoginName
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultPasswordAccountLoginName() Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["login_name"] = nil
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
|
||||
func WithPasswordAuthMethodMinLoginNameLength(inMinLoginNameLength uint32) Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
@@ -162,27 +138,3 @@ func DefaultName() Option {
|
||||
o.postMap["name"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithPasswordAccountPassword(inPassword string) Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["password"] = inPassword
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultPasswordAccountPassword() Option {
|
||||
return func(o *options) {
|
||||
raw, ok := o.postMap["attributes"]
|
||||
if !ok {
|
||||
raw = interface{}(map[string]interface{}{})
|
||||
}
|
||||
val := raw.(map[string]interface{})
|
||||
val["password"] = nil
|
||||
o.postMap["attributes"] = val
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,8 @@ func TestAuthTokens_List(t *testing.T) {
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
tokens := authtokens.NewAuthTokensClient(client)
|
||||
methods := authmethods.NewAuthMethodsClient(client)
|
||||
tokens := authtokens.NewClient(client)
|
||||
methods := authmethods.NewClient(client)
|
||||
|
||||
atl, apiErr, err := tokens.List(tc.Context())
|
||||
require.NoError(err)
|
||||
@@ -92,8 +92,8 @@ func TestAuthToken_Crud(t *testing.T) {
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
tokens := authtokens.NewAuthTokensClient(client)
|
||||
methods := authmethods.NewAuthMethodsClient(client)
|
||||
tokens := authtokens.NewClient(client)
|
||||
methods := authmethods.NewClient(client)
|
||||
|
||||
want, apiErr, err := methods.Authenticate(tc.Context(), amId, "user", "passpass")
|
||||
require.NoError(err)
|
||||
@@ -127,7 +127,7 @@ func TestAuthToken_Errors(t *testing.T) {
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
tokens := authtokens.NewAuthTokensClient(client)
|
||||
tokens := authtokens.NewClient(client)
|
||||
|
||||
_, apiErr, err := tokens.Read(tc.Context(), authtoken.AuthTokenPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
|
||||
@@ -23,15 +23,15 @@ type AuthToken struct {
|
||||
ExpirationTime time.Time `json:"expiration_time,omitempty"`
|
||||
}
|
||||
|
||||
type AuthTokensClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewAuthTokensClient(c *api.Client) *AuthTokensClient {
|
||||
return &AuthTokensClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *AuthTokensClient) Read(ctx context.Context, authTokenId string, opt ...Option) (*AuthToken, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, authTokenId string, opt ...Option) (*AuthToken, *api.Error, error) {
|
||||
if authTokenId == "" {
|
||||
return nil, nil, fmt.Errorf("empty authTokenId value passed into Read request")
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (c *AuthTokensClient) Read(ctx context.Context, authTokenId string, opt ...
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AuthTokensClient) Delete(ctx context.Context, authTokenId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, authTokenId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if authTokenId == "" {
|
||||
return false, nil, fmt.Errorf("empty authTokenId value passed into Delete request")
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (c *AuthTokensClient) Delete(ctx context.Context, authTokenId string, opt .
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *AuthTokensClient) List(ctx context.Context, opt ...Option) ([]*AuthToken, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, opt ...Option) ([]*AuthToken, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
+11
-11
@@ -26,15 +26,15 @@ type Group struct {
|
||||
Members []*Member `json:"members,omitempty"`
|
||||
}
|
||||
|
||||
type GroupsClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewGroupsClient(c *api.Client) *GroupsClient {
|
||||
return &GroupsClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *GroupsClient) Create(ctx context.Context, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, opt ...Option) (*Group, *api.Error, error) {
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
@@ -69,7 +69,7 @@ func (c *GroupsClient) Create(ctx context.Context, opt ...Option) (*Group, *api.
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *GroupsClient) Read(ctx context.Context, groupId string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, groupId string, opt ...Option) (*Group, *api.Error, error) {
|
||||
if groupId == "" {
|
||||
return nil, nil, fmt.Errorf("empty groupId value passed into Read request")
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func (c *GroupsClient) Read(ctx context.Context, groupId string, opt ...Option)
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *GroupsClient) Update(ctx context.Context, groupId string, version uint32, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, groupId string, version uint32, opt ...Option) (*Group, *api.Error, error) {
|
||||
if groupId == "" {
|
||||
return nil, nil, fmt.Errorf("empty groupId value passed into Update request")
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (c *GroupsClient) Update(ctx context.Context, groupId string, version uint3
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *GroupsClient) Delete(ctx context.Context, groupId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, groupId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if groupId == "" {
|
||||
return false, nil, fmt.Errorf("empty groupId value passed into Delete request")
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (c *GroupsClient) Delete(ctx context.Context, groupId string, opt ...Option
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *GroupsClient) List(ctx context.Context, opt ...Option) ([]*Group, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, opt ...Option) ([]*Group, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func (c *GroupsClient) List(ctx context.Context, opt ...Option) ([]*Group, *api.
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *GroupsClient) AddMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *Client) AddMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
if groupId == "" {
|
||||
return nil, nil, fmt.Errorf("empty groupId value passed into AddMembers request")
|
||||
}
|
||||
@@ -311,7 +311,7 @@ func (c *GroupsClient) AddMembers(ctx context.Context, groupId string, version u
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *GroupsClient) SetMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *Client) SetMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
if groupId == "" {
|
||||
return nil, nil, fmt.Errorf("empty groupId value passed into SetMembers request")
|
||||
}
|
||||
@@ -376,7 +376,7 @@ func (c *GroupsClient) SetMembers(ctx context.Context, groupId string, version u
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *GroupsClient) RemoveMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *Client) RemoveMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
if groupId == "" {
|
||||
return nil, nil, fmt.Errorf("empty groupId value passed into RemoveMembers request")
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestGroup_List(t *testing.T) {
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
grps := groups.NewGroupsClient(tt.scopeClient)
|
||||
grps := groups.NewClient(tt.scopeClient)
|
||||
pl, apiErr, err := grps.List(tc.Context())
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
@@ -133,17 +133,17 @@ func TestGroup_Crud(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
user1, apiErr, err := users.NewUsersClient(client).Create(tc.Context())
|
||||
user1, apiErr, err := users.NewClient(client).Create(tc.Context())
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
|
||||
user2, apiErr, err := users.NewUsersClient(client).Create(tc.Context())
|
||||
user2, apiErr, err := users.NewClient(client).Create(tc.Context())
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
groupsClient := groups.NewGroupsClient(tt.scopeClient)
|
||||
groupsClient := groups.NewClient(tt.scopeClient)
|
||||
g, apiErr, err := groupsClient.Create(tc.Context(), groups.WithName("foo"))
|
||||
checkGroup("create", g, apiErr, err, "foo", 1, nil)
|
||||
|
||||
@@ -209,7 +209,7 @@ func TestGroup_Errors(t *testing.T) {
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
groupClient := groups.NewGroupsClient(tt.scopeClient)
|
||||
groupClient := groups.NewClient(tt.scopeClient)
|
||||
|
||||
g, apiErr, err := groupClient.Create(tc.Context(), groups.WithName("first"))
|
||||
require.NoError(err)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package hosts
|
||||
package hostcatalogs
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -26,15 +26,15 @@ type HostCatalog struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type HostCatalogsClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewHostCatalogsClient(c *api.Client) *HostCatalogsClient {
|
||||
return &HostCatalogsClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *HostCatalogsClient) Create(ctx context.Context, resourceType string, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, resourceType string, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
@@ -74,7 +74,7 @@ func (c *HostCatalogsClient) Create(ctx context.Context, resourceType string, op
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostCatalogsClient) Read(ctx context.Context, hostCatalogId string, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, hostCatalogId string, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Read request")
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (c *HostCatalogsClient) Read(ctx context.Context, hostCatalogId string, opt
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostCatalogsClient) Update(ctx context.Context, hostCatalogId string, version uint32, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, hostCatalogId string, version uint32, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Update request")
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (c *HostCatalogsClient) Update(ctx context.Context, hostCatalogId string, v
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostCatalogsClient) Delete(ctx context.Context, hostCatalogId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, hostCatalogId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return false, nil, fmt.Errorf("empty hostCatalogId value passed into Delete request")
|
||||
}
|
||||
@@ -215,7 +215,7 @@ func (c *HostCatalogsClient) Delete(ctx context.Context, hostCatalogId string, o
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostCatalogsClient) List(ctx context.Context, opt ...Option) ([]*HostCatalog, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, opt ...Option) ([]*HostCatalog, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package hosts_test
|
||||
package hostcatalogs_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/internal/host/static"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller"
|
||||
@@ -28,19 +28,19 @@ func TestCatalog_List(t *testing.T) {
|
||||
client := tc.Client()
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
catalogClient := hosts.NewHostCatalogsClient(client)
|
||||
catalogClient := hostcatalogs.NewClient(client)
|
||||
|
||||
ul, apiErr, err := catalogClient.List(tc.Context())
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.Empty(ul)
|
||||
|
||||
var expected []*hosts.HostCatalog
|
||||
var expected []*hostcatalogs.HostCatalog
|
||||
for i := 0; i < 10; i++ {
|
||||
expected = append(expected, &hosts.HostCatalog{Name: fmt.Sprint(i)})
|
||||
expected = append(expected, &hostcatalogs.HostCatalog{Name: fmt.Sprint(i)})
|
||||
}
|
||||
|
||||
expected[0], apiErr, err = catalogClient.Create(tc.Context(), "static", hosts.WithName(expected[0].Name))
|
||||
expected[0], apiErr, err = catalogClient.Create(tc.Context(), "static", hostcatalogs.WithName(expected[0].Name))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestCatalog_List(t *testing.T) {
|
||||
assert.ElementsMatch(comparableCatalogSlice(expected[:1]), comparableCatalogSlice(ul))
|
||||
|
||||
for i := 1; i < 10; i++ {
|
||||
expected[i], apiErr, err = catalogClient.Create(tc.Context(), "static", hosts.WithName(expected[i].Name))
|
||||
expected[i], apiErr, err = catalogClient.Create(tc.Context(), "static", hostcatalogs.WithName(expected[i].Name))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
}
|
||||
@@ -60,10 +60,10 @@ func TestCatalog_List(t *testing.T) {
|
||||
assert.ElementsMatch(comparableCatalogSlice(expected), comparableCatalogSlice(ul))
|
||||
}
|
||||
|
||||
func comparableCatalogSlice(in []*hosts.HostCatalog) []hosts.HostCatalog {
|
||||
var filtered []hosts.HostCatalog
|
||||
func comparableCatalogSlice(in []*hostcatalogs.HostCatalog) []hostcatalogs.HostCatalog {
|
||||
var filtered []hostcatalogs.HostCatalog
|
||||
for _, i := range in {
|
||||
p := hosts.HostCatalog{
|
||||
p := hostcatalogs.HostCatalog{
|
||||
Id: i.Id,
|
||||
Name: i.Name,
|
||||
Description: i.Description,
|
||||
@@ -92,7 +92,7 @@ func TestCatalogs_Crud(t *testing.T) {
|
||||
projClient := client.Clone()
|
||||
projClient.SetScopeId(proj.GetPublicId())
|
||||
|
||||
checkCatalog := func(step string, hc *hosts.HostCatalog, apiErr *api.Error, err error, wantedName string, wantVersion uint32) {
|
||||
checkCatalog := func(step string, hc *hostcatalogs.HostCatalog, apiErr *api.Error, err error, wantedName string, wantVersion uint32) {
|
||||
require.NoError(err, step)
|
||||
if !assert.Nil(apiErr, step) && apiErr.Message != "" {
|
||||
t.Errorf("ApiError message: %q", apiErr.Message)
|
||||
@@ -106,18 +106,18 @@ func TestCatalogs_Crud(t *testing.T) {
|
||||
assert.Equal(wantVersion, hc.Version)
|
||||
}
|
||||
|
||||
hcClient := hosts.NewHostCatalogsClient(projClient)
|
||||
hcClient := hostcatalogs.NewClient(projClient)
|
||||
|
||||
hc, apiErr, err := hcClient.Create(tc.Context(), "static", hosts.WithName("foo"))
|
||||
hc, apiErr, err := hcClient.Create(tc.Context(), "static", hostcatalogs.WithName("foo"))
|
||||
checkCatalog("create", hc, apiErr, err, "foo", 1)
|
||||
|
||||
hc, apiErr, err = hcClient.Read(tc.Context(), hc.Id)
|
||||
checkCatalog("read", hc, apiErr, err, "foo", 1)
|
||||
|
||||
hc, apiErr, err = hcClient.Update(tc.Context(), hc.Id, hc.Version, hosts.WithName("bar"))
|
||||
hc, apiErr, err = hcClient.Update(tc.Context(), hc.Id, hc.Version, hostcatalogs.WithName("bar"))
|
||||
checkCatalog("update", hc, apiErr, err, "bar", 2)
|
||||
|
||||
hc, apiErr, err = hcClient.Update(tc.Context(), hc.Id, hc.Version, hosts.DefaultName())
|
||||
hc, apiErr, err = hcClient.Update(tc.Context(), hc.Id, hc.Version, hostcatalogs.DefaultName())
|
||||
checkCatalog("update", hc, apiErr, err, "", 3)
|
||||
|
||||
existed, apiErr, err := hcClient.Delete(tc.Context(), hc.Id)
|
||||
@@ -144,14 +144,14 @@ func TestCatalogs_Errors(t *testing.T) {
|
||||
client := tc.Client()
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
pc := hosts.NewHostCatalogsClient(client)
|
||||
pc := hostcatalogs.NewClient(client)
|
||||
|
||||
hc, apiErr, err := pc.Create(tc.Context(), "static", hosts.WithName("foo"))
|
||||
hc, apiErr, err := pc.Create(tc.Context(), "static", hostcatalogs.WithName("foo"))
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.NotNil(hc)
|
||||
|
||||
_, apiErr, err = pc.Create(tc.Context(), "static", hosts.WithName("foo"))
|
||||
_, apiErr, err = pc.Create(tc.Context(), "static", hostcatalogs.WithName("foo"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package hostcatalogs
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/api"
|
||||
)
|
||||
|
||||
// Option is a func that sets optional attributes for a call. This does not need
|
||||
// to be used directly, but instead option arguments are built from the
|
||||
// functions in this package. WithX options set a value to that given in the
|
||||
// argument; DefaultX options indicate that the value should be set to its
|
||||
// default. When an API call is made options are processed in ther order they
|
||||
// appear in the function call, so for a given argument X, a succession of WithX
|
||||
// or DefaultX calls will result in the last call taking effect.
|
||||
type Option func(*options)
|
||||
|
||||
type options struct {
|
||||
postMap map[string]interface{}
|
||||
queryMap map[string]string
|
||||
withScopeId string
|
||||
withAutomaticVersioning bool
|
||||
}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
return options{
|
||||
postMap: make(map[string]interface{}),
|
||||
queryMap: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func getOpts(opt ...Option) (options, []api.Option) {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
o(&opts)
|
||||
}
|
||||
var apiOpts []api.Option
|
||||
if opts.withScopeId != "" {
|
||||
apiOpts = append(apiOpts, api.WithScopeId(opts.withScopeId))
|
||||
}
|
||||
return opts, apiOpts
|
||||
}
|
||||
|
||||
func WithScopeId(id string) Option {
|
||||
return func(o *options) {
|
||||
o.withScopeId = id
|
||||
}
|
||||
}
|
||||
|
||||
// If set, and if the version is zero during an update, the API will perform a
|
||||
// fetch to get the current version of the resource and populate it during the
|
||||
// update call. This is convenient but opens up the possibility for subtle
|
||||
// order-of-modification issues, so use carefully.
|
||||
func WithAutomaticVersioning() Option {
|
||||
return func(o *options) {
|
||||
o.withAutomaticVersioning = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithAttributes(inAttributes map[string]interface{}) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["attributes"] = inAttributes
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultAttributes() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["attributes"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithDescription(inDescription string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["description"] = inDescription
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultDescription() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["description"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithName(inName string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["name"] = inName
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultName() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["name"] = nil
|
||||
}
|
||||
}
|
||||
@@ -28,15 +28,15 @@ type Host struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type HostsClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewHostsClient(c *api.Client) *HostsClient {
|
||||
return &HostsClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *HostsClient) Create(ctx context.Context, hostCatalogId string, opt ...Option) (*Host, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, hostCatalogId string, opt ...Option) (*Host, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Create request")
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (c *HostsClient) Create(ctx context.Context, hostCatalogId string, opt ...O
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostsClient) Read(ctx context.Context, hostCatalogId string, hostId string, opt ...Option) (*Host, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, hostCatalogId string, hostId string, opt ...Option) (*Host, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Read request")
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func (c *HostsClient) Read(ctx context.Context, hostCatalogId string, hostId str
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostsClient) Update(ctx context.Context, hostCatalogId string, hostId string, version uint32, opt ...Option) (*Host, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, hostCatalogId string, hostId string, version uint32, opt ...Option) (*Host, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Update request")
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (c *HostsClient) Update(ctx context.Context, hostCatalogId string, hostId s
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostsClient) Delete(ctx context.Context, hostCatalogId string, hostId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, hostCatalogId string, hostId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return false, nil, fmt.Errorf("empty hostCatalogId value passed into Delete request")
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (c *HostsClient) Delete(ctx context.Context, hostCatalogId string, hostId s
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostsClient) List(ctx context.Context, hostCatalogId string, opt ...Option) ([]*Host, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, hostCatalogId string, opt ...Option) ([]*Host, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into List request")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/internal/host/static"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
@@ -29,12 +30,12 @@ func TestHost_List(t *testing.T) {
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
hc, apiErr, err := hostcatalogs.NewClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
hClient := hosts.NewHostsClient(client)
|
||||
hClient := hosts.NewClient(client)
|
||||
|
||||
ul, apiErr, err := hClient.List(tc.Context(), hc.Id)
|
||||
assert.NoError(err)
|
||||
@@ -98,7 +99,7 @@ func TestHost_Crud(t *testing.T) {
|
||||
projClient := client.Clone()
|
||||
projClient.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(projClient).Create(tc.Context(), "static")
|
||||
hc, apiErr, err := hostcatalogs.NewClient(projClient).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
@@ -117,7 +118,7 @@ func TestHost_Crud(t *testing.T) {
|
||||
assert.Equal(wantVersion, h.Version)
|
||||
}
|
||||
|
||||
hClient := hosts.NewHostsClient(projClient)
|
||||
hClient := hosts.NewClient(projClient)
|
||||
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"), hosts.WithStaticHostAddress("someaddress"))
|
||||
checkHost("create", h, apiErr, err, "foo", 1)
|
||||
@@ -156,12 +157,12 @@ func TestHost_Errors(t *testing.T) {
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
hc, apiErr, err := hostcatalogs.NewClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
hClient := hosts.NewHostsClient(client)
|
||||
hClient := hosts.NewClient(client)
|
||||
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"), hosts.WithStaticHostAddress("someaddress"))
|
||||
require.NoError(err)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by "make api"; DO NOT EDIT.
|
||||
package hosts
|
||||
package hostsets
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -28,15 +28,15 @@ type HostSet struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type HostSetsClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewHostSetsClient(c *api.Client) *HostSetsClient {
|
||||
return &HostSetsClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) Create(ctx context.Context, hostCatalogId string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, hostCatalogId string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Create request")
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (c *HostSetsClient) Create(ctx context.Context, hostCatalogId string, opt .
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) Read(ctx context.Context, hostCatalogId string, hostSetId string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, hostCatalogId string, hostSetId string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Read request")
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func (c *HostSetsClient) Read(ctx context.Context, hostCatalogId string, hostSet
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) Update(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into Update request")
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (c *HostSetsClient) Update(ctx context.Context, hostCatalogId string, hostS
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) Delete(ctx context.Context, hostCatalogId string, hostSetId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, hostCatalogId string, hostSetId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return false, nil, fmt.Errorf("empty hostCatalogId value passed into Delete request")
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (c *HostSetsClient) Delete(ctx context.Context, hostCatalogId string, hostS
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) List(ctx context.Context, hostCatalogId string, opt ...Option) ([]*HostSet, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, hostCatalogId string, opt ...Option) ([]*HostSet, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into List request")
|
||||
}
|
||||
@@ -269,7 +269,7 @@ func (c *HostSetsClient) List(ctx context.Context, hostCatalogId string, opt ...
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) AddHosts(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, hostIds []string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
func (c *Client) AddHosts(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, hostIds []string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into AddHosts request")
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func (c *HostSetsClient) AddHosts(ctx context.Context, hostCatalogId string, hos
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) SetHosts(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, hostIds []string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
func (c *Client) SetHosts(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, hostIds []string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into SetHosts request")
|
||||
}
|
||||
@@ -402,7 +402,7 @@ func (c *HostSetsClient) SetHosts(ctx context.Context, hostCatalogId string, hos
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *HostSetsClient) RemoveHosts(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, hostIds []string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
func (c *Client) RemoveHosts(ctx context.Context, hostCatalogId string, hostSetId string, version uint32, hostIds []string, opt ...Option) (*HostSet, *api.Error, error) {
|
||||
if hostCatalogId == "" {
|
||||
return nil, nil, fmt.Errorf("empty hostCatalogId value passed into RemoveHosts request")
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package hosts_test
|
||||
package hostsets_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -6,7 +6,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/api/hostsets"
|
||||
"github.com/hashicorp/boundary/internal/host/static"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller"
|
||||
@@ -29,11 +31,11 @@ func TestCustom(t *testing.T) {
|
||||
client := tc.Client().Clone()
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
hc, apiErr, err := hostcatalogs.NewClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
|
||||
hClient := hosts.NewHostsClient(client)
|
||||
hClient := hosts.NewClient(client)
|
||||
h1, apiErr, err := hClient.Create(tc.Context(), hc.Id, hosts.WithStaticHostAddress("someaddress"))
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
@@ -41,7 +43,7 @@ func TestCustom(t *testing.T) {
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
|
||||
hSetClient := hosts.NewHostSetsClient(client)
|
||||
hSetClient := hostsets.NewClient(client)
|
||||
hSet, apiErr, err := hSetClient.Create(tc.Context(), hc.Id)
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
@@ -77,24 +79,24 @@ func TestSet_List(t *testing.T) {
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
hc, apiErr, err := hostcatalogs.NewClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
hClient := hosts.NewHostSetsClient(client)
|
||||
hClient := hostsets.NewClient(client)
|
||||
|
||||
ul, apiErr, err := hClient.List(tc.Context(), hc.Id)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.Empty(ul)
|
||||
|
||||
var expected []*hosts.HostSet
|
||||
var expected []*hostsets.HostSet
|
||||
for i := 0; i < 10; i++ {
|
||||
expected = append(expected, &hosts.HostSet{Name: fmt.Sprint(i)})
|
||||
expected = append(expected, &hostsets.HostSet{Name: fmt.Sprint(i)})
|
||||
}
|
||||
|
||||
expected[0], apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName(expected[0].Name))
|
||||
expected[0], apiErr, err = hClient.Create(tc.Context(), hc.Id, hostsets.WithName(expected[0].Name))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
@@ -104,7 +106,7 @@ func TestSet_List(t *testing.T) {
|
||||
assert.ElementsMatch(comparableSetSlice(expected[:1]), comparableSetSlice(ul))
|
||||
|
||||
for i := 1; i < 10; i++ {
|
||||
expected[i], apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName(expected[i].Name))
|
||||
expected[i], apiErr, err = hClient.Create(tc.Context(), hc.Id, hostsets.WithName(expected[i].Name))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
}
|
||||
@@ -114,10 +116,10 @@ func TestSet_List(t *testing.T) {
|
||||
assert.ElementsMatch(comparableSetSlice(expected), comparableSetSlice(ul))
|
||||
}
|
||||
|
||||
func comparableSetSlice(in []*hosts.HostSet) []hosts.HostSet {
|
||||
var filtered []hosts.HostSet
|
||||
func comparableSetSlice(in []*hostsets.HostSet) []hostsets.HostSet {
|
||||
var filtered []hostsets.HostSet
|
||||
for _, i := range in {
|
||||
p := hosts.HostSet{
|
||||
p := hostsets.HostSet{
|
||||
Id: i.Id,
|
||||
Name: i.Name,
|
||||
Description: i.Description,
|
||||
@@ -146,12 +148,12 @@ func TestSet_Crud(t *testing.T) {
|
||||
projClient := client.Clone()
|
||||
projClient.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(projClient).Create(tc.Context(), "static")
|
||||
hc, apiErr, err := hostcatalogs.NewClient(projClient).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
checkHost := func(step string, h *hosts.HostSet, apiErr *api.Error, err error, wantedName string, wantVersion uint32) {
|
||||
checkHost := func(step string, h *hostsets.HostSet, apiErr *api.Error, err error, wantedName string, wantVersion uint32) {
|
||||
require.NoError(err, step)
|
||||
if !assert.Nil(apiErr, step) && apiErr.Message != "" {
|
||||
t.Errorf("ApiError message: %q", apiErr.Message)
|
||||
@@ -165,18 +167,18 @@ func TestSet_Crud(t *testing.T) {
|
||||
assert.Equal(wantVersion, h.Version)
|
||||
}
|
||||
|
||||
hClient := hosts.NewHostSetsClient(projClient)
|
||||
hClient := hostsets.NewClient(projClient)
|
||||
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"))
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hostsets.WithName("foo"))
|
||||
checkHost("create", h, apiErr, err, "foo", 1)
|
||||
|
||||
h, apiErr, err = hClient.Read(tc.Context(), hc.Id, h.Id)
|
||||
checkHost("read", h, apiErr, err, "foo", 1)
|
||||
|
||||
h, apiErr, err = hClient.Update(tc.Context(), hc.Id, h.Id, h.Version, hosts.WithName("bar"))
|
||||
h, apiErr, err = hClient.Update(tc.Context(), hc.Id, h.Id, h.Version, hostsets.WithName("bar"))
|
||||
checkHost("update", h, apiErr, err, "bar", 2)
|
||||
|
||||
h, apiErr, err = hClient.Update(tc.Context(), hc.Id, h.Id, h.Version, hosts.DefaultName())
|
||||
h, apiErr, err = hClient.Update(tc.Context(), hc.Id, h.Id, h.Version, hostsets.DefaultName())
|
||||
checkHost("update", h, apiErr, err, "", 3)
|
||||
|
||||
existed, apiErr, err := hClient.Delete(tc.Context(), hc.Id, h.Id)
|
||||
@@ -204,19 +206,19 @@ func TestSet_Errors(t *testing.T) {
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
hc, apiErr, err := hostcatalogs.NewClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
hClient := hosts.NewHostSetsClient(client)
|
||||
hClient := hostsets.NewClient(client)
|
||||
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"))
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hostsets.WithName("foo"))
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
assert.NotNil(h)
|
||||
|
||||
_, apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"))
|
||||
_, apiErr, err = hClient.Create(tc.Context(), hc.Id, hostsets.WithName("foo"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package hostsets
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/api"
|
||||
)
|
||||
|
||||
// Option is a func that sets optional attributes for a call. This does not need
|
||||
// to be used directly, but instead option arguments are built from the
|
||||
// functions in this package. WithX options set a value to that given in the
|
||||
// argument; DefaultX options indicate that the value should be set to its
|
||||
// default. When an API call is made options are processed in ther order they
|
||||
// appear in the function call, so for a given argument X, a succession of WithX
|
||||
// or DefaultX calls will result in the last call taking effect.
|
||||
type Option func(*options)
|
||||
|
||||
type options struct {
|
||||
postMap map[string]interface{}
|
||||
queryMap map[string]string
|
||||
withScopeId string
|
||||
withAutomaticVersioning bool
|
||||
}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
return options{
|
||||
postMap: make(map[string]interface{}),
|
||||
queryMap: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func getOpts(opt ...Option) (options, []api.Option) {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
o(&opts)
|
||||
}
|
||||
var apiOpts []api.Option
|
||||
if opts.withScopeId != "" {
|
||||
apiOpts = append(apiOpts, api.WithScopeId(opts.withScopeId))
|
||||
}
|
||||
return opts, apiOpts
|
||||
}
|
||||
|
||||
func WithScopeId(id string) Option {
|
||||
return func(o *options) {
|
||||
o.withScopeId = id
|
||||
}
|
||||
}
|
||||
|
||||
// If set, and if the version is zero during an update, the API will perform a
|
||||
// fetch to get the current version of the resource and populate it during the
|
||||
// update call. This is convenient but opens up the possibility for subtle
|
||||
// order-of-modification issues, so use carefully.
|
||||
func WithAutomaticVersioning() Option {
|
||||
return func(o *options) {
|
||||
o.withAutomaticVersioning = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithDescription(inDescription string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["description"] = inDescription
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultDescription() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["description"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithName(inName string) Option {
|
||||
return func(o *options) {
|
||||
o.postMap["name"] = inName
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultName() Option {
|
||||
return func(o *options) {
|
||||
o.postMap["name"] = nil
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,13 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/accounts"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/authmethods"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/authtokens"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/groups"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/hosts"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/hostsets"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/roles"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/users"
|
||||
@@ -211,9 +214,10 @@ var inputStructs = []*structInfo{
|
||||
outFile: "authmethods/password_auth_method_attributes.gen.go",
|
||||
subtypeName: "PasswordAuthMethod",
|
||||
},
|
||||
// Accounts
|
||||
{
|
||||
inProto: &authmethods.Account{},
|
||||
outFile: "authmethods/account.gen.go",
|
||||
inProto: &accounts.Account{},
|
||||
outFile: "accounts/account.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
@@ -226,8 +230,8 @@ var inputStructs = []*structInfo{
|
||||
versionEnabled: true,
|
||||
},
|
||||
{
|
||||
inProto: &authmethods.PasswordAccountAttributes{},
|
||||
outFile: "authmethods/password_account_attributes.gen.go",
|
||||
inProto: &accounts.PasswordAccountAttributes{},
|
||||
outFile: "accounts/password_account_attributes.gen.go",
|
||||
subtypeName: "PasswordAccount",
|
||||
},
|
||||
// Auth Tokens
|
||||
@@ -244,8 +248,8 @@ var inputStructs = []*structInfo{
|
||||
},
|
||||
// Host related resources
|
||||
{
|
||||
inProto: &hosts.HostCatalog{},
|
||||
outFile: "hosts/host_catalog.gen.go",
|
||||
inProto: &hostcatalogs.HostCatalog{},
|
||||
outFile: "hostcatalogs/host_catalog.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
@@ -278,8 +282,8 @@ var inputStructs = []*structInfo{
|
||||
subtypeName: "StaticHost",
|
||||
},
|
||||
{
|
||||
inProto: &hosts.HostSet{},
|
||||
outFile: "hosts/host_set.gen.go",
|
||||
inProto: &hostsets.HostSet{},
|
||||
outFile: "hostsets/host_set.gen.go",
|
||||
templates: []*template.Template{
|
||||
clientTemplate,
|
||||
createTemplate,
|
||||
|
||||
@@ -59,7 +59,6 @@ func getArgsAndPaths(in []string, action string) (colArgs, resArgs []string, col
|
||||
}
|
||||
|
||||
type templateInput struct {
|
||||
ClientName string
|
||||
Name string
|
||||
Package string
|
||||
Fields []fieldInfo
|
||||
@@ -79,7 +78,6 @@ func fillTemplates() {
|
||||
for _, in := range inputStructs {
|
||||
outBuf := new(bytes.Buffer)
|
||||
input := templateInput{
|
||||
ClientName: in.generatedStructure.name + "s",
|
||||
Name: in.generatedStructure.name,
|
||||
Package: in.generatedStructure.pkg,
|
||||
Fields: in.generatedStructure.fields,
|
||||
@@ -200,7 +198,7 @@ func fillTemplates() {
|
||||
}
|
||||
|
||||
var listTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) List(ctx context.Context, {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }}opt... Option) ([]*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
func (c *Client) List(ctx context.Context, {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }}opt... Option) ([]*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into List request")
|
||||
}
|
||||
@@ -247,7 +245,7 @@ func (c *{{ .ClientName }}Client) List(ctx context.Context, {{ range .Collection
|
||||
`))
|
||||
|
||||
var readTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Read(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
func (c *Client) Read(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into Read request")
|
||||
}
|
||||
@@ -289,7 +287,7 @@ func (c *{{ .ClientName }}Client) Read(ctx context.Context, {{ range .ResourceFu
|
||||
`))
|
||||
|
||||
var deleteTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Delete(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (bool, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
func (c *Client) Delete(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (bool, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return false, nil, fmt.Errorf("empty {{ . }} value passed into Delete request")
|
||||
}
|
||||
@@ -334,7 +332,7 @@ func (c *{{ .ClientName }}Client) Delete(ctx context.Context, {{ range .Resource
|
||||
`))
|
||||
|
||||
var createTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Create(ctx context.Context, {{ if .TypeOnCreate }} resourceType string, {{ end }} {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
func (c *Client) Create(ctx context.Context, {{ if .TypeOnCreate }} resourceType string, {{ end }} {{ range .CollectionFunctionArgs }} {{ . }} string, {{ end }} opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .CollectionFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into Create request")
|
||||
}
|
||||
@@ -381,7 +379,7 @@ func (c *{{ .ClientName }}Client) Create(ctx context.Context, {{ if .TypeOnCreat
|
||||
`))
|
||||
|
||||
var updateTemplate = template.Must(template.New("").Parse(`
|
||||
func (c *{{ .ClientName }}Client) Update(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
func (c *Client) Update(ctx context.Context, {{ range .ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, opt... Option) (*{{ .Name }}, *api.Error, error) { {{ range .ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into Update request")
|
||||
}{{ end }}
|
||||
@@ -456,7 +454,7 @@ var sliceSubTypeTemplate = template.Must(template.New("").Funcs(
|
||||
{{ $fullName := print $op $key }}
|
||||
{{ $actionName := kebabCase $fullName }}
|
||||
{{ $resPath := getPathWithAction $input.PathArgs $actionName }}
|
||||
func (c *{{ $input.ClientName }}Client) {{ $fullName }}(ctx context.Context, {{ range $input.ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, {{ $value }} []string, opt... Option) (*{{ $input.Name }}, *api.Error, error) { {{ range $input.ResourceFunctionArgs }}
|
||||
func (c *Client) {{ $fullName }}(ctx context.Context, {{ range $input.ResourceFunctionArgs }} {{ . }} string, {{ end }}version uint32, {{ $value }} []string, opt... Option) (*{{ $input.Name }}, *api.Error, error) { {{ range $input.ResourceFunctionArgs }}
|
||||
if {{ . }} == "" {
|
||||
return nil, nil, fmt.Errorf("empty {{ . }} value passed into {{ $fullName }} request")
|
||||
}{{ end }}
|
||||
@@ -547,12 +545,12 @@ type {{ .Name }} struct { {{ range .Fields }}
|
||||
`)))
|
||||
|
||||
var clientTemplate = template.Must(template.New("").Parse(`
|
||||
type {{ .ClientName }}Client struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func New{{ .Name }}sClient(c *api.Client) *{{ .ClientName }}Client {
|
||||
return &{{ .ClientName }}Client{ client: c }
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{ client: c }
|
||||
}
|
||||
`))
|
||||
|
||||
|
||||
+14
-14
@@ -29,15 +29,15 @@ type Role struct {
|
||||
Grants []*Grant `json:"grants,omitempty"`
|
||||
}
|
||||
|
||||
type RolesClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewRolesClient(c *api.Client) *RolesClient {
|
||||
return &RolesClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *RolesClient) Create(ctx context.Context, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, opt ...Option) (*Role, *api.Error, error) {
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
@@ -72,7 +72,7 @@ func (c *RolesClient) Create(ctx context.Context, opt ...Option) (*Role, *api.Er
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) Read(ctx context.Context, roleId string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, roleId string, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into Read request")
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func (c *RolesClient) Read(ctx context.Context, roleId string, opt ...Option) (*
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) Update(ctx context.Context, roleId string, version uint32, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, roleId string, version uint32, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into Update request")
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func (c *RolesClient) Update(ctx context.Context, roleId string, version uint32,
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) Delete(ctx context.Context, roleId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, roleId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return false, nil, fmt.Errorf("empty roleId value passed into Delete request")
|
||||
}
|
||||
@@ -213,7 +213,7 @@ func (c *RolesClient) Delete(ctx context.Context, roleId string, opt ...Option)
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) List(ctx context.Context, opt ...Option) ([]*Role, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, opt ...Option) ([]*Role, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -252,7 +252,7 @@ func (c *RolesClient) List(ctx context.Context, opt ...Option) ([]*Role, *api.Er
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) AddGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) AddGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into AddGrants request")
|
||||
}
|
||||
@@ -314,7 +314,7 @@ func (c *RolesClient) AddGrants(ctx context.Context, roleId string, version uint
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) AddPrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) AddPrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into AddPrincipals request")
|
||||
}
|
||||
@@ -376,7 +376,7 @@ func (c *RolesClient) AddPrincipals(ctx context.Context, roleId string, version
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) SetGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) SetGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into SetGrants request")
|
||||
}
|
||||
@@ -441,7 +441,7 @@ func (c *RolesClient) SetGrants(ctx context.Context, roleId string, version uint
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) SetPrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) SetPrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into SetPrincipals request")
|
||||
}
|
||||
@@ -506,7 +506,7 @@ func (c *RolesClient) SetPrincipals(ctx context.Context, roleId string, version
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) RemoveGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) RemoveGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into RemoveGrants request")
|
||||
}
|
||||
@@ -568,7 +568,7 @@ func (c *RolesClient) RemoveGrants(ctx context.Context, roleId string, version u
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *RolesClient) RemovePrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *Client) RemovePrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
if roleId == "" {
|
||||
return nil, nil, fmt.Errorf("empty roleId value passed into RemovePrincipals request")
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestCustom(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
user, apiErr, err := users.NewUsersClient(client).Create(tc.Context())
|
||||
user, apiErr, err := users.NewClient(client).Create(tc.Context())
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
|
||||
@@ -69,12 +69,12 @@ func TestCustom(t *testing.T) {
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g, apiErr, err := groups.NewGroupsClient(tt.scopeClient).Create(tc.Context())
|
||||
g, apiErr, err := groups.NewClient(tt.scopeClient).Create(tc.Context())
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(g)
|
||||
|
||||
rc := roles.NewRolesClient(tt.scopeClient)
|
||||
rc := roles.NewClient(tt.scopeClient)
|
||||
var version uint32 = 1
|
||||
|
||||
r, apiErr, err := rc.Create(tc.Context(), roles.WithName("foo"))
|
||||
@@ -162,7 +162,7 @@ func TestRole_List(t *testing.T) {
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
roleClient := roles.NewRolesClient(tt.scopeClient)
|
||||
roleClient := roles.NewClient(tt.scopeClient)
|
||||
p1, apiErr, err := roleClient.List(tc.Context())
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
@@ -257,7 +257,7 @@ func TestRole_Crud(t *testing.T) {
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
roleClient := roles.NewRolesClient(tt.scopeClient)
|
||||
roleClient := roles.NewClient(tt.scopeClient)
|
||||
g, apiErr, err := roleClient.Create(tc.Context(), roles.WithName("foo"))
|
||||
checkRole("create", g, apiErr, err, "foo", 1)
|
||||
|
||||
@@ -316,7 +316,7 @@ func TestRole_Errors(t *testing.T) {
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
roleClient := roles.NewRolesClient(tt.scopeClient)
|
||||
roleClient := roles.NewClient(tt.scopeClient)
|
||||
u, apiErr, err := roleClient.Create(tc.Context(), roles.WithName("first"))
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestProjects_List(t *testing.T) {
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
|
||||
scps := scopes.NewScopesClient(client)
|
||||
scps := scopes.NewClient(client)
|
||||
|
||||
pl, apiErr, err := scps.List(tc.Context(), org.GetPublicId())
|
||||
require.NoError(err)
|
||||
@@ -77,7 +77,7 @@ func TestProjects_Crud(t *testing.T) {
|
||||
org, _ := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
|
||||
scps := scopes.NewScopesClient(client)
|
||||
scps := scopes.NewClient(client)
|
||||
|
||||
checkProject := func(step string, s *scopes.Scope, apiErr *api.Error, err error, wantedName string, wantedVersion uint32) {
|
||||
require.NoError(err, step)
|
||||
@@ -130,7 +130,7 @@ func TestProject_Errors(t *testing.T) {
|
||||
org, _ := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
|
||||
scps := scopes.NewScopesClient(client)
|
||||
scps := scopes.NewClient(client)
|
||||
|
||||
createdProj, apiErr, err := scps.Create(tc.Context(), org.GetPublicId())
|
||||
require.NoError(err)
|
||||
|
||||
@@ -23,15 +23,15 @@ type Scope struct {
|
||||
Version uint32 `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type ScopesClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewScopesClient(c *api.Client) *ScopesClient {
|
||||
return &ScopesClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *ScopesClient) Create(ctx context.Context, scopeId string, opt ...Option) (*Scope, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, scopeId string, opt ...Option) (*Scope, *api.Error, error) {
|
||||
if scopeId == "" {
|
||||
return nil, nil, fmt.Errorf("empty scopeId value passed into Create request")
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (c *ScopesClient) Create(ctx context.Context, scopeId string, opt ...Option
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *ScopesClient) Read(ctx context.Context, scopeId string, opt ...Option) (*Scope, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, scopeId string, opt ...Option) (*Scope, *api.Error, error) {
|
||||
if scopeId == "" {
|
||||
return nil, nil, fmt.Errorf("empty scopeId value passed into Read request")
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (c *ScopesClient) Read(ctx context.Context, scopeId string, opt ...Option)
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *ScopesClient) Update(ctx context.Context, scopeId string, version uint32, opt ...Option) (*Scope, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, scopeId string, version uint32, opt ...Option) (*Scope, *api.Error, error) {
|
||||
if scopeId == "" {
|
||||
return nil, nil, fmt.Errorf("empty scopeId value passed into Update request")
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func (c *ScopesClient) Update(ctx context.Context, scopeId string, version uint3
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *ScopesClient) Delete(ctx context.Context, scopeId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, scopeId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if scopeId == "" {
|
||||
return false, nil, fmt.Errorf("empty scopeId value passed into Delete request")
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func (c *ScopesClient) Delete(ctx context.Context, scopeId string, opt ...Option
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *ScopesClient) List(ctx context.Context, scopeId string, opt ...Option) ([]*Scope, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, scopeId string, opt ...Option) ([]*Scope, *api.Error, error) {
|
||||
if scopeId == "" {
|
||||
return nil, nil, fmt.Errorf("empty scopeId value passed into List request")
|
||||
}
|
||||
|
||||
@@ -24,15 +24,15 @@ type User struct {
|
||||
Version uint32 `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type UsersClient struct {
|
||||
type Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewUsersClient(c *api.Client) *UsersClient {
|
||||
return &UsersClient{client: c}
|
||||
func NewClient(c *api.Client) *Client {
|
||||
return &Client{client: c}
|
||||
}
|
||||
|
||||
func (c *UsersClient) Create(ctx context.Context, opt ...Option) (*User, *api.Error, error) {
|
||||
func (c *Client) Create(ctx context.Context, opt ...Option) (*User, *api.Error, error) {
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
@@ -67,7 +67,7 @@ func (c *UsersClient) Create(ctx context.Context, opt ...Option) (*User, *api.Er
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *UsersClient) Read(ctx context.Context, userId string, opt ...Option) (*User, *api.Error, error) {
|
||||
func (c *Client) Read(ctx context.Context, userId string, opt ...Option) (*User, *api.Error, error) {
|
||||
if userId == "" {
|
||||
return nil, nil, fmt.Errorf("empty userId value passed into Read request")
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (c *UsersClient) Read(ctx context.Context, userId string, opt ...Option) (*
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *UsersClient) Update(ctx context.Context, userId string, version uint32, opt ...Option) (*User, *api.Error, error) {
|
||||
func (c *Client) Update(ctx context.Context, userId string, version uint32, opt ...Option) (*User, *api.Error, error) {
|
||||
if userId == "" {
|
||||
return nil, nil, fmt.Errorf("empty userId value passed into Update request")
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (c *UsersClient) Update(ctx context.Context, userId string, version uint32,
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *UsersClient) Delete(ctx context.Context, userId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *Client) Delete(ctx context.Context, userId string, opt ...Option) (bool, *api.Error, error) {
|
||||
if userId == "" {
|
||||
return false, nil, fmt.Errorf("empty userId value passed into Delete request")
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func (c *UsersClient) Delete(ctx context.Context, userId string, opt ...Option)
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *UsersClient) List(ctx context.Context, opt ...Option) ([]*User, *api.Error, error) {
|
||||
func (c *Client) List(ctx context.Context, opt ...Option) ([]*User, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestUsers_List(t *testing.T) {
|
||||
client := tc.Client()
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
userClient := users.NewUsersClient(client)
|
||||
userClient := users.NewClient(client)
|
||||
|
||||
ul, apiErr, err := userClient.List(tc.Context())
|
||||
assert.NoError(err)
|
||||
@@ -88,7 +88,7 @@ func TestUser_Crud(t *testing.T) {
|
||||
client := tc.Client()
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
userClient := users.NewUsersClient(client)
|
||||
userClient := users.NewClient(client)
|
||||
|
||||
checkUser := func(step string, u *users.User, apiErr *api.Error, err error, wantedName string, wantedVersion uint32) {
|
||||
assert.NoError(err, step)
|
||||
@@ -141,7 +141,7 @@ func TestUser_Errors(t *testing.T) {
|
||||
client := tc.Client()
|
||||
org := iam.TestOrg(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
userClient := users.NewUsersClient(client)
|
||||
userClient := users.NewClient(client)
|
||||
|
||||
u, apiErr, err := userClient.Create(tc.Context(), users.WithName("first"))
|
||||
require.NoError(err)
|
||||
|
||||
Reference in new issue
Block a user