Skip to content
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

fix: lint cyclomatic complexity #1485

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions pkg/controller/ec2/vpcpeeringconnection/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,8 @@ func (e *custom) postObserve(_ context.Context, cr *svcapitypes.VPCPeeringConnec
req := svcsdk.ModifyVpcPeeringConnectionOptionsInput{
VpcPeeringConnectionId: awsclients.String(*obj.VpcPeeringConnections[0].VpcPeeringConnectionId),
}
if cr.Spec.ForProvider.AccepterPeeringOptions != nil {
req.AccepterPeeringConnectionOptions = &svcsdk.PeeringConnectionOptionsRequest{
AllowDnsResolutionFromRemoteVpc: cr.Spec.ForProvider.AccepterPeeringOptions.AllowDNSResolutionFromRemoteVPC,
AllowEgressFromLocalClassicLinkToRemoteVpc: cr.Spec.ForProvider.AccepterPeeringOptions.AllowEgressFromLocalClassicLinkToRemoteVPC,
AllowEgressFromLocalVpcToRemoteClassicLink: cr.Spec.ForProvider.AccepterPeeringOptions.AllowEgressFromLocalVPCToRemoteClassicLink,
}
}
if cr.Spec.ForProvider.RequesterPeeringOptions != nil {
req.RequesterPeeringConnectionOptions = &svcsdk.PeeringConnectionOptionsRequest{
AllowDnsResolutionFromRemoteVpc: cr.Spec.ForProvider.RequesterPeeringOptions.AllowDNSResolutionFromRemoteVPC,
AllowEgressFromLocalClassicLinkToRemoteVpc: cr.Spec.ForProvider.RequesterPeeringOptions.AllowEgressFromLocalClassicLinkToRemoteVPC,
AllowEgressFromLocalVpcToRemoteClassicLink: cr.Spec.ForProvider.RequesterPeeringOptions.AllowEgressFromLocalVPCToRemoteClassicLink,
}
}
setAccepterRequester(&req, cr)

request, _ := e.client.ModifyVpcPeeringConnectionOptionsRequest(&req)
err := request.Send()
if err != nil {
Expand All @@ -131,20 +119,34 @@ func (e *custom) postObserve(_ context.Context, cr *svcapitypes.VPCPeeringConnec
return obs, nil
}

func setAccepterRequester(req *svcsdk.ModifyVpcPeeringConnectionOptionsInput, cr *svcapitypes.VPCPeeringConnection) {
if cr.Spec.ForProvider.AccepterPeeringOptions != nil {
req.AccepterPeeringConnectionOptions = &svcsdk.PeeringConnectionOptionsRequest{
AllowDnsResolutionFromRemoteVpc: cr.Spec.ForProvider.AccepterPeeringOptions.AllowDNSResolutionFromRemoteVPC,
AllowEgressFromLocalClassicLinkToRemoteVpc: cr.Spec.ForProvider.AccepterPeeringOptions.AllowEgressFromLocalClassicLinkToRemoteVPC,
AllowEgressFromLocalVpcToRemoteClassicLink: cr.Spec.ForProvider.AccepterPeeringOptions.AllowEgressFromLocalVPCToRemoteClassicLink,
}
}
if cr.Spec.ForProvider.RequesterPeeringOptions != nil {
req.RequesterPeeringConnectionOptions = &svcsdk.PeeringConnectionOptionsRequest{
AllowDnsResolutionFromRemoteVpc: cr.Spec.ForProvider.RequesterPeeringOptions.AllowDNSResolutionFromRemoteVPC,
AllowEgressFromLocalClassicLinkToRemoteVpc: cr.Spec.ForProvider.RequesterPeeringOptions.AllowEgressFromLocalClassicLinkToRemoteVPC,
AllowEgressFromLocalVpcToRemoteClassicLink: cr.Spec.ForProvider.RequesterPeeringOptions.AllowEgressFromLocalVPCToRemoteClassicLink,
}
}
}

func setCondition(code *svcsdk.VpcPeeringConnectionStateReason, cr *svcapitypes.VPCPeeringConnection) bool {
switch aws.StringValue(code.Code) {
case string(svcapitypes.VPCPeeringConnectionStateReasonCode_pending_acceptance):
cr.SetConditions(xpv1.Creating())
return true
case string(svcapitypes.VPCPeeringConnectionStateReasonCode_deleted):
case string(svcapitypes.VPCPeeringConnectionStateReasonCode_deleted), string(svcapitypes.VPCPeeringConnectionStateReasonCode_failed):
cr.SetConditions(xpv1.Unavailable())
return false
case string(svcapitypes.VPCPeeringConnectionStateReasonCode_active):
cr.SetConditions(xpv1.Available())
return true
case string(svcapitypes.VPCPeeringConnectionStateReasonCode_failed):
cr.SetConditions(xpv1.Unavailable())
return false
}
return false
}
Expand Down