mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(ec2): support registered images and snapshots (#1601)
* feat(ec2): support registered images and snapshots * fix(ec2): scope self-owned image matches
This commit is contained in:
1 parent
c233eb4891
commit
2a6cf1c147
10 files changed
+704
-3
No files matched your search
@@ -151,7 +151,7 @@ public class AwsQueryController {
|
||||
"DescribeSecurityGroupRules", "ModifySecurityGroupRules",
|
||||
"UpdateSecurityGroupRuleDescriptionsIngress", "UpdateSecurityGroupRuleDescriptionsEgress",
|
||||
"CreateKeyPair", "DescribeKeyPairs", "DeleteKeyPair", "ImportKeyPair",
|
||||
"DescribeImages",
|
||||
"DescribeImages", "RegisterImage", "DescribeSnapshots",
|
||||
"CreateTags", "DeleteTags", "DescribeTags",
|
||||
"CreateInternetGateway", "DescribeInternetGateways", "DeleteInternetGateway",
|
||||
"AttachInternetGateway", "DetachInternetGateway",
|
||||
|
||||
@@ -98,6 +98,8 @@ public class Ec2QueryHandler {
|
||||
case "ImportKeyPair" -> handleImportKeyPair(params, region);
|
||||
// AMIs
|
||||
case "DescribeImages" -> handleDescribeImages(params, region);
|
||||
case "RegisterImage" -> handleRegisterImage(params, region);
|
||||
case "DescribeSnapshots" -> handleDescribeSnapshots(params, region);
|
||||
// Tags
|
||||
case "CreateTags" -> handleCreateTags(params, region);
|
||||
case "DeleteTags" -> handleDeleteTags(params, region);
|
||||
@@ -199,6 +201,14 @@ public class Ec2QueryHandler {
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String> getList(MultivaluedMap<String, String> p, String... prefixes) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String prefix : prefixes) {
|
||||
result.addAll(getList(p, prefix));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int parseIntParam(MultivaluedMap<String, String> p, String name, int defaultValue) {
|
||||
String val = p.getFirst(name);
|
||||
if (val == null || val.isEmpty()) return defaultValue;
|
||||
@@ -226,6 +236,64 @@ public class Ec2QueryHandler {
|
||||
return filters;
|
||||
}
|
||||
|
||||
private List<BlockDeviceMapping> parseBlockDeviceMappings(MultivaluedMap<String, String> p) {
|
||||
List<BlockDeviceMapping> mappings = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
String prefix = "BlockDeviceMapping." + i;
|
||||
String deviceName = p.getFirst(prefix + ".DeviceName");
|
||||
String snapshotId = p.getFirst(prefix + ".Ebs.SnapshotId");
|
||||
String volumeSize = p.getFirst(prefix + ".Ebs.VolumeSize");
|
||||
String volumeType = p.getFirst(prefix + ".Ebs.VolumeType");
|
||||
String deleteOnTermination = p.getFirst(prefix + ".Ebs.DeleteOnTermination");
|
||||
String encrypted = p.getFirst(prefix + ".Ebs.Encrypted");
|
||||
boolean hasEbs = snapshotId != null || volumeSize != null || volumeType != null
|
||||
|| deleteOnTermination != null || encrypted != null;
|
||||
if (deviceName == null && !hasEbs) {
|
||||
break;
|
||||
}
|
||||
if (deviceName == null || deviceName.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"BlockDeviceMapping." + i + ".DeviceName is required.", 400);
|
||||
}
|
||||
BlockDeviceMapping mapping = new BlockDeviceMapping();
|
||||
mapping.setDeviceName(deviceName);
|
||||
EbsBlockDevice ebs = new EbsBlockDevice();
|
||||
ebs.setSnapshotId(snapshotId);
|
||||
ebs.setVolumeSize(parseOptionalInt(volumeSize, prefix + ".Ebs.VolumeSize"));
|
||||
ebs.setVolumeType(volumeType);
|
||||
ebs.setDeleteOnTermination(parseOptionalBoolean(deleteOnTermination,
|
||||
prefix + ".Ebs.DeleteOnTermination"));
|
||||
ebs.setEncrypted(parseOptionalBoolean(encrypted, prefix + ".Ebs.Encrypted"));
|
||||
mapping.setEbs(ebs);
|
||||
mappings.add(mapping);
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
private Integer parseOptionalInt(String value, String name) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("InvalidParameterValue", name + " is not a valid integer.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean parseOptionalBoolean(String value, String name) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if ("true".equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
if ("false".equalsIgnoreCase(value)) {
|
||||
return false;
|
||||
}
|
||||
throw new AwsException("InvalidParameterValue", name + " is not a valid boolean.", 400);
|
||||
}
|
||||
|
||||
private List<IpPermission> parseIpPermissions(MultivaluedMap<String, String> p, String prefix) {
|
||||
List<IpPermission> perms = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
@@ -1184,12 +1252,45 @@ public class Ec2QueryHandler {
|
||||
.elem("hypervisor", img.getHypervisor())
|
||||
.elem("imageOwnerAlias", img.getImageOwnerAlias())
|
||||
.elem("creationDate", img.getCreationDate())
|
||||
.raw(blockDeviceMappingXml(img.getBlockDeviceMappings()))
|
||||
.end("item");
|
||||
}
|
||||
xml.end("imagesSet").end("DescribeImagesResponse");
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private Response handleRegisterImage(MultivaluedMap<String, String> p, String region) {
|
||||
Image image = service.registerImage(
|
||||
region,
|
||||
p.getFirst("Name"),
|
||||
p.getFirst("Description"),
|
||||
p.getFirst("Architecture"),
|
||||
p.getFirst("RootDeviceName"),
|
||||
parseBlockDeviceMappings(p));
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("RegisterImageResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.elem("imageId", image.getImageId())
|
||||
.end("RegisterImageResponse");
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private Response handleDescribeSnapshots(MultivaluedMap<String, String> p, String region) {
|
||||
List<String> ids = getList(p, "SnapshotId");
|
||||
List<String> owners = getList(p, "Owner", "OwnerId", "OwnerIds");
|
||||
Map<String, List<String>> filters = getFilters(p);
|
||||
List<Snapshot> snapshots = service.describeSnapshots(region, ids, owners, filters);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("DescribeSnapshotsResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.start("snapshotSet");
|
||||
for (Snapshot snapshot : snapshots) {
|
||||
xml.start("item").raw(snapshotXml(snapshot)).end("item");
|
||||
}
|
||||
xml.end("snapshotSet").end("DescribeSnapshotsResponse");
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
// ─── Tag handlers ─────────────────────────────────────────────────────────
|
||||
|
||||
private Response handleCreateTags(MultivaluedMap<String, String> p, String region) {
|
||||
@@ -2314,6 +2415,61 @@ public class Ec2QueryHandler {
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
private String blockDeviceMappingXml(List<BlockDeviceMapping> mappings) {
|
||||
if (mappings == null || mappings.isEmpty()) {
|
||||
return "<blockDeviceMapping/>";
|
||||
}
|
||||
XmlBuilder xml = new XmlBuilder().start("blockDeviceMapping");
|
||||
for (BlockDeviceMapping mapping : mappings) {
|
||||
xml.start("item")
|
||||
.elem("deviceName", mapping.getDeviceName());
|
||||
EbsBlockDevice ebs = mapping.getEbs();
|
||||
if (ebs != null) {
|
||||
xml.start("ebs");
|
||||
if (ebs.getSnapshotId() != null) {
|
||||
xml.elem("snapshotId", ebs.getSnapshotId());
|
||||
}
|
||||
if (ebs.getVolumeSize() != null) {
|
||||
xml.elem("volumeSize", String.valueOf(ebs.getVolumeSize()));
|
||||
}
|
||||
if (ebs.getVolumeType() != null) {
|
||||
xml.elem("volumeType", ebs.getVolumeType());
|
||||
}
|
||||
if (ebs.getDeleteOnTermination() != null) {
|
||||
xml.elem("deleteOnTermination", String.valueOf(ebs.getDeleteOnTermination()));
|
||||
}
|
||||
if (ebs.getEncrypted() != null) {
|
||||
xml.elem("encrypted", String.valueOf(ebs.getEncrypted()));
|
||||
}
|
||||
xml.end("ebs");
|
||||
}
|
||||
xml.end("item");
|
||||
}
|
||||
xml.end("blockDeviceMapping");
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
private String snapshotXml(Snapshot snapshot) {
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.elem("snapshotId", snapshot.getSnapshotId())
|
||||
.elem("ownerId", snapshot.getOwnerId())
|
||||
.elem("status", snapshot.getState())
|
||||
.elem("progress", snapshot.getProgress())
|
||||
.elem("encrypted", String.valueOf(snapshot.isEncrypted()))
|
||||
.elem("description", snapshot.getDescription());
|
||||
if (snapshot.getVolumeId() != null) {
|
||||
xml.elem("volumeId", snapshot.getVolumeId());
|
||||
}
|
||||
if (snapshot.getVolumeSize() != null) {
|
||||
xml.elem("volumeSize", String.valueOf(snapshot.getVolumeSize()));
|
||||
}
|
||||
if (snapshot.getStartTime() != null) {
|
||||
xml.elem("startTime", ISO_FMT.format(snapshot.getStartTime()));
|
||||
}
|
||||
xml.raw(tagSetXml(snapshot.getTags()));
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
// ─── Volume handlers ──────────────────────────────────────────────────────
|
||||
|
||||
private Response handleCreateVolume(MultivaluedMap<String, String> p, String region) {
|
||||
|
||||
@@ -29,6 +29,8 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Address;
|
||||
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
|
||||
import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
|
||||
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
|
||||
import io.github.hectorvent.floci.services.ec2.portforward.Ec2PortForwardManager;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Image;
|
||||
@@ -59,6 +61,7 @@ import io.github.hectorvent.floci.services.ec2.model.RouteTable;
|
||||
import io.github.hectorvent.floci.services.ec2.model.RouteTableAssociation;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
|
||||
import io.github.hectorvent.floci.services.ec2.model.SecurityGroupRule;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Snapshot;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Subnet;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Tag;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Volume;
|
||||
@@ -100,6 +103,8 @@ public class Ec2Service {
|
||||
private final StorageBackend<String, Address> addresses;
|
||||
private final StorageBackend<String, Instance> instances;
|
||||
private final StorageBackend<String, Volume> volumes;
|
||||
private final StorageBackend<String, Image> registeredImages;
|
||||
private final StorageBackend<String, Snapshot> snapshots;
|
||||
private final StorageBackend<String, LaunchTemplate> launchTemplates;
|
||||
private final StorageBackend<String, VpcEndpoint> vpcEndpoints;
|
||||
private final StorageBackend<String, NatGateway> natGateways;
|
||||
@@ -127,6 +132,8 @@ public class Ec2Service {
|
||||
storageFactory.create("ec2", "ec2-addresses.json", new TypeReference<Map<String, Address>>() {}),
|
||||
storageFactory.create("ec2", "ec2-instances.json", new TypeReference<Map<String, Instance>>() {}),
|
||||
storageFactory.create("ec2", "ec2-volumes.json", new TypeReference<Map<String, Volume>>() {}),
|
||||
storageFactory.create("ec2", "ec2-registered-images.json", new TypeReference<Map<String, Image>>() {}),
|
||||
storageFactory.create("ec2", "ec2-snapshots.json", new TypeReference<Map<String, Snapshot>>() {}),
|
||||
storageFactory.create("ec2", "ec2-launch-templates.json", new TypeReference<Map<String, LaunchTemplate>>() {}),
|
||||
storageFactory.create("ec2", "ec2-vpc-endpoints.json", new TypeReference<Map<String, VpcEndpoint>>() {}),
|
||||
storageFactory.create("ec2", "ec2-nat-gateways.json", new TypeReference<Map<String, NatGateway>>() {}),
|
||||
@@ -150,6 +157,8 @@ public class Ec2Service {
|
||||
StorageBackend<String, Address> addresses,
|
||||
StorageBackend<String, Instance> instances,
|
||||
StorageBackend<String, Volume> volumes,
|
||||
StorageBackend<String, Image> registeredImages,
|
||||
StorageBackend<String, Snapshot> snapshots,
|
||||
StorageBackend<String, LaunchTemplate> launchTemplates,
|
||||
StorageBackend<String, VpcEndpoint> vpcEndpoints,
|
||||
StorageBackend<String, NatGateway> natGateways,
|
||||
@@ -173,6 +182,8 @@ public class Ec2Service {
|
||||
this.addresses = addresses;
|
||||
this.instances = instances;
|
||||
this.volumes = volumes;
|
||||
this.registeredImages = registeredImages;
|
||||
this.snapshots = snapshots;
|
||||
this.launchTemplates = launchTemplates;
|
||||
this.vpcEndpoints = vpcEndpoints;
|
||||
this.natGateways = natGateways;
|
||||
@@ -1531,13 +1542,80 @@ public class Ec2Service {
|
||||
}
|
||||
|
||||
public List<Image> describeImages(String region, List<String> imageIds, List<String> owners, Map<String, List<String>> filters) {
|
||||
return imageCatalog.images().stream()
|
||||
List<Image> catalogImages = imageCatalog.images().stream()
|
||||
.filter(Ec2ImageCatalog.CatalogImage::advertised)
|
||||
.filter(img -> img.matchesIdOrAlias(imageIds))
|
||||
.filter(img -> img.matchesOwner(owners))
|
||||
.filter(img -> matchesImageFilters(img, filters))
|
||||
.map(Ec2ImageCatalog.CatalogImage::toImage)
|
||||
.collect(Collectors.toList());
|
||||
List<Image> createdImages = registeredImages.scan(k -> true).stream()
|
||||
.filter(img -> region.equals(img.getRegion()))
|
||||
.filter(img -> matchesImageIds(img, imageIds))
|
||||
.filter(img -> matchesImageOwners(img, owners))
|
||||
.filter(img -> matchesRegisteredImageFilters(img, filters))
|
||||
.collect(Collectors.toList());
|
||||
List<Image> images = new ArrayList<>(catalogImages);
|
||||
images.addAll(createdImages);
|
||||
return images;
|
||||
}
|
||||
|
||||
public Image registerImage(String region, String name, String description, String architecture,
|
||||
String rootDeviceName, List<BlockDeviceMapping> blockDeviceMappings) {
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("MissingParameter", "The request must contain the parameter Name", 400);
|
||||
}
|
||||
boolean duplicateName = registeredImages.scan(k -> true).stream()
|
||||
.filter(img -> region.equals(img.getRegion()))
|
||||
.anyMatch(img -> name.equals(img.getName()));
|
||||
if (duplicateName) {
|
||||
throw new AwsException("InvalidAMIName.Duplicate",
|
||||
"AMI name '" + name + "' is already in use.", 400);
|
||||
}
|
||||
Image image = new Image();
|
||||
image.setImageId("ami-" + randomHex(17));
|
||||
image.setName(name);
|
||||
image.setDescription(description != null ? description : name);
|
||||
image.setOwnerId(accountId);
|
||||
image.setImageOwnerAlias(null);
|
||||
image.setPublic(false);
|
||||
image.setArchitecture(architecture != null ? architecture : "x86_64");
|
||||
image.setRootDeviceName(rootDeviceName != null ? rootDeviceName : "/dev/sda1");
|
||||
image.setRootDeviceType("ebs");
|
||||
image.setVirtualizationType("hvm");
|
||||
image.setHypervisor("xen");
|
||||
image.setCreationDate(ISO_FMT.format(Instant.now()));
|
||||
image.setRegion(region);
|
||||
image.setBlockDeviceMappings(blockDeviceMappings != null ? new ArrayList<>(blockDeviceMappings) : List.of());
|
||||
registeredImages.put(key(region, image.getImageId()), image);
|
||||
for (BlockDeviceMapping mapping : image.getBlockDeviceMappings()) {
|
||||
EbsBlockDevice ebs = mapping.getEbs();
|
||||
if (ebs != null && ebs.getSnapshotId() != null) {
|
||||
String snapshotKey = key(region, ebs.getSnapshotId());
|
||||
if (snapshots.get(snapshotKey).isEmpty()) {
|
||||
snapshots.put(snapshotKey, snapshotFrom(region, ebs.getSnapshotId(), image, mapping));
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public List<Snapshot> describeSnapshots(String region, List<String> snapshotIds,
|
||||
List<String> ownerIds, Map<String, List<String>> filters) {
|
||||
if (snapshotIds != null && !snapshotIds.isEmpty()) {
|
||||
for (String id : snapshotIds) {
|
||||
if (snapshots.get(key(region, id)).isEmpty()) {
|
||||
throw new AwsException("InvalidSnapshot.NotFound",
|
||||
"The snapshot '" + id + "' does not exist.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
return snapshots.scan(k -> true).stream()
|
||||
.filter(snapshot -> region.equals(snapshot.getRegion()))
|
||||
.filter(snapshot -> snapshotIds == null || snapshotIds.isEmpty() || snapshotIds.contains(snapshot.getSnapshotId()))
|
||||
.filter(snapshot -> matchesSnapshotOwners(snapshot, ownerIds))
|
||||
.filter(snapshot -> matchesSnapshotFilters(snapshot, filters))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// ─── Launch Templates ─────────────────────────────────────────────────────
|
||||
@@ -1820,6 +1898,100 @@ public class Ec2Service {
|
||||
};
|
||||
}
|
||||
|
||||
private boolean matchesImageIds(Image image, List<String> imageIds) {
|
||||
return imageIds == null || imageIds.isEmpty() || imageIds.contains(image.getImageId());
|
||||
}
|
||||
|
||||
private boolean matchesImageOwners(Image image, List<String> owners) {
|
||||
return owners == null || owners.isEmpty()
|
||||
|| owners.contains(image.getOwnerId())
|
||||
|| (owners.contains("self") && accountId.equals(image.getOwnerId()));
|
||||
}
|
||||
|
||||
private boolean matchesRegisteredImageFilters(Image image, Map<String, List<String>> filters) {
|
||||
if (filters == null || filters.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<String, List<String>> filter : filters.entrySet()) {
|
||||
if (!matchesRegisteredImageFilter(image, filter.getKey(), filter.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean matchesRegisteredImageFilter(Image image, String name, List<String> values) {
|
||||
return switch (name) {
|
||||
case "architecture" -> matchesFilterValue(values, image.getArchitecture());
|
||||
case "block-device-mapping.snapshot-id" -> image.getBlockDeviceMappings().stream()
|
||||
.map(BlockDeviceMapping::getEbs)
|
||||
.filter(Objects::nonNull)
|
||||
.map(EbsBlockDevice::getSnapshotId)
|
||||
.anyMatch(snapshotId -> matchesFilterValue(values, snapshotId));
|
||||
case "description" -> matchesFilterValue(values, image.getDescription());
|
||||
case "hypervisor" -> matchesFilterValue(values, image.getHypervisor());
|
||||
case "image-id" -> matchesFilterValue(values, image.getImageId());
|
||||
case "image-type" -> matchesFilterValue(values, "machine");
|
||||
case "is-public" -> matchesFilterValue(values, String.valueOf(image.isPublic()));
|
||||
case "name" -> matchesFilterValue(values, image.getName());
|
||||
case "owner-alias" -> matchesFilterValue(values, image.getImageOwnerAlias());
|
||||
case "owner-id" -> matchesFilterValue(values, image.getOwnerId());
|
||||
case "root-device-name" -> matchesFilterValue(values, image.getRootDeviceName());
|
||||
case "root-device-type" -> matchesFilterValue(values, image.getRootDeviceType());
|
||||
case "state" -> matchesFilterValue(values, image.getState());
|
||||
case "virtualization-type" -> matchesFilterValue(values, image.getVirtualizationType());
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
|
||||
private Snapshot snapshotFrom(String region, String snapshotId, Image image, BlockDeviceMapping mapping) {
|
||||
EbsBlockDevice ebs = mapping.getEbs();
|
||||
Snapshot snapshot = new Snapshot();
|
||||
snapshot.setSnapshotId(snapshotId);
|
||||
snapshot.setOwnerId(accountId);
|
||||
snapshot.setState("completed");
|
||||
snapshot.setDescription("Created by RegisterImage for " + image.getName());
|
||||
snapshot.setStartTime(Instant.now());
|
||||
snapshot.setVolumeSize(ebs.getVolumeSize());
|
||||
snapshot.setEncrypted(Boolean.TRUE.equals(ebs.getEncrypted()));
|
||||
snapshot.setRegion(region);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
private boolean matchesSnapshotFilters(Snapshot snapshot, Map<String, List<String>> filters) {
|
||||
if (filters == null || filters.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<String, List<String>> filter : filters.entrySet()) {
|
||||
if (!matchesSnapshotFilter(snapshot, filter.getKey(), filter.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean matchesSnapshotOwners(Snapshot snapshot, List<String> ownerIds) {
|
||||
if (ownerIds == null || ownerIds.isEmpty()) {
|
||||
return accountId.equals(snapshot.getOwnerId());
|
||||
}
|
||||
return ownerIds.contains(snapshot.getOwnerId())
|
||||
|| ownerIds.contains("self") && accountId.equals(snapshot.getOwnerId());
|
||||
}
|
||||
|
||||
private boolean matchesSnapshotFilter(Snapshot snapshot, String name, List<String> values) {
|
||||
return switch (name) {
|
||||
case "description" -> matchesFilterValue(values, snapshot.getDescription());
|
||||
case "owner-id" -> matchesFilterValue(values, snapshot.getOwnerId());
|
||||
case "progress" -> matchesFilterValue(values, snapshot.getProgress());
|
||||
case "snapshot-id" -> matchesFilterValue(values, snapshot.getSnapshotId());
|
||||
case "status" -> matchesFilterValue(values, snapshot.getState());
|
||||
case "volume-id" -> matchesFilterValue(values, snapshot.getVolumeId());
|
||||
case "volume-size" -> matchesFilterValue(values,
|
||||
snapshot.getVolumeSize() != null ? String.valueOf(snapshot.getVolumeSize()) : null);
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean matchesFilterValue(List<String> patterns, String value) {
|
||||
if (patterns == null || patterns.isEmpty()) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.github.hectorvent.floci.services.ec2.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class BlockDeviceMapping {
|
||||
|
||||
private String deviceName;
|
||||
private EbsBlockDevice ebs;
|
||||
|
||||
public BlockDeviceMapping() {}
|
||||
|
||||
public String getDeviceName() { return deviceName; }
|
||||
public void setDeviceName(String deviceName) { this.deviceName = deviceName; }
|
||||
|
||||
public EbsBlockDevice getEbs() { return ebs; }
|
||||
public void setEbs(EbsBlockDevice ebs) { this.ebs = ebs; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.hectorvent.floci.services.ec2.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class EbsBlockDevice {
|
||||
|
||||
private String snapshotId;
|
||||
private Integer volumeSize;
|
||||
private String volumeType;
|
||||
private Boolean deleteOnTermination;
|
||||
private Boolean encrypted;
|
||||
|
||||
public EbsBlockDevice() {}
|
||||
|
||||
public String getSnapshotId() { return snapshotId; }
|
||||
public void setSnapshotId(String snapshotId) { this.snapshotId = snapshotId; }
|
||||
|
||||
public Integer getVolumeSize() { return volumeSize; }
|
||||
public void setVolumeSize(Integer volumeSize) { this.volumeSize = volumeSize; }
|
||||
|
||||
public String getVolumeType() { return volumeType; }
|
||||
public void setVolumeType(String volumeType) { this.volumeType = volumeType; }
|
||||
|
||||
public Boolean getDeleteOnTermination() { return deleteOnTermination; }
|
||||
public void setDeleteOnTermination(Boolean deleteOnTermination) { this.deleteOnTermination = deleteOnTermination; }
|
||||
|
||||
public Boolean getEncrypted() { return encrypted; }
|
||||
public void setEncrypted(Boolean encrypted) { this.encrypted = encrypted; }
|
||||
}
|
||||
@@ -24,6 +24,8 @@ public class Image {
|
||||
private String platform;
|
||||
private String imageOwnerAlias = "amazon";
|
||||
private String creationDate;
|
||||
private String region;
|
||||
private List<BlockDeviceMapping> blockDeviceMappings = new ArrayList<>();
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public Image() {}
|
||||
@@ -70,6 +72,12 @@ public class Image {
|
||||
public String getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(String creationDate) { this.creationDate = creationDate; }
|
||||
|
||||
public String getRegion() { return region; }
|
||||
public void setRegion(String region) { this.region = region; }
|
||||
|
||||
public List<BlockDeviceMapping> getBlockDeviceMappings() { return blockDeviceMappings; }
|
||||
public void setBlockDeviceMappings(List<BlockDeviceMapping> blockDeviceMappings) { this.blockDeviceMappings = blockDeviceMappings; }
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) { this.tags = tags; }
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package io.github.hectorvent.floci.services.ec2.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Snapshot {
|
||||
|
||||
private String snapshotId;
|
||||
private String volumeId;
|
||||
private Integer volumeSize;
|
||||
private String ownerId;
|
||||
private String state = "completed";
|
||||
private String description;
|
||||
private Instant startTime;
|
||||
private String progress = "100%";
|
||||
private boolean encrypted;
|
||||
private String region;
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
public Snapshot() {}
|
||||
|
||||
public String getSnapshotId() { return snapshotId; }
|
||||
public void setSnapshotId(String snapshotId) { this.snapshotId = snapshotId; }
|
||||
|
||||
public String getVolumeId() { return volumeId; }
|
||||
public void setVolumeId(String volumeId) { this.volumeId = volumeId; }
|
||||
|
||||
public Integer getVolumeSize() { return volumeSize; }
|
||||
public void setVolumeSize(Integer volumeSize) { this.volumeSize = volumeSize; }
|
||||
|
||||
public String getOwnerId() { return ownerId; }
|
||||
public void setOwnerId(String ownerId) { this.ownerId = ownerId; }
|
||||
|
||||
public String getState() { return state; }
|
||||
public void setState(String state) { this.state = state; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public Instant getStartTime() { return startTime; }
|
||||
public void setStartTime(Instant startTime) { this.startTime = startTime; }
|
||||
|
||||
public String getProgress() { return progress; }
|
||||
public void setProgress(String progress) { this.progress = progress; }
|
||||
|
||||
public boolean isEncrypted() { return encrypted; }
|
||||
public void setEncrypted(boolean encrypted) { this.encrypted = encrypted; }
|
||||
|
||||
public String getRegion() { return region; }
|
||||
public void setRegion(String region) { this.region = region; }
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) { this.tags = tags; }
|
||||
}
|
||||
Reference in new issue
Block a user