forked from GoogleCloudPlatform/k8s-config-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regional ssl certificate mock and update logs
- Loading branch information
Showing
33 changed files
with
2,724 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// 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" | ||
|
||
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" | ||
pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/compute/v1" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
type RegionalSSLCertificatesV1 struct { | ||
*MockService | ||
pb.UnimplementedRegionSslCertificatesServer | ||
} | ||
|
||
func (s *RegionalSSLCertificatesV1) Get(ctx context.Context, req *pb.GetRegionSslCertificateRequest) (*pb.SslCertificate, error) { | ||
reqName := "projects/" + req.GetProject() + "/regions/" + req.Region + "/sslCertificates/" + req.GetSslCertificate() | ||
name, err := s.parseRegionalSslCertificateName(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 *RegionalSSLCertificatesV1) Insert(ctx context.Context, req *pb.InsertRegionSslCertificateRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/regions/" + req.GetRegion() + "/sslCertificates/" + req.GetSslCertificateResource().GetName() | ||
name, err := s.parseRegionalSslCertificateName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
id := s.generateID() | ||
|
||
obj := proto.Clone(req.GetSslCertificateResource()).(*pb.SslCertificate) | ||
obj.SelfLink = PtrTo("https://www.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, err | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("insert"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startRegionalLRO(ctx, name.Project.ID, name.Region, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
func (s *RegionalSSLCertificatesV1) Delete(ctx context.Context, req *pb.DeleteRegionSslCertificateRequest) (*pb.Operation, error) { | ||
reqName := "projects/" + req.GetProject() + "/regions/" + req.GetRegion() + "/sslCertificates/" + req.GetSslCertificate() | ||
name, err := s.parseRegionalSslCertificateName(reqName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fqn := name.String() | ||
|
||
deleted := &pb.SslCertificate{} | ||
if err := s.storage.Delete(ctx, fqn, deleted); err != nil { | ||
return nil, err | ||
} | ||
|
||
op := &pb.Operation{ | ||
TargetId: deleted.Id, | ||
TargetLink: deleted.SelfLink, | ||
OperationType: PtrTo("delete"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startRegionalLRO(ctx, name.Project.ID, name.Region, op, func() (proto.Message, error) { | ||
return deleted, nil | ||
}) | ||
} | ||
|
||
type regionalSSLCertificateName struct { | ||
Project *projects.ProjectData | ||
Region string | ||
Name string | ||
} | ||
|
||
func (n *regionalSSLCertificateName) String() string { | ||
return "projects/" + n.Project.ID + "/regions/" + n.Region + "/sslCertificates/" + n.Name | ||
} | ||
|
||
// parseRegionalSslCertificateName parses a string into a regionalSSLCertificateName. | ||
// The expected form is `projects/*/regions/*/sslcertificate/*`. | ||
func (s *MockService) parseRegionalSslCertificateName(name string) (*regionalSSLCertificateName, error) { | ||
tokens := strings.Split(name, "/") | ||
|
||
if len(tokens) == 6 && tokens[0] == "projects" && tokens[2] == "regions" && tokens[4] == "sslCertificates" { | ||
project, err := s.Projects.GetProjectByID(tokens[1]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
name := ®ionalSSLCertificateName{ | ||
Project: project, | ||
Region: tokens[3], | ||
Name: tokens[5], | ||
} | ||
|
||
return name, nil | ||
} | ||
|
||
return nil, status.Errorf(codes.InvalidArgument, "name %q is not valid", name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,10 +283,46 @@ X-Xss-Protection: 0 | |
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "insert", | ||
"progress": 0, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE" | ||
"status": "RUNNING", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
||
GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false | ||
User-Agent: google-api-go-client/0.5 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 | ||
|
||
{ | ||
"endTime": "2024-04-01T12:34:56.123456Z", | ||
"id": "000000000000000000000", | ||
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "insert", | ||
"progress": 100, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
@@ -1107,10 +1143,46 @@ X-Xss-Protection: 0 | |
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "delete", | ||
"progress": 0, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE" | ||
"status": "RUNNING", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
||
GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false | ||
User-Agent: google-api-go-client/0.5 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 | ||
|
||
{ | ||
"endTime": "2024-04-01T12:34:56.123456Z", | ||
"id": "000000000000000000000", | ||
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "delete", | ||
"progress": 100, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,10 +283,46 @@ X-Xss-Protection: 0 | |
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "insert", | ||
"progress": 0, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE" | ||
"status": "RUNNING", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
||
GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false | ||
User-Agent: google-api-go-client/0.5 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 | ||
|
||
{ | ||
"endTime": "2024-04-01T12:34:56.123456Z", | ||
"id": "000000000000000000000", | ||
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "insert", | ||
"progress": 100, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
@@ -942,10 +978,46 @@ X-Xss-Protection: 0 | |
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "delete", | ||
"progress": 0, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE" | ||
"status": "RUNNING", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
||
GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false | ||
User-Agent: google-api-go-client/0.5 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 | ||
|
||
{ | ||
"endTime": "2024-04-01T12:34:56.123456Z", | ||
"id": "000000000000000000000", | ||
"insertTime": "2024-04-01T12:34:56.123456Z", | ||
"kind": "compute#operation", | ||
"name": "${operationID}", | ||
"operationType": "delete", | ||
"progress": 100, | ||
"selfLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}", | ||
"startTime": "2024-04-01T12:34:56.123456Z", | ||
"status": "DONE", | ||
"targetId": "${addressesId}", | ||
"targetLink": "https://www.googleapis.com/compute/v1/projects/${projectId}/global/addresses/computeaddress-${uniqueId}", | ||
"user": "[email protected]" | ||
} | ||
|
||
--- | ||
|
Oops, something went wrong.