Skip to content

Commit 9674bd2

Browse files
authoredMar 5, 2025
Remove obsolete IPRange property from EC2 (#3687)
1 parent 5d0018d commit 9674bd2

File tree

6 files changed

+18
-489
lines changed

6 files changed

+18
-489
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "EC2",
5+
"type": "patch",
6+
"changeLogMessages": [
7+
"[Breaking Change] Remove obsolete IPRanges behavior from EC2. IPV4Ranges or IPV6Ranges should be used instead."
8+
]
9+
}
10+
]
11+
}

‎sdk/src/Services/EC2/Custom/Internal/AmazonEC2PreMarshallHandler.cs

-73
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ namespace Amazon.EC2.Internal
3131
/// </summary>
3232
public class AmazonEC2PreMarshallHandler : PipelineHandler
3333
{
34-
/// <summary>
35-
/// Internal enum IpRangeValue to determine which of IpRange or Ipv4Ranges property will be used
36-
/// to make a request. If both properties are set differently, an exception will be thrown.
37-
/// </summary>
38-
internal enum IpRangeValue
39-
{
40-
Invalid,
41-
IpRanges,
42-
Ipv4Ranges
43-
}
44-
4534
private readonly AWSCredentials _credentials;
4635

4736
/// <summary>
@@ -179,68 +168,6 @@ protected void PreInvoke(IExecutionContext executionContext)
179168

180169
copySnapshotRequest.PresignedUrl = url.AbsoluteUri + authorization;
181170
}
182-
183-
var authorizeSecurityGroupEgressRequest = request as AuthorizeSecurityGroupEgressRequest;
184-
if (authorizeSecurityGroupEgressRequest != null)
185-
if (authorizeSecurityGroupEgressRequest.IsSetIpPermissions())
186-
SelectModifiedIpRange(authorizeSecurityGroupEgressRequest.IpPermissions);
187-
188-
var authorizeSecurityGroupIngressRequest = request as AuthorizeSecurityGroupIngressRequest;
189-
if (authorizeSecurityGroupIngressRequest != null)
190-
if (authorizeSecurityGroupIngressRequest.IsSetIpPermissions())
191-
SelectModifiedIpRange(authorizeSecurityGroupIngressRequest.IpPermissions);
192-
193-
var revokeSecurityGroupEgressRequest = request as RevokeSecurityGroupEgressRequest;
194-
if (revokeSecurityGroupEgressRequest != null)
195-
if (revokeSecurityGroupEgressRequest.IsSetIpPermissions())
196-
SelectModifiedIpRange(revokeSecurityGroupEgressRequest.IpPermissions);
197-
198-
var revokeSecurityGroupIngressRequest = request as RevokeSecurityGroupIngressRequest;
199-
if (revokeSecurityGroupIngressRequest != null)
200-
if (revokeSecurityGroupIngressRequest.IsSetIpPermissions())
201-
SelectModifiedIpRange(revokeSecurityGroupIngressRequest.IpPermissions);
202-
203-
var updateSecurityGroupRuleDescriptionsEgressRequest = request as UpdateSecurityGroupRuleDescriptionsEgressRequest;
204-
if (updateSecurityGroupRuleDescriptionsEgressRequest != null)
205-
if (updateSecurityGroupRuleDescriptionsEgressRequest.IsSetIpPermissions())
206-
SelectModifiedIpRange(updateSecurityGroupRuleDescriptionsEgressRequest.IpPermissions);
207-
208-
var updateSecurityGroupRuleDescriptionsIngressRequest = request as UpdateSecurityGroupRuleDescriptionsIngressRequest;
209-
if (updateSecurityGroupRuleDescriptionsIngressRequest != null)
210-
if (updateSecurityGroupRuleDescriptionsIngressRequest.IsSetIpPermissions())
211-
SelectModifiedIpRange(updateSecurityGroupRuleDescriptionsIngressRequest.IpPermissions);
212-
}
213-
214-
/// <summary>
215-
/// Analyse the user provided IpPermissions in the request to determine which of IpRanges/Ipv4ranges property will be used to make the final request.
216-
/// If both IpRanges and Ipv4Ranges are set with the same Cidr values, Ipv4Range property is selected.
217-
/// If no modifications have been made on either of IpRanges Ipv4ranges properties, Ipv4Ranges property is selected.
218-
/// If both IpRanges and Ipv4Ranges are set differently, an ArgumentException is thrown.
219-
/// </summary>
220-
/// <param name="IpPermissions"></param>
221-
private static void SelectModifiedIpRange(List<IpPermission> IpPermissions)
222-
{
223-
if (IpPermissions == null)
224-
return;
225-
226-
foreach (var ipPermission in IpPermissions)
227-
{
228-
switch (ipPermission.CanModify())
229-
{
230-
case IpRangeValue.Invalid:
231-
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.");
232-
case IpRangeValue.IpRanges:
233-
#pragma warning disable CS0618
234-
ipPermission.SelectIpRangeForMarshalling(ipPermission.IpRanges);
235-
#pragma warning restore CS0618
236-
break;
237-
case IpRangeValue.Ipv4Ranges:
238-
ipPermission.SelectIpV4RangeForMarshalling(ipPermission.Ipv4Ranges);
239-
break;
240-
default:
241-
break;
242-
}
243-
}
244171
}
245172
}
246173
}

