Skip to content

Commit

Permalink
fix(vault): add update logic for allow events and allow substitution (#…
Browse files Browse the repository at this point in the history
…1085)

* fix(vault): add update logic for allow events and allow substitution

* fix tests
  • Loading branch information
ecrupper committed Mar 15, 2024
1 parent aa44bf3 commit 0c3e620
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 46 deletions.
21 changes: 21 additions & 0 deletions secret/vault/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func TestVault_Create_Org(t *testing.T) {
sec.SetType("org")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
sec.SetAllowEvents(library.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down Expand Up @@ -136,6 +143,13 @@ func TestVault_Create_Repo(t *testing.T) {
sec.SetType("repo")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
sec.SetAllowEvents(library.NewEventsFromMask(3))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down Expand Up @@ -221,6 +235,13 @@ func TestVault_Create_Shared(t *testing.T) {
sec.SetType("shared")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(false)
sec.SetAllowSubstitution(false)
sec.SetAllowEvents(library.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down
21 changes: 21 additions & 0 deletions secret/vault/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func TestVault_Get_Org(t *testing.T) {
want.SetType("org")
want.SetImages([]string{"foo", "bar"})
want.SetEvents([]string{"foo", "bar"})
want.SetAllowCommand(true)
want.SetAllowSubstitution(true)
want.SetAllowEvents(library.NewEventsFromMask(1))
want.SetCreatedAt(1563474077)
want.SetCreatedBy("octocat")
want.SetUpdatedAt(1563474079)
want.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down Expand Up @@ -136,6 +143,13 @@ func TestVault_Get_Repo(t *testing.T) {
want.SetType("repo")
want.SetImages([]string{"foo", "bar"})
want.SetEvents([]string{"foo", "bar"})
want.SetAllowCommand(true)
want.SetAllowSubstitution(true)
want.SetAllowEvents(library.NewEventsFromMask(3))
want.SetCreatedAt(1563474077)
want.SetCreatedBy("octocat")
want.SetUpdatedAt(1563474079)
want.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down Expand Up @@ -220,6 +234,13 @@ func TestVault_Get_Shared(t *testing.T) {
want.SetType("shared")
want.SetImages([]string{"foo", "bar"})
want.SetEvents([]string{"foo", "bar"})
want.SetAllowCommand(false)
want.SetAllowSubstitution(false)
want.SetAllowEvents(library.NewEventsFromMask(1))
want.SetCreatedAt(1563474077)
want.SetCreatedBy("octocat")
want.SetUpdatedAt(1563474079)
want.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down
21 changes: 21 additions & 0 deletions secret/vault/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func TestVault_List_Org(t *testing.T) {
sec.SetType("org")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
sec.SetAllowEvents(library.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

want := []*library.Secret{sec}

Expand Down Expand Up @@ -198,6 +205,13 @@ func TestVault_List_Repo(t *testing.T) {
sec.SetType("repo")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
sec.SetAllowEvents(library.NewEventsFromMask(3))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

want := []*library.Secret{sec}

Expand Down Expand Up @@ -314,6 +328,13 @@ func TestVault_List_Shared(t *testing.T) {
sec.SetType("shared")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(false)
sec.SetAllowSubstitution(false)
sec.SetAllowEvents(library.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

want := []*library.Secret{sec}

Expand Down
9 changes: 8 additions & 1 deletion secret/vault/testdata/v1/org.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
"org": "foo",
"repo": "*",
"type": "org",
"value": "baz"
"value": "baz",
"allow_command": true,
"allow_substitution": true,
"allow_events": 1,
"created_at": 1563474077,
"created_by": "octocat",
"updated_at": 1563474079,
"updated_by": "octocat2"
},
"wrap_info": null,
"warnings": null,
Expand Down
19 changes: 10 additions & 9 deletions secret/vault/testdata/v1/repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"renewable": false,
"lease_duration": 2764800,
"data": {
"events": [
"foo",
"bar"
],
"images": [
"foo",
"bar"
],
"events": ["foo", "bar"],
"images": ["foo", "bar"],
"name": "baz",
"org": "foo",
"repo": "bar",
"type": "repo",
"value": "foob"
"value": "foob",
"allow_command": true,
"allow_substitution": true,
"allow_events": 3,
"created_at": 1563474077,
"created_by": "octocat",
"updated_at": 1563474079,
"updated_by": "octocat2"
},
"wrap_info": null,
"warnings": null,
Expand Down
19 changes: 10 additions & 9 deletions secret/vault/testdata/v1/shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"renewable": false,
"lease_duration": 2764800,
"data": {
"events": [
"foo",
"bar"
],
"images": [
"foo",
"bar"
],
"events": ["foo", "bar"],
"images": ["foo", "bar"],
"name": "baz",
"org": "foo",
"team": "bar",
"type": "shared",
"value": "foob"
"value": "foob",
"allow_command": false,
"allow_substitution": false,
"allow_events": 1,
"created_at": 1563474077,
"created_by": "octocat",
"updated_at": 1563474079,
"updated_by": "octocat2"
},
"wrap_info": null,
"warnings": null,
Expand Down
19 changes: 10 additions & 9 deletions secret/vault/testdata/v2/org.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
"renewable": false,
"data": {
"data": {
"events": [
"foo",
"bar"
],
"images": [
"foo",
"bar"
],
"events": ["foo", "bar"],
"images": ["foo", "bar"],
"name": "bar",
"org": "foo",
"repo": "*",
"type": "org",
"value": "baz"
"value": "baz",
"allow_command": true,
"allow_substitution": true,
"allow_events": 1,
"created_at": 1563474077,
"created_by": "octocat",
"updated_at": 1563474079,
"updated_by": "octocat2"
},
"metadata": {
"created_time": "2020-08-14T15:43:44.3462581Z",
Expand Down
19 changes: 10 additions & 9 deletions secret/vault/testdata/v2/repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
"renewable": false,
"data": {
"data": {
"events": [
"foo",
"bar"
],
"images": [
"foo",
"bar"
],
"events": ["foo", "bar"],
"images": ["foo", "bar"],
"name": "baz",
"org": "foo",
"repo": "bar",
"type": "repo",
"value": "foob"
"value": "foob",
"allow_command": true,
"allow_substitution": true,
"allow_events": 3,
"created_at": 1563474077,
"created_by": "octocat",
"updated_at": 1563474079,
"updated_by": "octocat2"
},
"metadata": {
"created_time": "2020-08-14T15:43:44.3462581Z",
Expand Down
19 changes: 10 additions & 9 deletions secret/vault/testdata/v2/shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
"renewable": false,
"data": {
"data": {
"events": [
"foo",
"bar"
],
"images": [
"foo",
"bar"
],
"events": ["foo", "bar"],
"images": ["foo", "bar"],
"name": "baz",
"org": "foo",
"team": "bar",
"type": "shared",
"value": "foob"
"value": "foob",
"allow_command": false,
"allow_substitution": false,
"allow_events": 1,
"created_at": 1563474077,
"created_by": "octocat",
"updated_at": 1563474079,
"updated_by": "octocat2"
},
"metadata": {
"created_time": "2020-08-14T15:43:44.3462581Z",
Expand Down
8 changes: 8 additions & 0 deletions secret/vault/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (c *client) Update(ctx context.Context, sType, org, name string, s *library
vault.Data["events"] = s.GetEvents()
}

if s.GetAllowEvents().ToDatabase() != 0 {
vault.Data["allow_events"] = s.GetAllowEvents().ToDatabase()
}

if s.Images != nil {
vault.Data["images"] = s.GetImages()
}
Expand All @@ -61,6 +65,10 @@ func (c *client) Update(ctx context.Context, sType, org, name string, s *library
vault.Data["allow_command"] = s.GetAllowCommand()
}

if s.AllowSubstitution != nil {
vault.Data["allow_substitution"] = s.GetAllowSubstitution()
}

// validate the secret
err = database.SecretFromLibrary(secretFromVault(vault)).Validate()
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions secret/vault/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func TestVault_Update_Org(t *testing.T) {
sec.SetType("org")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
sec.SetAllowEvents(library.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down Expand Up @@ -167,6 +174,13 @@ func TestVault_Update_Repo(t *testing.T) {
sec.SetType("repo")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(true)
sec.SetAllowSubstitution(true)
sec.SetAllowEvents(library.NewEventsFromMask(3))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down Expand Up @@ -267,6 +281,13 @@ func TestVault_Update_Shared(t *testing.T) {
sec.SetType("shared")
sec.SetImages([]string{"foo", "bar"})
sec.SetEvents([]string{"foo", "bar"})
sec.SetAllowCommand(false)
sec.SetAllowSubstitution(false)
sec.SetAllowEvents(library.NewEventsFromMask(1))
sec.SetCreatedAt(1563474077)
sec.SetCreatedBy("octocat")
sec.SetUpdatedAt(1563474079)
sec.SetUpdatedBy("octocat2")

type args struct {
version string
Expand Down

0 comments on commit 0c3e620

Please sign in to comment.