Skip to content

Commit

Permalink
test: scenario test for SecretManager version alias
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed Dec 4, 2024
1 parent d0cc290 commit 6fafcf3
Show file tree
Hide file tree
Showing 12 changed files with 514 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,9 @@ conditions:
externalRef: string
name: string
observedGeneration: integer
observedState: {}
observedState:
versionAliases:
string: string
```

<table class="properties responsive">
Expand Down Expand Up @@ -642,6 +644,13 @@ observedState: {}
<p>{% verbatim %}ObservedState is the state of the resource as most recently observed in GCP.{% endverbatim %}</p>
</td>
</tr>
<tr>
<td><code>observedState.versionAliases</code></td>
<td>
<p><code class="apitype">map (key: string, value: string)</code></p>
<p>{% verbatim %}{% endverbatim %}</p>
</td>
</tr>
</tbody>
</table>

Expand Down
15 changes: 11 additions & 4 deletions tests/e2e/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured, expectati
case schema.GroupKind{Group: "cloudbuild.cnrm.cloud.google.com", Kind: "CloudBuildWorkerPool"}:
exportURI = "//cloudbuild.googleapis.com/projects/" + projectID + "/locations/" + location + "/workerPools/" + resourceID

case schema.GroupKind{Group: "secretmanager.cnrm.cloud.google.com", Kind: "SecretManagerSecret"}:
exportURI = "//secretmanager.googleapis.com/projects/" + projectID + "/secrets/" + resourceID

}

if exportURI == "" {
Expand Down Expand Up @@ -103,17 +106,21 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured, expectati
}
exportURI = strings.ReplaceAll(exportURI, "{.spec.collection}", collection)
}

exportParams := h.ExportParams()
exportParams.IAMFormat = "partialpolicy"
exportParams.ResourceFormat = "krm"
outputDir := h.TempDir()
outputPath := filepath.Join(outputDir, "export.yaml")
exportParams.Output = outputPath
exportParams.URI = exportURI
if err := export.Execute(h.Ctx, &exportParams); err != nil {
h.Errorf("error from export.Execute: %v", err)
return ""
switch gvk.Kind {
case "SecretManagerSecretVersion":
break
default:
if err := export.Execute(h.Ctx, &exportParams); err != nil {
h.Errorf("error from export.Execute: %v", err)
return ""
}
}

output := h.MustReadFile(outputPath)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1
kind: SecretManagerSecret
metadata:
annotations:
cnrm.cloud.google.com/project-id: ${projectId}
labels:
managed-by-cnrm: "true"
name: secret-${uniqueId}
spec:
replication:
userManaged:
replicas:
- location: us-central1
resourceID: secret-${uniqueId}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1
kind: SecretManagerSecret
metadata:
annotations:
cnrm.cloud.google.com/project-id: ${projectId}
labels:
managed-by-cnrm: "true"
name: secret-${uniqueId}
spec:
replication:
userManaged:
replicas:
- location: us-central1
resourceID: secret-${uniqueId}
versionAliases:
foo: "1"
115 changes: 115 additions & 0 deletions tests/e2e/testdata/scenarios/secretmanagerversionalias/_http00.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
GET https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets/secret-${uniqueId}?%24alt=json%3Benum-encoding%3Dint
Content-Type: application/json
User-Agent: kcc/controller-manager
x-goog-request-params: name=projects%2F${projectId}%2Fsecrets%2Fsecret-${uniqueId}

404 Not Found
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"error": {
"code": 404,
"details": [
{
"@type": "type.googleapis.com/google.rpc.DebugInfo",
"detail": "[ORIGINAL ERROR] generic::not_found: Secret [projects/${projectNumber}/secrets/secret-${uniqueId}] not found. [google.rpc.error_details_ext] { message: \"Secret [projects/${projectNumber}/secrets/secret-${uniqueId}] not found.\" }"
}
],
"message": "Secret [projects/${projectNumber}/secrets/secret-${uniqueId}] not found.",
"status": "NOT_FOUND"
}
}

---

POST https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets?%24alt=json%3Benum-encoding%3Dint&secretId=secret-${uniqueId}
Content-Type: application/json
User-Agent: kcc/controller-manager
x-goog-request-params: parent=projects%2F${projectId}

{
"labels": {
"managed-by-cnrm": "true"
},
"replication": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
}
}

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"createTime": "2024-04-01T12:34:56.123456Z",
"etag": "abcdef0123A=",
"labels": {
"managed-by-cnrm": "true"
},
"name": "projects/${projectNumber}/secrets/secret-${uniqueId}",
"replication": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
}
}

---

GET https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets/secret-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"createTime": "2024-04-01T12:34:56.123456Z",
"etag": "abcdef0123A=",
"labels": {
"managed-by-cnrm": "true"
},
"name": "projects/${projectNumber}/secrets/secret-${uniqueId}",
"replication": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
}
}
74 changes: 74 additions & 0 deletions tests/e2e/testdata/scenarios/secretmanagerversionalias/_http02.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
POST https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets/secret-${uniqueId}:addVersion?%24alt=json%3Benum-encoding%3Dint
Content-Type: application/json
User-Agent: kcc/controller-manager
x-goog-request-params: parent=projects%2F${projectId}%2Fsecrets%2Fsecret-${uniqueId}

{
"parent": "projects/${projectId}/secrets/secret-${uniqueId}",
"payload": {
"data": "SSBhbHdheXMgbG92ZWQgc3BhcnJpbmcgd2l0aCBnaWFudCBjYW5keSBzd29yZHMsIGJ1dCBJIGhhZCBubyBpZGVhIHRoYXQgd2FzIG15IHN1cGVyIHNlY3JldCBpbmZvcm1hdGlvbiE="
}
}

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"createTime": "2024-04-01T12:34:56.123456Z",
"etag": "abcdef0123A=",
"name": "projects/${projectNumber}/secrets/secret-${uniqueId}/versions/1",
"replicationStatus": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
},
"state": 1
}

---

GET https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets/secret-${uniqueId}?%24alt=json%3Benum-encoding%3Dint
Content-Type: application/json
User-Agent: kcc/controller-manager
x-goog-request-params: name=projects%2F${projectId}%2Fsecrets%2Fsecret-${uniqueId}

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"createTime": "2024-04-01T12:34:56.123456Z",
"etag": "abcdef0123A=",
"labels": {
"managed-by-cnrm": "true"
},
"name": "projects/${projectNumber}/secrets/secret-${uniqueId}",
"replication": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
}
}
94 changes: 94 additions & 0 deletions tests/e2e/testdata/scenarios/secretmanagerversionalias/_http03.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
PATCH https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets/secret-${uniqueId}?%24alt=json%3Benum-encoding%3Dint&updateMask=versionAliases
Content-Type: application/json
User-Agent: kcc/controller-manager
x-goog-request-params: secret.name=projects%2F${projectId}%2Fsecrets%2Fsecret-${uniqueId}

{
"etag": "abcdef0123A=",
"labels": {
"managed-by-cnrm": "true"
},
"name": "projects/${projectId}/secrets/secret-${uniqueId}",
"replication": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
},
"versionAliases": {
"foo": "1"
}
}

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"createTime": "2024-04-01T12:34:56.123456Z",
"etag": "abcdef0123A=",
"labels": {
"managed-by-cnrm": "true"
},
"name": "projects/${projectNumber}/secrets/secret-${uniqueId}",
"replication": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
},
"versionAliases": {
"foo": "1"
}
}

---

GET https://secretmanager.googleapis.com/v1/projects/${projectId}/secrets/secret-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"createTime": "2024-04-01T12:34:56.123456Z",
"etag": "abcdef0123A=",
"labels": {
"managed-by-cnrm": "true"
},
"name": "projects/${projectNumber}/secrets/secret-${uniqueId}",
"replication": {
"userManaged": {
"replicas": [
{
"location": "us-central1"
}
]
}
},
"versionAliases": {
"foo": "1"
}
}
Loading

0 comments on commit 6fafcf3

Please sign in to comment.