Skip to content

Commit

Permalink
CLOUDGA-18024: Handle the case when last rotated is null (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
arishta-yb authored Dec 5, 2023
1 parent d65d9c5 commit b9b78fc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
10 changes: 8 additions & 2 deletions cmd/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ AWS 0a80e409-e690-42fc-b209-baf969930b2c 2023-11-03T07:37:26.351Z arn
{
jsonFilePath: "./test/fixtures/azure_cmk.json",
provider: "AZURE",
expected: `Provider Key Alias Last Rotated Security Principals CMK Status
AZURE 8aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5b 2023-11-03T07:37:26.351Z https://test-azure-gj.vault.azure.net/ ACTIVE` + "\n",
expected: `Provider Key Alias Last Rotated Security Principals CMK Status
AZURE 8aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5b - https://test-azure-gj.vault.azure.net/ ACTIVE` + "\n",
},
{
jsonFilePath: "./test/fixtures/gcp_cmk.json",
provider: "GCP",
expected: `Provider Key Alias Last Rotated Security Principals CMK Status
GCP GCP-test-key 2023-11-03T07:37:26.351Z projects/<your-project-id>/locations/global/keyRings/GCP-test-key-ring/cryptoKeys/GCP-test-key ACTIVE` + "\n",
},
{
jsonFilePath: "./test/fixtures/azure_cmk_not_rotated.json",
provider: "AZURE",
expected: `Provider Key Alias Last Rotated Security Principals CMK Status
AZURE 8aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5b - https://test-azure-gj.vault.azure.net/ ACTIVE` + "\n",
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion cmd/test/fixtures/azure_cmk.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"info": {
"cmk_id": "41c64d5f-c97d-472c-889e-0d9f80d2c754",
"rotated_on": "2023-11-03T07:37:26.351Z",
"rotated_on": null,
"metadata": {
"created_on": "2023-11-03T07:37:26.351Z",
"updated_on": "2023-11-03T07:38:30.141Z"
Expand Down
28 changes: 28 additions & 0 deletions cmd/test/fixtures/azure_cmk_not_rotated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"data": {
"spec": {
"provider_type": "AZURE",
"aws_cmk_spec": null,
"status": "ACTIVE",
"gcp_cmk_spec": null,
"azure_cmk_spec": {
"client_id": "8aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5b",
"client_secret": "bfXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXlZ",
"tenant_id": "81XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX83",
"key_vault_uri": "https://test-azure-gj.vault.azure.net/",
"key_name": "AZURE-test-key",
"key_algorithm": "RSA",
"key_size": 2048
},
"is_enabled": true
},
"info": {
"cmk_id": "41c64d5f-c97d-472c-889e-0d9f80d2c754",
"rotated_on": null,
"metadata": {
"created_on": "2023-11-03T07:37:26.351Z",
"updated_on": "2023-11-03T07:38:30.141Z"
}
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20231109190829-ed4eb88fd77d
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20231201193810-43fdeee78dc9
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/mod v0.12.0
golang.org/x/term v0.13.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20231109190829-ed4eb88fd77d h1:85z/eaOBgKThrbq9b3HnKPCmz4eFQax6guqVH8sTEAc=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20231109190829-ed4eb88fd77d/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20231201193810-43fdeee78dc9 h1:V68/eDlBEKmk7rmjvIeuH4mi7elEYN45laQouBvtIpU=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20231201193810-43fdeee78dc9/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
5 changes: 4 additions & 1 deletion internal/formatter/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ func (c *CMKContext) Provider() ybmclient.CMKProviderEnum {
}

func (c *CMKContext) LastRotated() string {
return *c.c.Info.RotatedOn.Get()
if c.c.Info.GetRotatedOn() != "" {
return c.c.Info.GetRotatedOn()
}
return "-"
}

func (c *CMKContext) CMKStatus() ybmclient.CMKStatusEnum {
Expand Down

0 comments on commit b9b78fc

Please sign in to comment.