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 afde6b9 commit 32a002c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 8 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
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
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
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 32a002c

Please sign in to comment.