Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authorized collection actions output for credential stores #1530

Merged
merged 2 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

Canonical reference for changes, improvements, and bugfixes for Boundary.

## Next


## 0.6.1 (2021/09/14)

### Bug Fixes
Expand All @@ -15,6 +12,8 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
project scope output. ([PR](https://github.com/hashicorp/boundary/pull/1524))
* actions: Fix `sessions` collection actions not being visible when reading a
scope ([PR](https://github.com/hashicorp/boundary/pull/1527))
* credential stores: Fix credential stores not showing authorized collection
actions ([PR](https://github.com/hashicorp/boundary/pull/1530))

## 0.6.0 (2021/09/03)

Expand Down
2 changes: 1 addition & 1 deletion internal/servers/controller/auth/authorized_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func CalculateAuthorizedCollectionActions(ctx context.Context,
if err != nil {
return nil, err
}
ret[k.String()+"s"] = lv
ret[k.PluralString()] = lv
}
}
return ret, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ func toProto(in credential.Store, opt ...handlers.Option) (*pb.CredentialStore,
if outputFields.Has(globals.AuthorizedActionsField) {
out.AuthorizedActions = opts.WithAuthorizedActions
}
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
out.AuthorizedCollectionActions = opts.WithAuthorizedCollectionActions
}
if outputFields.Has(globals.AttributesField) {
switch credential.SubtypeFromId(in.GetPublicId()) {
case vault.Subtype:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb"
)

var testAuthorizedActions = []string{"no-op", "read", "update", "delete"}
var (
testAuthorizedActions = []string{"no-op", "read", "update", "delete"}
testAuthorizedCollectionActions = map[string]*structpb.ListValue{
"credential-libraries": {
Values: []*structpb.Value{
structpb.NewStringValue("create"),
structpb.NewStringValue("list"),
},
},
}
)

func TestList(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
Expand All @@ -57,14 +67,15 @@ func TestList(t *testing.T) {
var wantStores []*pb.CredentialStore
for _, s := range vault.TestCredentialStores(t, conn, wrapper, prj.GetPublicId(), 10) {
wantStores = append(wantStores, &pb.CredentialStore{
Id: s.GetPublicId(),
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
CreatedTime: s.GetCreateTime().GetTimestamp(),
UpdatedTime: s.GetUpdateTime().GetTimestamp(),
Version: s.GetVersion(),
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
Id: s.GetPublicId(),
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
CreatedTime: s.GetCreateTime().GetTimestamp(),
UpdatedTime: s.GetUpdateTime().GetTimestamp(),
Version: s.GetVersion(),
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedCollectionActions,
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(s.GetVaultAddress()),
Expand Down Expand Up @@ -451,7 +462,8 @@ func TestCreate(t *testing.T) {
require.NoError(t, err)
return attrs
}(),
AuthorizedActions: testAuthorizedActions,
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedCollectionActions,
},
},
},
Expand Down Expand Up @@ -495,7 +507,8 @@ func TestCreate(t *testing.T) {
require.NoError(t, err)
return attrs
}(),
AuthorizedActions: testAuthorizedActions,
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedCollectionActions,
},
},
},
Expand Down Expand Up @@ -580,14 +593,15 @@ func TestGet(t *testing.T) {
id: store.GetPublicId(),
res: &pbs.GetCredentialStoreResponse{
Item: &pb.CredentialStore{
Id: store.GetPublicId(),
ScopeId: store.GetScopeId(),
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: store.CreateTime.GetTimestamp(),
UpdatedTime: store.UpdateTime.GetTimestamp(),
Version: 1,
Id: store.GetPublicId(),
ScopeId: store.GetScopeId(),
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: vault.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedCollectionActions,
CreatedTime: store.CreateTime.GetTimestamp(),
UpdatedTime: store.UpdateTime.GetTimestamp(),
Version: 1,
Attributes: func() *structpb.Struct {
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
Address: wrapperspb.String(store.GetVaultAddress()),
Expand Down
9 changes: 9 additions & 0 deletions internal/types/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ func (r Type) String() string {
}[r]
}

func (r Type) PluralString() string {
switch r {
case CredentialLibrary:
return "credential-libraries"
default:
return r.String() + "s"
}
}

var Map = map[string]Type{
Unknown.String(): Unknown,
All.String(): All,
Expand Down