Skip to content

Commit

Permalink
Additional refactoring to remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrsongg committed Mar 4, 2025
1 parent c732b06 commit a263a2b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,54 +178,6 @@ protected void PreInvoke(IExecutionContext executionContext)

copySnapshotRequest.PresignedUrl = url.AbsoluteUri + authorization;
}

var authorizeSecurityGroupEgressRequest = request as AuthorizeSecurityGroupEgressRequest;
if (authorizeSecurityGroupEgressRequest != null)
if (authorizeSecurityGroupEgressRequest.IsSetIpPermissions())
SelectModifiedIpRange(authorizeSecurityGroupEgressRequest.IpPermissions);

var authorizeSecurityGroupIngressRequest = request as AuthorizeSecurityGroupIngressRequest;
if (authorizeSecurityGroupIngressRequest != null)
if (authorizeSecurityGroupIngressRequest.IsSetIpPermissions())
SelectModifiedIpRange(authorizeSecurityGroupIngressRequest.IpPermissions);

var revokeSecurityGroupEgressRequest = request as RevokeSecurityGroupEgressRequest;
if (revokeSecurityGroupEgressRequest != null)
if (revokeSecurityGroupEgressRequest.IsSetIpPermissions())
SelectModifiedIpRange(revokeSecurityGroupEgressRequest.IpPermissions);

var revokeSecurityGroupIngressRequest = request as RevokeSecurityGroupIngressRequest;
if (revokeSecurityGroupIngressRequest != null)
if (revokeSecurityGroupIngressRequest.IsSetIpPermissions())
SelectModifiedIpRange(revokeSecurityGroupIngressRequest.IpPermissions);

var updateSecurityGroupRuleDescriptionsEgressRequest = request as UpdateSecurityGroupRuleDescriptionsEgressRequest;
if (updateSecurityGroupRuleDescriptionsEgressRequest != null)
if (updateSecurityGroupRuleDescriptionsEgressRequest.IsSetIpPermissions())
SelectModifiedIpRange(updateSecurityGroupRuleDescriptionsEgressRequest.IpPermissions);

var updateSecurityGroupRuleDescriptionsIngressRequest = request as UpdateSecurityGroupRuleDescriptionsIngressRequest;
if (updateSecurityGroupRuleDescriptionsIngressRequest != null)
if (updateSecurityGroupRuleDescriptionsIngressRequest.IsSetIpPermissions())
SelectModifiedIpRange(updateSecurityGroupRuleDescriptionsIngressRequest.IpPermissions);
}

/// <summary>
/// Analyse the user provided IpPermissions in the request to determine which of IpRanges/Ipv4ranges property will be used to make the final request.
/// If both IpRanges and Ipv4Ranges are set with the same Cidr values, Ipv4Range property is selected.
/// If no modifications have been made on either of IpRanges Ipv4ranges properties, Ipv4Ranges property is selected.
/// If both IpRanges and Ipv4Ranges are set differently, an ArgumentException is thrown.
/// </summary>
/// <param name="IpPermissions"></param>
private static void SelectModifiedIpRange(List<IpPermission> IpPermissions)
{
if (IpPermissions == null)
return;

foreach (var ipPermission in IpPermissions)
{
ipPermission.SelectIpV4RangeForMarshalling(ipPermission.Ipv4Ranges);
}
}
}
}
110 changes: 0 additions & 110 deletions sdk/src/Services/EC2/Custom/Internal/AmazonEC2ResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,116 +118,6 @@ protected virtual void PostInvoke(IExecutionContext executionContext)
PopulateReservationSecurityGroupNames(rir.Reservation);
return;
}

// In case of DescribeSecurityGroupsResponse type, the Ipv4Ranges values for each of the retured IpPermissions is unmarshalled
// and the extracted Cidr values is set on the IpRanges property of IpPermission. If the customer is using IpRanges, then they will not be broken.
var describeSecurityGroupsResponse = response as DescribeSecurityGroupsResponse;
if(describeSecurityGroupsResponse!=null)
{
if(describeSecurityGroupsResponse.IsSetSecurityGroups())
{
foreach (var securityGroup in describeSecurityGroupsResponse.SecurityGroups)
{
if (securityGroup.IsSetIpPermissions())
{
SetIpRangesProperty(securityGroup.IpPermissions);
}
else if(securityGroup.IsSetIpPermissionsEgress())
{
SetIpRangesProperty(securityGroup.IpPermissionsEgress);
}
}
}
return;
}