‎sdk/src/Services/EC2/Custom/Internal/AmazonEC2ResponseHandler.cs

-113
Original file line numberDiff line numberDiff line change
@@ -118,119 +118,6 @@ protected virtual void PostInvoke(IExecutionContext executionContext)
118118
PopulateReservationSecurityGroupNames(rir.Reservation);
119119
return;
120120
}
121-
122-
// In case of DescribeSecurityGroupsResponse type, the Ipv4Ranges values for each of the retured IpPermissions is unmarshalled
123-
// 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.
124-
var describeSecurityGroupsResponse = response as DescribeSecurityGroupsResponse;
125-
if(describeSecurityGroupsResponse!=null)
126-
{
127-
if(describeSecurityGroupsResponse.IsSetSecurityGroups())
128-
{
129-
foreach (var securityGroup in describeSecurityGroupsResponse.SecurityGroups)
130-
{
131-
if (securityGroup.IsSetIpPermissions())
132-
{
133-
SetIpRangesProperty(securityGroup.IpPermissions);
134-
}
135-
else if(securityGroup.IsSetIpPermissionsEgress())
136-
{
137-
SetIpRangesProperty(securityGroup.IpPermissionsEgress);
138-
}
139-
}
140-
}
141-
return;
142-
}
143-
144-
var authorizeSecurityGroupEgressRequest = request as AuthorizeSecurityGroupEgressRequest;
145-
if (authorizeSecurityGroupEgressRequest != null)
146-
if (authorizeSecurityGroupEgressRequest.IsSetIpPermissions())
147-
{
148-
RestoreRequestIpPermissions(authorizeSecurityGroupEgressRequest.IpPermissions);
149-
return;
150-
}
151-
152-
var authorizeSecurityGroupIngressRequest = request as AuthorizeSecurityGroupIngressRequest;
153-
if (authorizeSecurityGroupIngressRequest != null)
154-
if (authorizeSecurityGroupIngressRequest.IsSetIpPermissions())
155-
{
156-
RestoreRequestIpPermissions(authorizeSecurityGroupIngressRequest.IpPermissions);
157-
return;
158-
}
159-
160-
161-
var revokeSecurityGroupEgressRequest = request as RevokeSecurityGroupEgressRequest;
162-
if (revokeSecurityGroupEgressRequest != null)
163-
if (revokeSecurityGroupEgressRequest.IsSetIpPermissions())
164-
{
165-
RestoreRequestIpPermissions(revokeSecurityGroupEgressRequest.IpPermissions);
166-
return;
167-
}
168-
169-
170-
var revokeSecurityGroupIngressRequest = request as RevokeSecurityGroupIngressRequest;
171-
if (revokeSecurityGroupIngressRequest != null)
172-
if (revokeSecurityGroupIngressRequest.IsSetIpPermissions())
173-
{
174-
RestoreRequestIpPermissions(revokeSecurityGroupIngressRequest.IpPermissions);
175-
return;
176-
}
177-
178-
179-
var updateSecurityGroupRuleDescriptionsEgressRequest = request as UpdateSecurityGroupRuleDescriptionsEgressRequest;
180-
if (updateSecurityGroupRuleDescriptionsEgressRequest != null)
181-
if (updateSecurityGroupRuleDescriptionsEgressRequest.IsSetIpPermissions())
182-
{
183-
RestoreRequestIpPermissions(updateSecurityGroupRuleDescriptionsEgressRequest.IpPermissions);
184-
return;
185-
}
186-
187-
188-
var updateSecurityGroupRuleDescriptionsIngressRequest = request as UpdateSecurityGroupRuleDescriptionsIngressRequest;
189-
if (updateSecurityGroupRuleDescriptionsIngressRequest != null)
190-
if (updateSecurityGroupRuleDescriptionsIngressRequest.IsSetIpPermissions())
191-
{
192-
RestoreRequestIpPermissions(updateSecurityGroupRuleDescriptionsIngressRequest.IpPermissions);
193-
return;
194-
}
195-
196-
}
197-
198-
/// <summary>
199-
/// Cidr values from Ipv4Ranges is extracted and set on IpRanges.
200-
/// The internal dictionary collection is also set to the Ipv4Range values.
201-
/// </summary>
202-
/// <param name="ipPermissions"></param>
203-
private static void SetIpRangesProperty(List<IpPermission> ipPermissions)
204-
{
205-
foreach (var ipPermission in ipPermissions)
206-
{
207-
if (ipPermission.Ipv4Ranges == null)
208-
{
209-
continue;
210-
}
211-
212-
#pragma warning disable CS0612,CS0618
213-
ipPermission.IpRanges = ipPermission.Ipv4Ranges.Select(i => i.CidrIp).ToList();
214-
#pragma warning restore CS0612,CS0618
215-
ipPermission.CopyIpv4RangesToInternalCollection(ipPermission.Ipv4Ranges);
216-
}
217-
}
218-
219-
/// <summary>
220-
/// The original values used by the customer in the Ipv4Ranges property on the request
221-
/// object is restored. This is done when the customer is using the deprecated IpRanges property.
222-
/// </summary>
223-
/// <param name="IpPermissions"></param>
224-
private static void RestoreRequestIpPermissions(List<IpPermission> IpPermissions)
225-
{
226-
foreach (var ipPermission in IpPermissions)
227-
{
228-
if (ipPermission.RestoreOldIpV4Range)
229-
{
230-
ipPermission.Ipv4Ranges = ipPermission.PreIpv4Ranges;
231-
ipPermission.RestoreOldIpV4Range = false;
232-
}
233-
}
234121
}
235122

236123
private static void PopulateLaunchSpecificationSecurityGroupNames(LaunchSpecification launchSpecification)

‎sdk/src/Services/EC2/Custom/Model/IpPermission.cs

-169
This file was deleted.

‎sdk/src/Services/EC2/Custom/Util/_bcl/VPCUtilities.bcl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public static LaunchVPCWithPublicAndPrivateSubnetsResponse LaunchVPCWithPublicAn
287287
IpPermission spec = new IpPermission
288288
{
289289
IpProtocol = "-1",
290-
IpRanges = new List<string>{ "0.0.0.0/0"},
290+
Ipv4Ranges = new List<IpRange> { new IpRange { CidrIp = "0.0.0.0/0", Description = "All Ip ranges"} },
291291
UserIdGroupPairs = new List<UserIdGroupPair>() { new UserIdGroupPair() { GroupId = groupId } }
292292
};
293293
#pragma warning restore CS0612,CS0618

0 commit comments

Comments
 (0)
Failed to load comments.