Minor fixes and first API test changeover (#243)
This commit is contained in:
1 parent
d74e30d94a
commit
df4730b1a0
16 files changed
+167
-145
No files matched your search
@@ -23,15 +23,15 @@ type Account struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type accountClient struct {
|
||||
type accountsClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewAccountClient(c *api.Client) *accountClient {
|
||||
return &accountClient{client: c}
|
||||
func NewAccountsClient(c *api.Client) *accountsClient {
|
||||
return &accountsClient{client: c}
|
||||
}
|
||||
|
||||
func (c *accountClient) Create(ctx context.Context, authMethodId string, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *accountsClient) 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")
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (c *accountClient) Create(ctx context.Context, authMethodId string, opt ...
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *accountClient) Read(ctx context.Context, authMethodId string, accountId string, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *accountsClient) 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")
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (c *accountClient) Read(ctx context.Context, authMethodId string, accountId
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *accountClient) Update(ctx context.Context, authMethodId string, accountId string, version uint32, opt ...Option) (*Account, *api.Error, error) {
|
||||
func (c *accountsClient) 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")
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func (c *accountClient) Update(ctx context.Context, authMethodId string, account
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *accountClient) Delete(ctx context.Context, authMethodId string, accountId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *accountsClient) 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")
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (c *accountClient) Delete(ctx context.Context, authMethodId string, account
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *accountClient) List(ctx context.Context, authMethodId string, opt ...Option) ([]*Account, *api.Error, error) {
|
||||
func (c *accountsClient) 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")
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ type AuthMethod struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type authmethodClient struct {
|
||||
type authmethodsClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewAuthMethodClient(c *api.Client) *authmethodClient {
|
||||
return &authmethodClient{client: c}
|
||||
func NewAuthMethodsClient(c *api.Client) *authmethodsClient {
|
||||
return &authmethodsClient{client: c}
|
||||
}
|
||||
|
||||
func (c *authmethodClient) Create(ctx context.Context, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
func (c *authmethodsClient) Create(ctx context.Context, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func (c *authmethodClient) Create(ctx context.Context, opt ...Option) (*AuthMeth
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *authmethodClient) Read(ctx context.Context, authMethodId string, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
func (c *authmethodsClient) 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")
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func (c *authmethodClient) Read(ctx context.Context, authMethodId string, opt ..
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *authmethodClient) Update(ctx context.Context, authMethodId string, version uint32, opt ...Option) (*AuthMethod, *api.Error, error) {
|
||||
func (c *authmethodsClient) 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")
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (c *authmethodClient) Update(ctx context.Context, authMethodId string, vers
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *authmethodClient) Delete(ctx context.Context, authMethodId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *authmethodsClient) 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")
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func (c *authmethodClient) Delete(ctx context.Context, authMethodId string, opt
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *authmethodClient) List(ctx context.Context, opt ...Option) ([]*AuthMethod, *api.Error, error) {
|
||||
func (c *authmethodsClient) List(ctx context.Context, opt ...Option) ([]*AuthMethod, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
@@ -1,42 +1,58 @@
|
||||
package authtokens_test
|
||||
|
||||
/*
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/watchtower/api/authmethods"
|
||||
"github.com/hashicorp/watchtower/api/authtokens"
|
||||
"github.com/hashicorp/watchtower/internal/authtoken"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAuthTokens_List(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{DisableAuthorizationFailures: true})
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultUsername: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
org := &scopes.Org{
|
||||
Client: client,
|
||||
}
|
||||
ctx := context.Background()
|
||||
tokens := authtokens.NewAuthTokenClient(client)
|
||||
methods := authmethods.NewAuthMethodClient(client)
|
||||
|
||||
atl, apiErr, err := org.ListAuthTokens(ctx)
|
||||
assert.NoError(err)
|
||||
atl, apiErr, err := tokens.List(tc.Context())
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.Empty(atl)
|
||||
|
||||
var expected []*authtokens.AuthToken
|
||||
|
||||
at, apiErr, err := org.Authenticate(ctx, "am_1234567890", "name", "pw")
|
||||
assert.NoError(err)
|
||||
at, apiErr, err := methods.Authenticate(tc.Context(), amId, "user", "passpass")
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
expected = append(expected, at)
|
||||
|
||||
atl, apiErr, err = org.ListAuthTokens(ctx)
|
||||
assert.NoError(err)
|
||||
atl, apiErr, err = tokens.List(tc.Context())
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSlice(expected), comparableSlice(atl))
|
||||
|
||||
for i := 1; i < 10; i++ {
|
||||
at, apiErr, err = org.Authenticate(ctx, "am_1234567890", "name", "pw")
|
||||
assert.NoError(err)
|
||||
at, apiErr, err = methods.Authenticate(tc.Context(), amId, "user", "passpass")
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
expected = append(expected, at)
|
||||
}
|
||||
atl, apiErr, err = org.ListAuthTokens(ctx)
|
||||
require.NoError(t, err)
|
||||
atl, apiErr, err = tokens.List(tc.Context())
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSlice(expected), comparableSlice(atl))
|
||||
}
|
||||
@@ -65,52 +81,61 @@ func comparableSlice(in []*authtokens.AuthToken) []authtokens.AuthToken {
|
||||
}
|
||||
|
||||
func TestAuthToken_Crud(t *testing.T) {
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{DisableAuthorizationFailures: true})
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultUsername: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
org := &scopes.Org{
|
||||
Client: client,
|
||||
}
|
||||
tokens := authtokens.NewAuthTokenClient(client)
|
||||
methods := authmethods.NewAuthMethodClient(client)
|
||||
|
||||
want, apiErr, err := org.Authenticate(tc.Context(), "am_1234567890", "name", "pw")
|
||||
want, apiErr, err := methods.Authenticate(tc.Context(), amId, "user", "passpass")
|
||||
require.NoError(err)
|
||||
assert.Empty(apiErr)
|
||||
|
||||
at, apiErr, err := org.ReadAuthToken(tc.Context(), &authtokens.AuthToken{Id: want.Id})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, apiErr)
|
||||
at.Token = ""
|
||||
assert.EqualValues(t, comparableResource(want), comparableResource(at))
|
||||
at, apiErr, err := tokens.Read(tc.Context(), want.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.EqualValues(comparableResource(want), comparableResource(at))
|
||||
|
||||
existed, _, err := org.DeleteAuthToken(tc.Context(), at)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, apiErr)
|
||||
assert.True(t, existed, "Expected existing user when deleted, but it wasn't.")
|
||||
existed, _, err := tokens.Delete(tc.Context(), at.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.True(existed, "Expected existing user when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = org.DeleteAuthToken(tc.Context(), at)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, apiErr)
|
||||
assert.False(t, existed, "Expected user to not exist when deleted, but it did.")
|
||||
existed, apiErr, err = tokens.Delete(tc.Context(), at.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.False(existed, "Expected user to not exist when deleted, but it did.")
|
||||
}
|
||||
|
||||
func TestAuthToken_Errors(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{DisableAuthorizationFailures: true})
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultUsername: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
ctx := tc.Context()
|
||||
|
||||
client := tc.Client()
|
||||
org := &scopes.Org{
|
||||
Client: client,
|
||||
}
|
||||
tokens := authtokens.NewAuthTokenClient(client)
|
||||
|
||||
_, apiErr, err := org.ReadAuthToken(ctx, &authtokens.AuthToken{Id: authtoken.AuthTokenPrefix + "_doesntexis"})
|
||||
assert.NoError(err)
|
||||
_, apiErr, err := tokens.Read(tc.Context(), authtoken.AuthTokenPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(apiErr.Status, http.StatusNotFound)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
|
||||
_, apiErr, err = org.ReadAuthToken(ctx, &authtokens.AuthToken{Id: "invalid id"})
|
||||
assert.NoError(err)
|
||||
_, apiErr, err = tokens.Read(tc.Context(), "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(apiErr.Status, http.StatusBadRequest)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
}
|
||||
*/
|
||||
@@ -22,15 +22,15 @@ type AuthToken struct {
|
||||
ExpirationTime time.Time `json:"expiration_time,omitempty"`
|
||||
}
|
||||
|
||||
type authtokenClient struct {
|
||||
type authtokensClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewAuthTokenClient(c *api.Client) *authtokenClient {
|
||||
return &authtokenClient{client: c}
|
||||
func NewAuthTokensClient(c *api.Client) *authtokensClient {
|
||||
return &authtokensClient{client: c}
|
||||
}
|
||||
|
||||
func (c *authtokenClient) Read(ctx context.Context, authTokenId string, opt ...Option) (*AuthToken, *api.Error, error) {
|
||||
func (c *authtokensClient) 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")
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (c *authtokenClient) Read(ctx context.Context, authTokenId string, opt ...O
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *authtokenClient) Delete(ctx context.Context, authTokenId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *authtokensClient) 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")
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (c *authtokenClient) Delete(ctx context.Context, authTokenId string, opt ..
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *authtokenClient) List(ctx context.Context, opt ...Option) ([]*AuthToken, *api.Error, error) {
|
||||
func (c *authtokensClient) 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 groupClient struct {
|
||||
type groupsClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewGroupClient(c *api.Client) *groupClient {
|
||||
return &groupClient{client: c}
|
||||
func NewGroupsClient(c *api.Client) *groupsClient {
|
||||
return &groupsClient{client: c}
|
||||
}
|
||||
|
||||
func (c *groupClient) Create(ctx context.Context, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *groupsClient) Create(ctx context.Context, opt ...Option) (*Group, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (c *groupClient) Create(ctx context.Context, opt ...Option) (*Group, *api.E
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *groupClient) Read(ctx context.Context, groupId string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *groupsClient) 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")
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func (c *groupClient) Read(ctx context.Context, groupId string, opt ...Option) (
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *groupClient) Update(ctx context.Context, groupId string, version uint32, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *groupsClient) 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")
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (c *groupClient) Update(ctx context.Context, groupId string, version uint32
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *groupClient) Delete(ctx context.Context, groupId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *groupsClient) 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")
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func (c *groupClient) Delete(ctx context.Context, groupId string, opt ...Option)
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *groupClient) List(ctx context.Context, opt ...Option) ([]*Group, *api.Error, error) {
|
||||
func (c *groupsClient) List(ctx context.Context, opt ...Option) ([]*Group, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func (c *groupClient) List(ctx context.Context, opt ...Option) ([]*Group, *api.E
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *groupClient) AddMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *groupsClient) 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")
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func (c *groupClient) AddMembers(ctx context.Context, groupId string, version ui
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *groupClient) SetMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *groupsClient) 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")
|
||||
}
|
||||
@@ -304,7 +304,7 @@ func (c *groupClient) SetMembers(ctx context.Context, groupId string, version ui
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *groupClient) RemoveMembers(ctx context.Context, groupId string, version uint32, memberIds []string, opt ...Option) (*Group, *api.Error, error) {
|
||||
func (c *groupsClient) 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")
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ type Host struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
}
|
||||
|
||||
type hostClient struct {
|
||||
type hostsClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewHostClient(c *api.Client) *hostClient {
|
||||
return &hostClient{client: c}
|
||||
func NewHostsClient(c *api.Client) *hostsClient {
|
||||
return &hostsClient{client: c}
|
||||
}
|
||||
|
||||
func (c *hostClient) Create(ctx context.Context, hostCatalogId string, opt ...Option) (*Host, *api.Error, error) {
|
||||
func (c *hostsClient) 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")
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (c *hostClient) Create(ctx context.Context, hostCatalogId string, opt ...Op
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostClient) Read(ctx context.Context, hostCatalogId string, hostId string, opt ...Option) (*Host, *api.Error, error) {
|
||||
func (c *hostsClient) 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")
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func (c *hostClient) Read(ctx context.Context, hostCatalogId string, hostId stri
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostClient) Update(ctx context.Context, hostCatalogId string, hostId string, version uint32, opt ...Option) (*Host, *api.Error, error) {
|
||||
func (c *hostsClient) 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")
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func (c *hostClient) Update(ctx context.Context, hostCatalogId string, hostId st
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostClient) Delete(ctx context.Context, hostCatalogId string, hostId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *hostsClient) 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")
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func (c *hostClient) Delete(ctx context.Context, hostCatalogId string, hostId st
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostClient) List(ctx context.Context, hostCatalogId string, opt ...Option) ([]*Host, *api.Error, error) {
|
||||
func (c *hostsClient) 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")
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ type HostCatalog struct {
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type hostcatalogClient struct {
|
||||
type hostcatalogsClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewHostCatalogClient(c *api.Client) *hostcatalogClient {
|
||||
return &hostcatalogClient{client: c}
|
||||
func NewHostCatalogsClient(c *api.Client) *hostcatalogsClient {
|
||||
return &hostcatalogsClient{client: c}
|
||||
}
|
||||
|
||||
func (c *hostcatalogClient) Create(ctx context.Context, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
func (c *hostcatalogsClient) Create(ctx context.Context, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func (c *hostcatalogClient) Create(ctx context.Context, opt ...Option) (*HostCat
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostcatalogClient) Read(ctx context.Context, hostCatalogId string, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
func (c *hostcatalogsClient) 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")
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (c *hostcatalogClient) Read(ctx context.Context, hostCatalogId string, opt
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostcatalogClient) Update(ctx context.Context, hostCatalogId string, version uint32, opt ...Option) (*HostCatalog, *api.Error, error) {
|
||||
func (c *hostcatalogsClient) 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")
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func (c *hostcatalogClient) Update(ctx context.Context, hostCatalogId string, ve
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostcatalogClient) Delete(ctx context.Context, hostCatalogId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *hostcatalogsClient) 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")
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (c *hostcatalogClient) Delete(ctx context.Context, hostCatalogId string, op
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *hostcatalogClient) List(ctx context.Context, opt ...Option) ([]*HostCatalog, *api.Error, error) {
|
||||
func (c *hostcatalogsClient) List(ctx context.Context, opt ...Option) ([]*HostCatalog, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func fillTemplates() {
|
||||
for _, in := range inputStructs {
|
||||
outBuf := new(bytes.Buffer)
|
||||
input := templateInput{
|
||||
ClientName: strings.ToLower(in.generatedStructure.name),
|
||||
ClientName: strings.ToLower(in.generatedStructure.name) + "s",
|
||||
Name: in.generatedStructure.name,
|
||||
Package: in.generatedStructure.pkg,
|
||||
Fields: in.generatedStructure.fields,
|
||||
@@ -453,7 +453,7 @@ type {{ .ClientName }}Client struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func New{{ .Name }}Client(c *api.Client) *{{ .ClientName }}Client {
|
||||
func New{{ .Name }}sClient(c *api.Client) *{{ .ClientName }}Client {
|
||||
return &{{ .ClientName }}Client{ client: c }
|
||||
}
|
||||
`))
|
||||
|
||||
+14
-14
@@ -29,15 +29,15 @@ type Role struct {
|
||||
Grants []*Grant `json:"grants,omitempty"`
|
||||
}
|
||||
|
||||
type roleClient struct {
|
||||
type rolesClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewRoleClient(c *api.Client) *roleClient {
|
||||
return &roleClient{client: c}
|
||||
func NewRolesClient(c *api.Client) *rolesClient {
|
||||
return &rolesClient{client: c}
|
||||
}
|
||||
|
||||
func (c *roleClient) Create(ctx context.Context, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) Create(ctx context.Context, opt ...Option) (*Role, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func (c *roleClient) Create(ctx context.Context, opt ...Option) (*Role, *api.Err
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) Read(ctx context.Context, roleId string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (c *roleClient) Read(ctx context.Context, roleId string, opt ...Option) (*R
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) Update(ctx context.Context, roleId string, version uint32, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (c *roleClient) Update(ctx context.Context, roleId string, version uint32,
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) Delete(ctx context.Context, roleId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func (c *roleClient) Delete(ctx context.Context, roleId string, opt ...Option) (
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) List(ctx context.Context, opt ...Option) ([]*Role, *api.Error, error) {
|
||||
func (c *rolesClient) List(ctx context.Context, opt ...Option) ([]*Role, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (c *roleClient) List(ctx context.Context, opt ...Option) ([]*Role, *api.Err
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) AddGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -253,7 +253,7 @@ func (c *roleClient) AddGrants(ctx context.Context, roleId string, version uint3
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) AddPrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -304,7 +304,7 @@ func (c *roleClient) AddPrincipals(ctx context.Context, roleId string, version u
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) SetGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -358,7 +358,7 @@ func (c *roleClient) SetGrants(ctx context.Context, roleId string, version uint3
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) SetPrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -412,7 +412,7 @@ func (c *roleClient) SetPrincipals(ctx context.Context, roleId string, version u
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) RemoveGrants(ctx context.Context, roleId string, version uint32, grantStrings []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
@@ -463,7 +463,7 @@ func (c *roleClient) RemoveGrants(ctx context.Context, roleId string, version ui
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *roleClient) RemovePrincipals(ctx context.Context, roleId string, version uint32, principalIds []string, opt ...Option) (*Role, *api.Error, error) {
|
||||
func (c *rolesClient) 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")
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ type Scope struct {
|
||||
Version uint32 `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type scopeClient struct {
|
||||
type scopesClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewScopeClient(c *api.Client) *scopeClient {
|
||||
return &scopeClient{client: c}
|
||||
func NewScopesClient(c *api.Client) *scopesClient {
|
||||
return &scopesClient{client: c}
|
||||
}
|
||||
|
||||
func (c *scopeClient) Create(ctx context.Context, opt ...Option) (*Scope, *api.Error, error) {
|
||||
func (c *scopesClient) Create(ctx context.Context, opt ...Option) (*Scope, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (c *scopeClient) Create(ctx context.Context, opt ...Option) (*Scope, *api.E
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *scopeClient) Read(ctx context.Context, scopeId string, opt ...Option) (*Scope, *api.Error, error) {
|
||||
func (c *scopesClient) 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")
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func (c *scopeClient) Read(ctx context.Context, scopeId string, opt ...Option) (
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *scopeClient) Update(ctx context.Context, scopeId string, version uint32, opt ...Option) (*Scope, *api.Error, error) {
|
||||
func (c *scopesClient) 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")
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func (c *scopeClient) Update(ctx context.Context, scopeId string, version uint32
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *scopeClient) Delete(ctx context.Context, scopeId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *scopesClient) 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")
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (c *scopeClient) Delete(ctx context.Context, scopeId string, opt ...Option)
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *scopeClient) List(ctx context.Context, opt ...Option) ([]*Scope, *api.Error, error) {
|
||||
func (c *scopesClient) List(ctx context.Context, opt ...Option) ([]*Scope, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
@@ -24,15 +24,15 @@ type User struct {
|
||||
Version uint32 `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type userClient struct {
|
||||
type usersClient struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
func NewUserClient(c *api.Client) *userClient {
|
||||
return &userClient{client: c}
|
||||
func NewUsersClient(c *api.Client) *usersClient {
|
||||
return &usersClient{client: c}
|
||||
}
|
||||
|
||||
func (c *userClient) Create(ctx context.Context, opt ...Option) (*User, *api.Error, error) {
|
||||
func (c *usersClient) Create(ctx context.Context, opt ...Option) (*User, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func (c *userClient) Create(ctx context.Context, opt ...Option) (*User, *api.Err
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *userClient) Read(ctx context.Context, userId string, opt ...Option) (*User, *api.Error, error) {
|
||||
func (c *usersClient) 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")
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (c *userClient) Read(ctx context.Context, userId string, opt ...Option) (*U
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *userClient) Update(ctx context.Context, userId string, version uint32, opt ...Option) (*User, *api.Error, error) {
|
||||
func (c *usersClient) 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")
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (c *userClient) Update(ctx context.Context, userId string, version uint32,
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *userClient) Delete(ctx context.Context, userId string, opt ...Option) (bool, *api.Error, error) {
|
||||
func (c *usersClient) 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")
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func (c *userClient) Delete(ctx context.Context, userId string, opt ...Option) (
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
func (c *userClient) List(ctx context.Context, opt ...Option) ([]*User, *api.Error, error) {
|
||||
func (c *usersClient) List(ctx context.Context, opt ...Option) ([]*User, *api.Error, error) {
|
||||
if c.client == nil {
|
||||
return nil, nil, fmt.Errorf("nil client")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user