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.
Update mocks with API default spec field
- Loading branch information
Showing
18 changed files
with
804 additions
and
51 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ package mockcompute | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" | ||
|
@@ -63,13 +64,53 @@ func (s *GlobalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertGlob | |
obj.CreationTimestamp = PtrTo(s.nowString()) | ||
obj.Id = &id | ||
obj.Kind = PtrTo("compute#forwardingRule") | ||
obj.LabelFingerprint = PtrTo("abcdef0123A=") | ||
// If below values are not provided by user, it appears to default by GCP | ||
if obj.LabelFingerprint == nil { | ||
obj.LabelFingerprint = PtrTo(computeFingerprint(obj)) | ||
} | ||
if obj.Fingerprint == nil { | ||
obj.Fingerprint = PtrTo(computeFingerprint(obj)) | ||
} | ||
if obj.IPProtocol == nil { | ||
obj.IPProtocol = PtrTo("TCP") | ||
} | ||
if obj.NetworkTier == nil { | ||
obj.NetworkTier = PtrTo("PREMIUM") | ||
} | ||
|
||
// pattern: \d+(?:-\d+)? | ||
if obj.PortRange != nil { | ||
r := obj.GetPortRange() | ||
token := strings.Split(r, "-") | ||
if len(token) == 1 { | ||
obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[0])) | ||
} else if len(token) == 2 { | ||
obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[1])) | ||
} else { | ||
return nil, status.Errorf(codes.InvalidArgument, "portRange %s is not valid", obj.GetPortRange()) | ||
} | ||
} | ||
|
||
if obj.Network != nil { | ||
networkName, err := s.parseNetworkName(obj.GetNetwork()) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "network %q is not valid", obj.GetNetwork()) | ||
} | ||
obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) | ||
} | ||
if err := s.storage.Create(ctx, fqn, obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
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 *GlobalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteGlobalForwardingRuleRequest) (*pb.Operation, error) { | ||
|
@@ -86,7 +127,15 @@ func (s *GlobalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteGlob | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
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) { | ||
return deleted, nil | ||
}) | ||
} | ||
|
||
func (s *GlobalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLabelsGlobalForwardingRuleRequest) (*pb.Operation, error) { | ||
|
@@ -108,7 +157,17 @@ func (s *GlobalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLabe | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("SetLabels"), | ||
User: PtrTo("[email protected]"), | ||
// SetLabels operation has EndTime in response | ||
EndTime: PtrTo("2024-04-01T12:34:56.123456Z"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
func (s *GlobalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTargetGlobalForwardingRuleRequest) (*pb.Operation, error) { | ||
|
@@ -130,7 +189,15 @@ func (s *GlobalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTarg | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("SetTarget"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
type globalForwardingRuleName struct { | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ package mockcompute | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects" | ||
|
@@ -63,13 +64,54 @@ func (s *RegionalForwardingRulesV1) Insert(ctx context.Context, req *pb.InsertFo | |
obj.CreationTimestamp = PtrTo(s.nowString()) | ||
obj.Id = &id | ||
obj.Kind = PtrTo("compute#forwardingRule") | ||
obj.LabelFingerprint = PtrTo("abcdef0123A=") | ||
// If below values are not provided by user, it appears to default by GCP | ||
if obj.LabelFingerprint == nil { | ||
obj.LabelFingerprint = PtrTo(computeFingerprint(obj)) | ||
} | ||
if obj.Fingerprint == nil { | ||
obj.Fingerprint = PtrTo(computeFingerprint(obj)) | ||
} | ||
if obj.IPProtocol == nil { | ||
obj.IPProtocol = PtrTo("TCP") | ||
} | ||
if obj.NetworkTier == nil { | ||
obj.NetworkTier = PtrTo("PREMIUM") | ||
} | ||
|
||
// pattern: \d+(?:-\d+)? | ||
if obj.PortRange != nil { | ||
r := obj.GetPortRange() | ||
token := strings.Split(r, "-") | ||
if len(token) == 1 { | ||
obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[0])) | ||
} else if len(token) == 2 { | ||
obj.PortRange = PtrTo(fmt.Sprintf("%s-%s", token[0], token[1])) | ||
} else { | ||
return nil, status.Errorf(codes.InvalidArgument, "portRange %s is not valid", obj.GetPortRange()) | ||
} | ||
} | ||
|
||
if obj.Network != nil { | ||
networkName, err := s.parseNetworkName(obj.GetNetwork()) | ||
if err != nil { | ||
return nil, status.Errorf(codes.InvalidArgument, "network %q is not valid", obj.GetNetwork()) | ||
} | ||
obj.Network = PtrTo(fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", networkName.Project.ID, networkName.Name)) | ||
} | ||
|
||
if err := s.storage.Create(ctx, fqn, obj); err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
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 *RegionalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteForwardingRuleRequest) (*pb.Operation, error) { | ||
|
@@ -86,7 +128,15 @@ func (s *RegionalForwardingRulesV1) Delete(ctx context.Context, req *pb.DeleteFo | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
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) { | ||
return deleted, nil | ||
}) | ||
} | ||
|
||
func (s *RegionalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLabelsForwardingRuleRequest) (*pb.Operation, error) { | ||
|
@@ -108,7 +158,17 @@ func (s *RegionalForwardingRulesV1) SetLabels(ctx context.Context, req *pb.SetLa | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("SetLabels"), | ||
User: PtrTo("[email protected]"), | ||
// SetLabels operation has EndTime in response | ||
EndTime: PtrTo("2024-04-01T12:34:56.123456Z"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
func (s *RegionalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTargetForwardingRuleRequest) (*pb.Operation, error) { | ||
|
@@ -130,7 +190,15 @@ func (s *RegionalForwardingRulesV1) SetTarget(ctx context.Context, req *pb.SetTa | |
return nil, err | ||
} | ||
|
||
return s.newLRO(ctx, name.Project.ID) | ||
op := &pb.Operation{ | ||
TargetId: obj.Id, | ||
TargetLink: obj.SelfLink, | ||
OperationType: PtrTo("SetTarget"), | ||
User: PtrTo("[email protected]"), | ||
} | ||
return s.startGlobalLRO(ctx, name.Project.ID, op, func() (proto.Message, error) { | ||
return obj, nil | ||
}) | ||
} | ||
|
||
type regionalForwardingRuleName struct { | ||
|
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
Oops, something went wrong.