mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(ec2): validate CreateSecurityGroup required parameters (#3888)
This commit is contained in:
1 parent
d348763345
commit
37ac2505e8
3 files changed
+44
-3
No files matched your search
@@ -2902,8 +2902,8 @@ public class Ec2QueryHandler {
|
||||
// ─── Security Group handlers ───────────────────────────────────────────────
|
||||
|
||||
private Response handleCreateSecurityGroup(MultivaluedMap<String, String> p, String region) {
|
||||
String groupName = p.getFirst("GroupName");
|
||||
String description = p.getFirst("GroupDescription");
|
||||
String groupName = requireParameter(p, "GroupName");
|
||||
String description = requireParameter(p, "GroupDescription");
|
||||
String vpcId = p.getFirst("VpcId");
|
||||
SecurityGroup sg = service.createSecurityGroup(region, groupName, description, vpcId);
|
||||
applyResourceTags(p, region, "security-group", sg.getGroupId());
|
||||
@@ -2916,6 +2916,17 @@ public class Ec2QueryHandler {
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private static String requireParameter(MultivaluedMap<String, String> params, String parameterName) {
|
||||
String value = params.getFirst(parameterName);
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new AwsException(
|
||||
"MissingParameter",
|
||||
"The request must contain the parameter " + parameterName,
|
||||
400);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private Response handleDescribeSecurityGroups(MultivaluedMap<String, String> p, String region) {
|
||||
List<String> groupIds = getList(p, "GroupId");
|
||||
List<String> groupNames = getList(p, "GroupName");
|
||||
|
||||
@@ -4395,7 +4395,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
// Check duplicate
|
||||
String finalVpcId = vpcId;
|
||||
boolean exists = securityGroups.scan(k -> true).stream()
|
||||
.anyMatch(sg -> sg.getRegion().equals(region) && sg.getGroupName().equals(groupName)
|
||||
.anyMatch(sg -> sg.getRegion().equals(region) && Objects.equals(sg.getGroupName(), groupName)
|
||||
&& finalVpcId.equals(sg.getVpcId()));
|
||||
if (exists) {
|
||||
throw new AwsException("InvalidGroup.Duplicate", "The security group '" + groupName + "' already exists", 400);
|
||||
|
||||
Reference in new issue
Block a user