Skip to content

Commit

Permalink
fix: lint cyclomatic complexity (#1485)
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Dauby <romain.dauby@gmail.com>

Signed-off-by: Romain Dauby <romain.dauby@gmail.com>
  • Loading branch information
r0mdau committed Sep 20, 2022
1 parent ffae9f2 commit 50cc61b
Showing 1 changed file with 20 additions and 18 deletions.
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

0 comments on commit 50cc61b

Please sign in to comment.