Skip to content

Commit

Permalink
mockGCP log
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Nov 22, 2024
1 parent 78a132c commit 78cc28c
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 1,654 deletions.
18 changes: 18 additions & 0 deletions mockgcp/mockcompute/globaltargettcpproxyv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package mockcompute

import (
"context"
"fmt"
"strings"

"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects"
Expand Down Expand Up @@ -63,6 +64,15 @@ func (s *GlobalTargetTcpProxyV1) Insert(ctx context.Context, req *pb.InsertTarge
obj.CreationTimestamp = PtrTo(s.nowString())
obj.Id = &id
obj.Kind = PtrTo("compute#targetTcpProxy")

if obj.Service != nil {
service, err := s.parseGlobalBackendServiceName(obj.GetService())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "backend service %q is not valid", obj.GetService())
}
obj.Service = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/backendServices/%s", service.Project.ID, service.Name))
}

if obj.ProxyHeader == nil {
obj.ProxyHeader = PtrTo("NONE")
}
Expand Down Expand Up @@ -122,6 +132,14 @@ func (s *GlobalTargetTcpProxyV1) SetBackendService(ctx context.Context, req *pb.
}

obj.Service = req.GetTargetTcpProxiesSetBackendServiceRequestResource().Service
if obj.Service != nil {
service, err := s.parseGlobalBackendServiceName(obj.GetService())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "backend service %q is not valid", obj.GetService())
}
obj.Service = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/backendServices/%s", service.Project.ID, service.Name))
}

if err := s.storage.Update(ctx, fqn, obj); err != nil {
return nil, err
}
Expand Down
10 changes: 10 additions & 0 deletions mockgcp/mockcompute/regionaltargettcpproxyv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package mockcompute

import (
"context"
"fmt"
"strings"

"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects"
Expand Down Expand Up @@ -65,6 +66,15 @@ func (s *RegionalTargetTcpProxyV1) Insert(ctx context.Context, req *pb.InsertReg
obj.Kind = PtrTo("compute#targetTcpProxy")
obj.Region = PtrTo("https://www.googleapis.com/compute/v1/projects/${projectId}/regions/" + req.GetRegion())

obj.Service = req.GetTargetTcpProxyResource().Service
if obj.Service != nil {
service, err := s.parseRegionalBackendServiceName(obj.GetService())
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "backend service %q is not valid", obj.GetService())
}
obj.Service = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/backendServices/%s", service.Project.ID, service.Region, service.Name))
}

if err := s.storage.Create(ctx, fqn, obj); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 78cc28c

Please sign in to comment.