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

Remove obsolete IPRange property from EC2 #3687

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Changes from 2 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
11 changes: 11 additions & 0 deletions generator/.DevConfigs/a769f591-c10f-45e6-94ec-f49295484df3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"services": [
{
"serviceName": "EC2",
"type": "patch",
"changeLogMessages": [
"[Breaking Change] Remove obsolete IPRanges behavior from EC2. IPV4Ranges or IPV6Ranges should be used instead."
]
}
]
}
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ public class AmazonEC2PreMarshallHandler : PipelineHandler
internal enum IpRangeValue
{
Invalid,
IpRanges,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't remove this whole enum since we only have one property now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point removed.

Ipv4Ranges
}

@@ -225,21 +224,7 @@ private static void SelectModifiedIpRange(List<IpPermission> IpPermissions)

foreach (var ipPermission in IpPermissions)
{
switch (ipPermission.CanModify())
{
case IpRangeValue.Invalid:
throw new ArgumentException("Cannot set values for both Ipv4Ranges and IpRanges properties on the IpPermission type which is part of the request. Consider using only Ipv4Ranges as IpRanges has been marked obsolete.");
case IpRangeValue.IpRanges:
#pragma warning disable CS0618
ipPermission.SelectIpRangeForMarshalling(ipPermission.IpRanges);
#pragma warning restore CS0618
break;
case IpRangeValue.Ipv4Ranges:
ipPermission.SelectIpV4RangeForMarshalling(ipPermission.Ipv4Ranges);
break;
default:
break;
}
ipPermission.SelectIpV4RangeForMarshalling(ipPermission.Ipv4Ranges);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should be able to refactor EC2 to not even need this method since we only have one property now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I removed a bunch of related code that that was accounting for the old IpRanges property.

}
}
}
Original file line number Diff line number Diff line change
@@ -209,9 +209,6 @@ private static void SetIpRangesProperty(List<IpPermission> ipPermissions)
continue;
}

#pragma warning disable CS0612,CS0618
ipPermission.IpRanges = ipPermission.Ipv4Ranges.Select(i => i.CidrIp).ToList();
#pragma warning restore CS0612,CS0618
ipPermission.CopyIpv4RangesToInternalCollection(ipPermission.Ipv4Ranges);
}
}
84 changes: 0 additions & 84 deletions sdk/src/Services/EC2/Custom/Model/IpPermission.cs
Original file line number Diff line number Diff line change
@@ -32,28 +32,9 @@ namespace Amazon.EC2.Model
/// </summary>
public partial class IpPermission
{
private List<string> _ipRanges = new List<string>();
private Dictionary<string, IpRange> _internalIpRangesCollection = new Dictionary<string, IpRange>();
private bool _clearIpv4Ranges = false;
private List<IpRange> _preIpv4Ranges = new List<IpRange>();
/// <summary>
/// Gets and sets the property IpRanges.
/// <para>
/// One or more IPv4 ranges.
/// </para>
/// </summary>
[Obsolete("Deprecated in favor of Ipv4Ranges. Setting this property instead of Ipv4Ranges for UpdateSecurityGroupRuleDescriptionsIngressRequest results in no change in the CidrIp's description. An argument exception is thrown if both IpRanges and Ipv4Ranges properties are set in the IpPermission request object.")]
public List<string> IpRanges
{
get { return this._ipRanges; }
set { this._ipRanges = value; }
}

// Check to see if IpRanges property is set
internal bool IsSetIpRanges()
{
return this._ipRanges != null && this._ipRanges.Count > 0;
}

/// <summary>
/// Internal property to store the original Ipv4Range values, before they are overwritten.
@@ -65,44 +46,6 @@ internal List<IpRange> PreIpv4Ranges
set { _preIpv4Ranges = value; }
}

