Skip to content

Commit

Permalink
SCALRCORE-18605 CR [API_BRANCH]
Browse files Browse the repository at this point in the history
  • Loading branch information
vaniakov committed Jul 21, 2021
1 parent ccd4256 commit 6d501d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions access_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type AccessPolicyCreateOptions struct {

// Relations
Roles []*Role `jsonapi:"relation,roles"`
// The object of access policy, one of this fields must be filled
// The subject of access policy, one of this fields must be filled
User *User `jsonapi:"relation,user,omitempty"`
Team *Team `jsonapi:"relation,team,omitempty"`
ServiceAccount *ServiceAccount `jsonapi:"relation,service-account,omitempty"`
Expand Down Expand Up @@ -89,20 +89,20 @@ func (o AccessPolicyCreateOptions) valid() error {
return errors.New("one of: user,team,service_account must be provided")
}

var object string
var subjectId string
if o.User != nil {
object = o.User.ID
subjectId = o.User.ID
field = "user"
} else if o.Team != nil {
object = o.Team.ID
subjectId = o.Team.ID
field = "team"
} else {
object = o.ServiceAccount.ID
field = "service_account"
subjectId = o.ServiceAccount.ID
field = "service account"
}

if !validStringID(&object) {
return fmt.Errorf("invalid value for %v ID: %v", field, object)
if !validStringID(&subjectId) {
return fmt.Errorf("invalid value for %v ID: %v", field, subjectId)
}

return nil
Expand Down Expand Up @@ -161,7 +161,7 @@ func (s *accessPolicies) Create(ctx context.Context, options AccessPolicyCreateO
// Read an accessPolicy by its ID.
func (s *accessPolicies) Read(ctx context.Context, accessPolicyID string) (*AccessPolicy, error) {
if !validStringID(&accessPolicyID) {
return nil, errors.New("invalid value for accessPolicy")
return nil, errors.New("invalid value for access policy ID")
}

u := fmt.Sprintf("access-policies/%s", url.QueryEscape(accessPolicyID))
Expand Down Expand Up @@ -213,7 +213,7 @@ func (s *accessPolicies) Update(ctx context.Context, accessPolicyID string, opti
// Delete an accessPolicy by its ID.
func (s *accessPolicies) Delete(ctx context.Context, accessPolicyID string) error {
if !validStringID(&accessPolicyID) {
return errors.New("invalid value for accessPolicy ID")
return errors.New("invalid value for access policy ID")
}

u := fmt.Sprintf("access-policies/%s", url.QueryEscape(accessPolicyID))
Expand Down
4 changes: 2 additions & 2 deletions access_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestAccessPoliciesRead(t *testing.T) {
t.Run("with invalid accessPolicy id", func(t *testing.T) {
ap, err := client.AccessPolicies.Read(ctx, badIdentifier)
assert.Nil(t, ap)
assert.EqualError(t, err, "invalid value for accessPolicy")
assert.EqualError(t, err, "invalid value for access policy ID")
})
}

Expand Down Expand Up @@ -249,6 +249,6 @@ func TestAccessPoliciesDelete(t *testing.T) {

t.Run("without a valid accessPolicy ID", func(t *testing.T) {
err := client.AccessPolicies.Delete(ctx, badIdentifier)
assert.EqualError(t, err, "invalid value for accessPolicy ID")
assert.EqualError(t, err, "invalid value for access policy ID")
})
}

0 comments on commit 6d501d8

Please sign in to comment.