Skip to content

Commit 1f7999e

Browse files
authored
Add authorized collection actions output for credential stores (#1530)
Add authorized collection actions output for credential stores
1 parent 5d7e723 commit 1f7999e

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

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

5-
## Next
6-
7-
85
## 0.6.1 (2021/09/14)
96

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

1918
## 0.6.0 (2021/09/03)
2019

internal/servers/controller/auth/authorized_actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func CalculateAuthorizedCollectionActions(ctx context.Context,
3838
if err != nil {
3939
return nil, err
4040
}
41-
ret[k.String()+"s"] = lv
41+
ret[k.PluralString()] = lv
4242
}
4343
}
4444
return ret, nil

internal/servers/controller/handlers/credentialstores/credentialstore_service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ func toProto(in credential.Store, opt ...handlers.Option) (*pb.CredentialStore,
501501
if outputFields.Has(globals.AuthorizedActionsField) {
502502
out.AuthorizedActions = opts.WithAuthorizedActions
503503
}
504+
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
505+
out.AuthorizedCollectionActions = opts.WithAuthorizedCollectionActions
506+
}
504507
if outputFields.Has(globals.AttributesField) {
505508
switch credential.SubtypeFromId(in.GetPublicId()) {
506509
case vault.Subtype:

internal/servers/controller/handlers/credentialstores/credentialstore_service_test.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ import (
3434
"google.golang.org/protobuf/types/known/wrapperspb"
3535
)
3636

37-
var testAuthorizedActions = []string{"no-op", "read", "update", "delete"}
37+
var (
38+
testAuthorizedActions = []string{"no-op", "read", "update", "delete"}
39+
testAuthorizedCollectionActions = map[string]*structpb.ListValue{
40+
"credential-libraries": {
41+
Values: []*structpb.Value{
42+
structpb.NewStringValue("create"),
43+
structpb.NewStringValue("list"),
44+
},
45+
},
46+
}
47+
)
3848

3949
func TestList(t *testing.T) {
4050
conn, _ := db.TestSetup(t, "postgres")
@@ -57,14 +67,15 @@ func TestList(t *testing.T) {
5767
var wantStores []*pb.CredentialStore
5868
for _, s := range vault.TestCredentialStores(t, conn, wrapper, prj.GetPublicId(), 10) {
5969
wantStores = append(wantStores, &pb.CredentialStore{
60-
Id: s.GetPublicId(),
61-
ScopeId: prj.GetPublicId(),
62-
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
63-
CreatedTime: s.GetCreateTime().GetTimestamp(),
64-
UpdatedTime: s.GetUpdateTime().GetTimestamp(),
65-
Version: s.GetVersion(),
66-
Type: vault.Subtype.String(),
67-
AuthorizedActions: testAuthorizedActions,
70+
Id: s.GetPublicId(),
71+
ScopeId: prj.GetPublicId(),
72+
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
73+
CreatedTime: s.GetCreateTime().GetTimestamp(),
74+
UpdatedTime: s.GetUpdateTime().GetTimestamp(),
75+
Version: s.GetVersion(),
76+
Type: vault.Subtype.String(),
77+
AuthorizedActions: testAuthorizedActions,
78+
AuthorizedCollectionActions: testAuthorizedCollectionActions,
6879
Attributes: func() *structpb.Struct {
6980
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
7081
Address: wrapperspb.String(s.GetVaultAddress()),
@@ -451,7 +462,8 @@ func TestCreate(t *testing.T) {
451462
require.NoError(t, err)
452463
return attrs
453464
}(),
454-
AuthorizedActions: testAuthorizedActions,
465+
AuthorizedActions: testAuthorizedActions,
466+
AuthorizedCollectionActions: testAuthorizedCollectionActions,
455467
},
456468
},
457469
},
@@ -495,7 +507,8 @@ func TestCreate(t *testing.T) {
495507
require.NoError(t, err)
496508
return attrs
497509
}(),
498-
AuthorizedActions: testAuthorizedActions,
510+
AuthorizedActions: testAuthorizedActions,
511+
AuthorizedCollectionActions: testAuthorizedCollectionActions,
499512
},
500513
},
501514
},
@@ -580,14 +593,15 @@ func TestGet(t *testing.T) {
580593
id: store.GetPublicId(),
581594
res: &pbs.GetCredentialStoreResponse{
582595
Item: &pb.CredentialStore{
583-
Id: store.GetPublicId(),
584-
ScopeId: store.GetScopeId(),
585-
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
586-
Type: vault.Subtype.String(),
587-
AuthorizedActions: testAuthorizedActions,
588-
CreatedTime: store.CreateTime.GetTimestamp(),
589-
UpdatedTime: store.UpdateTime.GetTimestamp(),
590-
Version: 1,
596+
Id: store.GetPublicId(),
597+
ScopeId: store.GetScopeId(),
598+
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
599+
Type: vault.Subtype.String(),
600+
AuthorizedActions: testAuthorizedActions,
601+
AuthorizedCollectionActions: testAuthorizedCollectionActions,
602+
CreatedTime: store.CreateTime.GetTimestamp(),
603+
UpdatedTime: store.UpdateTime.GetTimestamp(),
604+
Version: 1,
591605
Attributes: func() *structpb.Struct {
592606
attrs, err := handlers.ProtoToStruct(&pb.VaultCredentialStoreAttributes{
593607
Address: wrapperspb.String(store.GetVaultAddress()),

internal/types/resource/resource.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ func (r Type) String() string {
6060
}[r]
6161
}
6262

63+
func (r Type) PluralString() string {
64+
switch r {
65+
case CredentialLibrary:
66+
return "credential-libraries"
67+
default:
68+
return r.String() + "s"
69+
}
70+
}
71+
6372
var Map = map[string]Type{
6473
Unknown.String(): Unknown,
6574
All.String(): All,

0 commit comments

Comments
 (0)