/// <summary>
/// This method decides which of IpRanges/Ipv4Ranges property values will be used to make the 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 with different CIDRs the method returns IpRangeValue.Invalid. The AmazonEC2PreMarshallHandler
/// is main caller of this method which throws an ArgumentException exception if IpRangeValue.Invalid is returned.
/// </summary>
/// <returns></returns>
internal IpRangeValue CanModify()
{
#pragma warning disable CS0618
if (this._ipv4Ranges != null && this.IpRanges == null)
return IpRangeValue.Ipv4Ranges;
else if (this.IpRanges != null && this._ipv4Ranges == null)
return IpRangeValue.IpRanges;
else if (this._ipv4Ranges == null && this.IpRanges == null)
return IpRangeValue.Ipv4Ranges; // This is the no IP case so defaulting to the non obsolete property.

List<string> ipv4Ranges = this._ipv4Ranges?.Select(p => p.CidrIp).ToList() ?? new List<string>();
var equallyModified = !(ipv4Ranges.Except(this.IpRanges).ToList().Any() || this.IpRanges.Except(ipv4Ranges).ToList().Any());

if (equallyModified)
return IpRangeValue.Ipv4Ranges;

List<string> internalRanges = this._internalIpRangesCollection.Select(p => p.Value.CidrIp).ToList();

var ipRangeModified = internalRanges.Except(this.IpRanges).ToList().Any() || this.IpRanges.Except(internalRanges).ToList().Any();
var iv4RangeModified = internalRanges.Except(ipv4Ranges).ToList().Any() || ipv4Ranges.Except(internalRanges).ToList().Any();

if (ipRangeModified && iv4RangeModified)
return IpRangeValue.Invalid;
else if (ipRangeModified)
return IpRangeValue.IpRanges;
else
return IpRangeValue.Ipv4Ranges;
#pragma warning restore CS0618
}

/// <summary>
/// This method is used when the customer is using the Ipv4Ranges property to make the request.
/// The internal dictionary collection is updated to latest values in the Ipv4Ranges property.
@@ -128,33 +71,6 @@ internal void CopyIpv4RangesToInternalCollection(List<IpRange> list)
}
}

/// <summary>
/// This method is used when the customer is using the deprecated IpRanges property to make the request.
/// The Ipv4Ranges property is updated to the IpRanges property values.
/// The internal dictionary collection is updated to latest values in the Ipv4Ranges property.
/// Inorder to ensure that the added customer descriptions are not lost, a CidrIp comparison is made on the
/// internal dictionary and if a description exists for the said CidrIp, it is retained.
/// </summary>
/// <param name="list"></param>
internal void SelectIpRangeForMarshalling(List<string> list)
{
var tempInternalIpRangesCollection = new Dictionary<string, IpRange>();
foreach (var iprange in list)
{
IpRange value = new IpRange();
if (_internalIpRangesCollection.TryGetValue(iprange, out value))
{
tempInternalIpRangesCollection.Add(iprange, value);
}
else
tempInternalIpRangesCollection.Add(iprange, new IpRange { CidrIp = iprange });
}
_internalIpRangesCollection = tempInternalIpRangesCollection;
this.PreIpv4Ranges = this.Ipv4Ranges;
this.Ipv4Ranges = _internalIpRangesCollection.Select(p => p.Value).ToList();
this.RestoreOldIpV4Range = true;
}

/// <summary>
/// Flag to indicate if Ipv4Ranges property has been overwritten.
/// This property will be used to restore the Ipv4Ranges to its original value,
2 changes: 1 addition & 1 deletion sdk/src/Services/EC2/Custom/Util/_bcl/VPCUtilities.bcl.cs
Original file line number Diff line number Diff line change
@@ -287,7 +287,7 @@ public static LaunchVPCWithPublicAndPrivateSubnetsResponse LaunchVPCWithPublicAn
IpPermission spec = new IpPermission
{
IpProtocol = "-1",
IpRanges = new List<string>{ "0.0.0.0/0"},
Ipv4Ranges = new List<IpRange> { new IpRange { CidrIp = "0.0.0.0/0", Description = "All Ip ranges"} },
UserIdGroupPairs = new List<UserIdGroupPair>() { new UserIdGroupPair() { GroupId = groupId } }
};
#pragma warning restore CS0612,CS0618
Loading
Oops, something went wrong.