var authorizeSecurityGroupEgressRequest = request as AuthorizeSecurityGroupEgressRequest;
if (authorizeSecurityGroupEgressRequest != null)
if (authorizeSecurityGroupEgressRequest.IsSetIpPermissions())
{
RestoreRequestIpPermissions(authorizeSecurityGroupEgressRequest.IpPermissions);
return;
}

var authorizeSecurityGroupIngressRequest = request as AuthorizeSecurityGroupIngressRequest;
if (authorizeSecurityGroupIngressRequest != null)
if (authorizeSecurityGroupIngressRequest.IsSetIpPermissions())
{
RestoreRequestIpPermissions(authorizeSecurityGroupIngressRequest.IpPermissions);
return;
}


var revokeSecurityGroupEgressRequest = request as RevokeSecurityGroupEgressRequest;
if (revokeSecurityGroupEgressRequest != null)
if (revokeSecurityGroupEgressRequest.IsSetIpPermissions())
{
RestoreRequestIpPermissions(revokeSecurityGroupEgressRequest.IpPermissions);
return;
}


var revokeSecurityGroupIngressRequest = request as RevokeSecurityGroupIngressRequest;
if (revokeSecurityGroupIngressRequest != null)
if (revokeSecurityGroupIngressRequest.IsSetIpPermissions())
{
RestoreRequestIpPermissions(revokeSecurityGroupIngressRequest.IpPermissions);
return;
}


var updateSecurityGroupRuleDescriptionsEgressRequest = request as UpdateSecurityGroupRuleDescriptionsEgressRequest;
if (updateSecurityGroupRuleDescriptionsEgressRequest != null)
if (updateSecurityGroupRuleDescriptionsEgressRequest.IsSetIpPermissions())
{
RestoreRequestIpPermissions(updateSecurityGroupRuleDescriptionsEgressRequest.IpPermissions);
return;
}


var updateSecurityGroupRuleDescriptionsIngressRequest = request as UpdateSecurityGroupRuleDescriptionsIngressRequest;
if (updateSecurityGroupRuleDescriptionsIngressRequest != null)
if (updateSecurityGroupRuleDescriptionsIngressRequest.IsSetIpPermissions())
{
RestoreRequestIpPermissions(updateSecurityGroupRuleDescriptionsIngressRequest.IpPermissions);
return;
}

}

/// <summary>
/// Cidr values from Ipv4Ranges is extracted and set on IpRanges.
/// The internal dictionary collection is also set to the Ipv4Range values.
/// </summary>
/// <param name="ipPermissions"></param>
private static void SetIpRangesProperty(List<IpPermission> ipPermissions)
{
foreach (var ipPermission in ipPermissions)
{
if (ipPermission.Ipv4Ranges == null)
{
continue;
}

ipPermission.CopyIpv4RangesToInternalCollection(ipPermission.Ipv4Ranges);
}
}

/// <summary>
/// The original values used by the customer in the Ipv4Ranges property on the request
/// object is restored. This is done when the customer is using the deprecated IpRanges property.
/// </summary>
/// <param name="IpPermissions"></param>
private static void RestoreRequestIpPermissions(List<IpPermission> IpPermissions)
{
foreach (var ipPermission in IpPermissions)
{
if (ipPermission.RestoreOldIpV4Range)
{
ipPermission.Ipv4Ranges = ipPermission.PreIpv4Ranges;
ipPermission.RestoreOldIpV4Range = false;
}
}
}

private static void PopulateLaunchSpecificationSecurityGroupNames(LaunchSpecification launchSpecification)
Expand Down
85 changes: 0 additions & 85 deletions sdk/src/Services/EC2/Custom/Model/IpPermission.cs

This file was deleted.

0 comments on commit a263a2b

Please sign in to comment.