Skip to content

Commit

Permalink
feat(amazon): Add Edda proxy for LaunchTemplateVersions (#5083)
Browse files Browse the repository at this point in the history
* feat(amazon): Add Edda proxy for LaunchTemplateVersions

* Apply formatting

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
caseyhebebrand and mergify[bot] committed Nov 9, 2020
1 parent f8e0144 commit c9286ae
Showing 1 changed file with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
Expand Down Expand Up @@ -203,6 +205,40 @@ public DescribeLaunchTemplatesResult describeLaunchTemplates(
describe(request, "launchTemplateNames", "launchTemplates", LaunchTemplate.class));
}

private static final Function<AmazonWebServiceRequest, Collection<String>>
LAUNCH_TEMPLATE_VERSION_EXTRACTOR =
(r) -> {
if (r == null) {
return Collections.emptyList();
}
DescribeLaunchTemplateVersionsRequest req = (DescribeLaunchTemplateVersionsRequest) r;
if (req.getLaunchTemplateId() == null) {
return Collections.emptyList();
}
if (req.getVersions() == null || req.getVersions().isEmpty()) {
String defaultId = req.getLaunchTemplateId() + ":$Default";
return Collections.singletonList(defaultId);
}
return req.getVersions().stream()
.map(v -> req.getLaunchTemplateId() + ":" + v)
.collect(Collectors.toCollection(ArrayList::new));
};

public DescribeLaunchTemplateVersionsResult describeLaunchTemplateVersions() {
return describeLaunchTemplateVersions(null);
}

public DescribeLaunchTemplateVersionsResult describeLaunchTemplateVersions(
DescribeLaunchTemplateVersionsRequest request) {
return new DescribeLaunchTemplateVersionsResult()
.withLaunchTemplateVersions(
describe(
request,
LAUNCH_TEMPLATE_VERSION_EXTRACTOR,
"launchTemplateVersions",
LaunchTemplateVersion.class));
}

public DescribeImagesResult describeImages() {
return describeImages(null);
}
Expand Down Expand Up @@ -349,11 +385,19 @@ private <T> List<T> describe(
String idKey,
final String object,
final Class<T> singleType) {
return describe(request, r -> getRequestIds(r, idKey), object, singleType);
}

private <T> List<T> describe(
AmazonWebServiceRequest request,
Function<AmazonWebServiceRequest, Collection<String>> idExtractor,
final String object,
final Class<T> singleType) {
lastModified.set(null);
final Map<String, String> metricTags = new HashMap<>(this.metricTags);
metricTags.put("collection", object);
try {
final Collection<String> ids = getRequestIds(request, idKey);
final Collection<String> ids = idExtractor.apply(request);
metricTags.put("collectionMode", ids.isEmpty() ? "full" : "byId");
final JavaType singleMeta =
objectMapper
Expand Down

0 comments on commit c9286ae

Please sign in to comment.