Skip to content

Commit

Permalink
mock gcp log
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed Dec 12, 2024
1 parent 31cacb9 commit 16438ad
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 9 deletions.
11 changes: 11 additions & 0 deletions mockgcp/mocksecretmanager/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func (s *SecretsV1) populateDefaultsForSecret(ctx context.Context, obj *pb.Secre
return fmt.Errorf("Aliases cannot be assigned to versions that don't exist")
}
}
// TTL and ExpireTime are OneOf, but the GCP service always converts TTL to expireTime before storing the object.
if obj.GetTtl() != nil {
expirateTime := timestamppb.Now().AsTime().Add(obj.GetTtl().AsDuration())
obj.Expiration = &pb.Secret_ExpireTime{
ExpireTime: timestamppb.New(expirateTime),
}
}
return nil
}

Expand Down Expand Up @@ -154,6 +161,10 @@ func (s *SecretsV1) UpdateSecret(ctx context.Context, req *pb.UpdateSecretReques
updated.Expiration = &pb.Secret_ExpireTime{
ExpireTime: req.Secret.GetExpireTime(),
}
case "ttl":
updated.Expiration = &pb.Secret_Ttl{
Ttl: req.Secret.GetTtl(),
}
case "expiration":
updated.Expiration = req.Secret.GetExpiration()
case "rotation.nextRotationTime":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1
kind: SecretManagerSecret
metadata:
annotations:
alpha.cnrm.cloud.google.com/reconciler: direct
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
finalizers:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1
kind: SecretManagerSecret
metadata:
annotations:
cnrm.cloud.google.com/project-id: ${projectId}
labels:
cnrm-test: "true"
label-one: value-one
label-two: value-two
managed-by-cnrm: "true"
name: secretmanagersecret-${uniqueId}
spec:
annotations:
bar: secretmanagersecret-bar
foo: secretmanagersecret
expireTime: "2025-10-03T15:01:23Z"
resourceID: secretmanagersecret-${uniqueId}
rotation:
nextRotationTime: "2025-10-03T15:01:23Z"
rotationPeriod: 3600s
topics:
- topicRef:
external: projects/${projectId}/topics/topic-2-${uniqueId}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1
kind: SecretManagerSecret
metadata:
annotations:
cnrm.cloud.google.com/project-id: ${projectId}
labels:
cnrm-test: "true"
label-one: value-one
label-two: value-two
managed-by-cnrm: "true"
name: secretmanagersecret-${uniqueId}
spec:
annotations:
bar: secretmanagersecret-bar
foo: secretmanagersecret
expireTime: "2025-10-03T15:01:23Z"
replication:
auto:
customerManagedEncryption:
kmsKeyRef:
external: projects/${projectId}/locations/global/keyRings/kmskeyring-${uniqueId}/cryptoKeys/kmscryptokey-${uniqueId}
resourceID: secretmanagersecret-${uniqueId}
rotation:
nextRotationTime: "2025-10-03T15:01:23Z"
rotationPeriod: 7200s
topics:
- topicRef:
external: projects/${projectId}/topics/topic-2-${uniqueId}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1
kind: SecretManagerSecret
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 3
labels:
cnrm-test: "true"
label-one: value-one
label-two: value-two
name: secretmanagersecret-${uniqueId}
namespace: ${uniqueId}
spec:
annotations:
bar: secretmanagersecret-bar
foo: secretmanagersecret
expireTime: "2025-10-03T15:01:23Z"
replication:
automatic: true
resourceID: secretmanagersecret-${uniqueId}
rotation:
nextRotationTime: "2025-10-03T15:01:23Z"
rotationPeriod: 3600s
topics:
- topicRef:
name: topic-2-${uniqueId}
status:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: The resource is up to date
reason: UpToDate
status: "True"
type: Ready
name: projects/${projectNumber}/secrets/secretmanagersecret-${uniqueId}
observedGeneration: 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: secretmanager.cnrm.cloud.google.com/v1beta1
kind: SecretManagerSecret
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 2
labels:
cnrm-test: "true"
label-one: value-one
label-two: value-two
name: secretmanagersecret-${uniqueId}
namespace: ${uniqueId}
spec:
annotations:
bar: secretmanagersecret-bar
foo: secretmanagersecret
expireTime: "2025-10-03T15:01:23Z"
replication:
auto:
customerManagedEncryption:
kmsKeyRef:
name: kmscryptokey-${uniqueId}
automatic: true
rotation:
nextRotationTime: "2025-10-03T15:01:23Z"
rotationPeriod: 7200s
topics:
- topicRef:
name: topic-2-${uniqueId}
status:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: The resource is up to date
reason: UpToDate
status: "True"
type: Ready
externalRef: projects/${projectId}/secrets/secretmanagersecret-${uniqueId}
name: projects/${projectNumber}/secrets/secretmanagersecret-${uniqueId}
observedGeneration: 2
observedState: {}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ 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
Expand All @@ -180,7 +181,7 @@ X-Xss-Protection: 0
"done": true,
"name": "operations/${operationID}",
"response": {
"@type": "type.googleapis.com/google.api.serviceusage.v1beta1.ServiceIdentity",
"@type": "type.googleapis.com/mockgcp.api.serviceusage.v1beta1.ServiceIdentity",
"email": "service-${projectNumber}@gcp-sa-secretmanager.iam.gserviceaccount.com",
"uniqueId": "12345678"
}
Expand Down Expand Up @@ -899,5 +900,4 @@ Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{}
{}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
annotations:
bar: secretmanagersecret-bar
foo: secretmanagersecret
expireTime: "2024-12-12T06:58:02.096290745Z"
expireTime: "2025-10-03T15:01:23Z"
replication:
userManaged:
replicas:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ 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
Expand All @@ -362,7 +363,7 @@ X-Xss-Protection: 0
"done": true,
"name": "operations/${operationID}",
"response": {
"@type": "type.googleapis.com/google.api.serviceusage.v1beta1.ServiceIdentity",
"@type": "type.googleapis.com/mockgcp.api.serviceusage.v1beta1.ServiceIdentity",
"email": "service-${projectNumber}@gcp-sa-secretmanager.iam.gserviceaccount.com",
"uniqueId": "12345678"
}
Expand Down Expand Up @@ -1493,4 +1494,4 @@ X-Xss-Protection: 0
{
"createTime": "2024-04-01T12:34:56.123456Z",
"name": "projects/${projectId}/locations/us-central1/keyRings/kmskeyring-${uniqueId}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
annotations:
bar: secretmanagersecret-bar
foo: secretmanagersecret
expireTime: "2024-12-12T06:55:04.583510160Z"
expireTime: "2025-10-03T15:01:23Z"
replication:
userManaged:
replicas:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ 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
Expand All @@ -362,7 +363,7 @@ X-Xss-Protection: 0
"done": true,
"name": "operations/${operationID}",
"response": {
"@type": "type.googleapis.com/google.api.serviceusage.v1beta1.ServiceIdentity",
"@type": "type.googleapis.com/mockgcp.api.serviceusage.v1beta1.ServiceIdentity",
"email": "service-${projectNumber}@gcp-sa-secretmanager.iam.gserviceaccount.com",
"uniqueId": "12345678"
}
Expand Down Expand Up @@ -1430,4 +1431,4 @@ X-Xss-Protection: 0
{
"createTime": "2024-04-01T12:34:56.123456Z",
"name": "projects/${projectId}/locations/us-central1/keyRings/kmskeyring-${uniqueId}"
}
}
3 changes: 3 additions & 0 deletions tests/e2e/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func normalizeKRMObject(t *testing.T, u *unstructured.Unstructured, project test
// Specific to Certificate Manager
visitor.replacePaths[".status.dnsResourceRecord[].data"] = "${uniqueId}"

// Specific to Secret Manager
visitor.replacePaths[".spec.expireTime"] = "2025-10-03T15:01:23Z"

// Specific to MonitoringDashboard
visitor.stringTransforms = append(visitor.stringTransforms, func(path string, s string) string {
if strings.HasSuffix(path, ".alertChart.alertPolicyRef.external") {
Expand Down

0 comments on commit 16438ad

Please sign in to comment.