-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mockgcp: ComputeManagedSSLCertificate #2010
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mockcompute | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/proto" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
|
||
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" | ||
pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/compute/v1" | ||
) | ||
|
||
type GlobalSSLCertificatesV1 struct { | ||
*MockService | ||
pb.UnimplementedSslCertificatesServer | ||
} | ||
|
||
func (s *GlobalSSLCertificatesV1) Get(ctx context.Context, req *pb.GetSslCertificateRequest) (*pb.SslCertificate, error) { | ||
reqName := "projects/" + req.GetProject() + "/global" + "/sslCertificates/" + req.GetSslCertificate() | ||
name, err := s.parseGlobalSslCertificateName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
obj := &pb.SslCertificate{} | ||
if err := s.storage.Get(ctx, fqn, obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
return obj, nil | ||
} | ||
|
||
func (s *GlobalSSLCertificatesV1) Insert(ctx context.Context, req *pb.InsertSslCertificateRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/global" + "/sslCertificates/" + req.GetSslCertificateResource().GetName() | ||
name, err := s.parseGlobalSslCertificateName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
id := s.generateID() | ||
|
||
obj := proto.Clone(req.GetSslCertificateResource()).(*pb.SslCertificate) | ||
obj.SelfLink = PtrTo("https://compute.googleapis.com/compute/v1/" + name.String()) | ||
obj.CreationTimestamp = PtrTo(s.nowString()) | ||
obj.Id = &id | ||
obj.Kind = PtrTo("compute#sslCertificate") | ||
|
||
if err := s.storage.Create(ctx, fqn, obj); err != nil { | ||
return nil, status.Errorf(codes.Internal, "error creating sslCertificate: %v", err) | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("insert"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
func (s *GlobalSSLCertificatesV1) Delete(ctx context.Context, req *pb.DeleteSslCertificateRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/global" + "/sslCertificates/" + req.GetSslCertificate() | ||
name, err := s.parseGlobalSslCertificateName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
deleted := &pb.SslCertificate{} | ||
if err := s.storage.Delete(ctx, fqn, deleted); err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return nil, status.Errorf(codes.NotFound, "sslCertificate %q not found", name) | ||
} | ||
|
||
return nil, status.Errorf(codes.Internal, "error deleting sslCertificate: %v", err) | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: deleted.Id, | ||
TargetLink: deleted.SelfLink, | ||
OperationType: PtrTo("delete"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I like this! |
||
return deleted, nil | ||
}) | ||
} | ||
|
||
type globalSSLCertificateName struct { | ||
Project *projects.ProjectData | ||
Name string | ||
} | ||
|
||
func (n *globalSSLCertificateName) String() string { | ||
return "projects/" + n.Project.ID + "/global" + "/sslCertificates/" + n.Name | ||
} | ||
|
||
// parseGlobalSslCertificateName parses a string into a globalSslCertificateName. | ||
// The expected form is `projects/*/regions/*/sslcertificate/*`. | ||
func (s *MockService) parseGlobalSslCertificateName(name string) (*globalSSLCertificateName, error) { | ||
tokens := strings.Split(name, "/") | ||
|
||
if len(tokens) == 5 && tokens[0] == "projects" && tokens[2] == "global" && tokens[3] == "sslCertificates" { | ||
project, err := s.Projects.GetProjectByID(tokens[1]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
name := &globalSSLCertificateName{ | ||
Project: project, | ||
Name: tokens[4], | ||
} | ||
|
||
return name, nil | ||
} | ||
|
||
return nil, status.Errorf(codes.InvalidArgument, "name %q is not valid", name) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,7 @@ X-Xss-Protection: 0 | |
"selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "RUNNING", | ||
"targetId": "${networkID}", | ||
"targetId": "7780111738275460050", | ||
"targetLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/computenetwork-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
@@ -1023,7 +1023,7 @@ X-Xss-Protection: 0 | |
"selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "RUNNING", | ||
"targetId": "${networkID}", | ||
"targetId": "7780111738275460050", | ||
"targetLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/networks/computenetwork-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
GET https://compute.googleapis.com/compute/beta/projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${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 | ||
|
||
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, | ||
"errors": [ | ||
{ | ||
"domain": "global", | ||
"message": "sslCertificate \"projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${uniqueId}\" not found", | ||
"reason": "notFound" | ||
} | ||
], | ||
"message": "sslCertificate \"projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${uniqueId}\" not found" | ||
} | ||
} | ||
|
||
--- | ||
|
||
POST https://compute.googleapis.com/compute/beta/projects/${projectId}/global/sslCertificates?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 | ||
|
||
{ | ||
"managed": { | ||
"domains": [ | ||
"sslcert.kcc-test.club." | ||
] | ||
}, | ||
"name": "computemanagedsslcertificate-${uniqueId}", | ||
"type": "MANAGED" | ||
} | ||
|
||
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 | ||
|
||
{ | ||
"id": "000000000000000000000", | ||
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "insert", | ||
"progress": 0, | ||
"selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "RUNNING", | ||
"targetId": "7780111738275460050", | ||
"targetLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
||
GET https://compute.googleapis.com/compute/beta/projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${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 | ||
|
||
{ | ||
"creationTimestamp": "2024-04-01T12:34:56.123456Z", | ||
"id": "000000000000000000000", | ||
"kind": "compute#sslCertificate", | ||
"managed": { | ||
"domains": [ | ||
"sslcert.kcc-test.club." | ||
] | ||
}, | ||
"name": "computemanagedsslcertificate-${uniqueId}", | ||
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${uniqueId}", | ||
"type": "MANAGED" | ||
} | ||
|
||
--- | ||
|
||
DELETE https://compute.googleapis.com/compute/beta/projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${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 | ||
|
||
{ | ||
"id": "000000000000000000000", | ||
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting, do you know the difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite certain, maybe it is resource specific? |
||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "delete", | ||
"progress": 0, | ||
"selfLink": "https://www.googleapis.com/compute/beta/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "RUNNING", | ||
"targetId": "7780111738275460050", | ||
"targetLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/sslCertificates/computemanagedsslcertificate-${uniqueId}", | ||
"user": "[email protected]" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -546,6 +546,7 @@ func runScenario(ctx context.Context, t *testing.T, testPause bool, fixture reso | |
addReplacement("insertTime", "2024-04-01T12:34:56.123456Z") | ||
addReplacement("startTime", "2024-04-01T12:34:56.123456Z") | ||
addReplacement("user", "[email protected]") | ||
addReplacement("targetId", "7780111738275460050") | ||
|
||
// Specific to vertexai | ||
addReplacement("blobStoragePathPrefix", "cloud-ai-platform-00000000-1111-2222-3333-444444444444") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq: I don't see update method, nor update.yaml test file. Is that intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes there is no
update
/patch
for this resource AFAICT.