mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(config): compliance evaluation loop, retention, pagination (#2642)
* feat(config): add compliance evaluation loop, retention, and pagination Replace the hardcoded INSUFFICIENT_DATA compliance with real aggregation over evaluations reported via PutEvaluations / PutExternalEvaluation: - New actions (13): PutEvaluations, PutExternalEvaluation, DeleteEvaluationResults, DescribeComplianceByResource, GetComplianceDetailsByConfigRule, GetComplianceDetailsByResource, GetComplianceSummaryByConfigRule, GetComplianceSummaryByResourceType, DeleteConfigurationRecorder, DeleteDeliveryChannel, PutRetentionConfiguration, DescribeRetentionConfigurations, DeleteRetentionConfiguration - PutConfigRule now round-trips the full AWS rule shape (Description, Scope, SourceDetails, InputParameters, MaximumExecutionFrequency, EvaluationModes) instead of silently dropping fields - Evaluations persist to config-evaluations.json and are cascade-deleted with their rule; retention persists to config-retention.json - NextToken/Limit pagination on describe/get operations with AWS page sizes and InvalidNextTokenException/InvalidLimitException validation - DescribeConfigRules with an unknown name now fails with NoSuchConfigRuleException, matching AWS - boto3 compatibility suite: tests/test_config.py Since Floci performs no Lambda invocation, PutEvaluations accepts the config rule name as the ResultToken; documented in the service doc's deviations section. * fix: honor Limit field in Config pagination requests * fix(config): enforce the modeled rule enums and the ComplianceTypes filter shape PutConfigRule now deserializes the whole modeled ConfigRule and stores it, so Source.Owner, MaximumExecutionFrequency, ConfigRuleState and EvaluationModes[].Mode were persisted and echoed back verbatim — a rule AWS would have rejected with InvalidParameterValueException read back as a valid one. The ComplianceTypes filter on the four compliance reads was likewise unchecked: an unmodeled value or a list longer than the shape's max of 3 simply matched nothing, which a caller reads as an empty result rather than as a rejection. * fix(config): validate the nested SourceDetails enums and Scope cardinality The stored ConfigRule carries SourceDetails, whose EventSource (aws.config only), MessageType and MaximumExecutionFrequency are all enum-typed, and a Scope whose ComplianceResourceTypes list is capped at 100. All four were persisted and echoed back by DescribeConfigRules verbatim, one level below the members the previous commit checked. * fix(config): reject a missing ConfigRuleName on DeleteConfigRule store.remove(ruleName) throws NullPointerException on the backing ConcurrentHashMap when ruleName is null (the handler passes null when ConfigRuleName is absent from the request), producing a 500 instead of the modeled NoSuchConfigRuleException. Guard on isBlank(ruleName) first, matching the existing requireRule() idiom used by the sibling evaluation operations for the same field. * fix(config): keep the newest evaluation when PutEvaluations reorders storeEvaluations() unconditionally overwrote the stored compliance result for a resource/rule pair, so an older evaluation arriving after a newer one (e.g. an out-of-order Lambda invocation) regressed compliance details, aggregates, and summaries back to the stale value. Compare against the stored OrderingTimestamp and skip the incoming evaluation when it is older than what is already recorded. * fix(config): make PutEvaluations atomic per resource/rule key storeEvaluations() read the current evaluation with a plain get() and wrote the new one with a separate put(), so two concurrent PutEvaluations calls for the same resource could both read the old value before either wrote, letting an older OrderingTimestamp win the race regardless of arrival order. Replace the read-then-write with ConcurrentHashMap.compute(), which is atomic per key. Added a stress test exercising 16 concurrent writers per resource key across 100 attempts; it passes reliably under the fix. The race window in the prior get/put shape is narrow enough (a handful of nanoseconds between the two calls) that it did not reproduce deterministically under test scheduling even with that much contention -- the fix is justified by the non-atomic read-then-write shape itself, not by a forced failure. * fix(config): enforce DescribeConfigRules' 25-name limit ConfigRuleNames is modeled with Maximum 25 items (confirmed against botocore's config service-2.json) but describeConfigRules had no size check, so 26+ names were processed instead of rejected with InvalidParameterValueException like every other array-size limit this PR already enforces. * fix(config): close the DeleteConfigRule/PutEvaluations deletion race PutEvaluations (and PutExternalEvaluation, DeleteEvaluationResults) checked a rule's existence via requireRule and then wrote to the evaluations map as two separate steps. If DeleteConfigRule ran in between -- removing the rule and its evaluation bucket -- the pending PutEvaluations call would recreate the bucket via computeIfAbsent after the delete, orphaning evaluations under the deleted rule's name. A later rule created with that same name would then inherit the deleted rule's compliance details and evaluation status. Guard the check-then-act with a per-rule monitor (ruleKey(region, ruleName)), matching the lockFor()-keyed-monitor idiom already used by DocDbService for the identical class of race between a tag update and a delete. Added a stress test racing PutEvaluations against DeleteConfigRule across 200 attempts, then recreating the rule under the same name and asserting a clean (INSUFFICIENT_DATA) evaluation state. It passes under the fix; as with the earlier PutEvaluations-ordering race, it did not reproduce RED against the pre-fix code even under that much contention -- the race window between the existence check and the map write is too narrow to hit deterministically without injecting an artificial delay into production code. The fix is justified by the non-atomic check-then-act shape itself, confirmed by reading the code.
This commit is contained in:
1 parent
41b5148824
commit
1b3417a7a3
33 files changed
+2970
-125
No files matched your search
+650
-53
@@ -6,22 +6,38 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackedMap;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.configservice.model.Compliance;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ComplianceByConfigRule;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ComplianceByResource;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ComplianceContributorCount;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ComplianceSummary;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ComplianceSummaryByResourceType;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigEvaluation;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigRule;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigRuleEvaluationStatus;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigRuleSource;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorder;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorderStatus;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConformancePack;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConformancePackStatusDetail;
|
||||
import io.github.hectorvent.floci.services.configservice.model.DeliveryChannel;
|
||||
import io.github.hectorvent.floci.services.configservice.model.EvaluationModeConfiguration;
|
||||
import io.github.hectorvent.floci.services.configservice.model.EvaluationResult;
|
||||
import io.github.hectorvent.floci.services.configservice.model.EvaluationResultIdentifier;
|
||||
import io.github.hectorvent.floci.services.configservice.model.EvaluationResultQualifier;
|
||||
import io.github.hectorvent.floci.services.configservice.model.RetentionConfiguration;
|
||||
import io.github.hectorvent.floci.services.configservice.model.SourceDetail;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -29,6 +45,34 @@ import java.util.stream.Collectors;
|
||||
@ApplicationScoped
|
||||
public class AwsConfigService {
|
||||
|
||||
private static final Set<String> VALID_COMPLIANCE_TYPES =
|
||||
Set.of("COMPLIANT", "NON_COMPLIANT", "NOT_APPLICABLE", "INSUFFICIENT_DATA");
|
||||
private static final String NO_SUCH_CONFIG_RULE_MESSAGE =
|
||||
"The ConfigRule provided in the request is invalid. Please check the configRule name.";
|
||||
private static final String INVALID_NEXT_TOKEN_MESSAGE =
|
||||
"The specified next token is not valid. Specify the nextToken string that was returned "
|
||||
+ "in the previous response to get the next page of results.";
|
||||
/** Enum shapes from the Config model (config/2014-11-12/service-2.json). */
|
||||
private static final Set<String> VALID_RULE_OWNERS =
|
||||
Set.of("CUSTOM_LAMBDA", "AWS", "CUSTOM_POLICY");
|
||||
private static final Set<String> VALID_EXECUTION_FREQUENCIES =
|
||||
Set.of("One_Hour", "Three_Hours", "Six_Hours", "Twelve_Hours", "TwentyFour_Hours");
|
||||
private static final Set<String> VALID_RULE_STATES =
|
||||
Set.of("ACTIVE", "DELETING", "DELETING_RESULTS", "EVALUATING");
|
||||
private static final Set<String> VALID_EVALUATION_MODES = Set.of("DETECTIVE", "PROACTIVE");
|
||||
private static final Set<String> VALID_EVENT_SOURCES = Set.of("aws.config");
|
||||
private static final Set<String> VALID_MESSAGE_TYPES = Set.of(
|
||||
"ConfigurationItemChangeNotification", "ConfigurationSnapshotDeliveryCompleted",
|
||||
"ScheduledNotification", "OversizedConfigurationItemChangeNotification");
|
||||
/** {@code ComplianceTypes} is a list of ComplianceType with {@code max: 3}. */
|
||||
private static final int MAX_COMPLIANCE_TYPE_FILTERS = 3;
|
||||
/** {@code Scope.ComplianceResourceTypes} is {@code max: 100}. */
|
||||
private static final int MAX_COMPLIANCE_RESOURCE_TYPES = 100;
|
||||
/** {@code DescribeConfigRulesRequest.ConfigRuleNames} is {@code max: 25}. */
|
||||
private static final int MAX_DESCRIBE_CONFIG_RULE_NAMES = 25;
|
||||
private static final int RULE_CONTRIBUTOR_CAP = 25;
|
||||
private static final int RESOURCE_CONTRIBUTOR_CAP = 100;
|
||||
|
||||
private final RegionResolver regionResolver;
|
||||
private final StorageFactory storageFactory;
|
||||
|
||||
@@ -36,16 +80,28 @@ public class AwsConfigService {
|
||||
private Map<String, Map<String, ConfigRule>> configRules = new ConcurrentHashMap<>();
|
||||
// region -> packName -> pack (nested)
|
||||
private Map<String, Map<String, ConformancePack>> conformancePacks = new ConcurrentHashMap<>();
|
||||
// region -> ruleName -> resourceKey("Type|Id") -> evaluation (doubly nested)
|
||||
private Map<String, Map<String, Map<String, ConfigEvaluation>>> evaluations = new ConcurrentHashMap<>();
|
||||
|
||||
// region -> recorder / channel (flat)
|
||||
// region -> recorder / channel / retention (flat)
|
||||
private Map<String, ConfigurationRecorder> configurationRecorders = new ConcurrentHashMap<>();
|
||||
private Map<String, DeliveryChannel> deliveryChannels = new ConcurrentHashMap<>();
|
||||
private Map<String, RetentionConfiguration> retentionConfigurations = new ConcurrentHashMap<>();
|
||||
|
||||
// recorder run-state is transient runtime state (not persisted)
|
||||
private final ConcurrentHashMap<String, Boolean> recorderRunning = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, Long> recorderLastStartTime = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, Long> recorderLastStopTime = new ConcurrentHashMap<>();
|
||||
|
||||
// per-rule evaluation timing is transient runtime state, keyed region + "|" + ruleName
|
||||
private final ConcurrentHashMap<String, Long> ruleFirstActivatedTime = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, Long> ruleLastInvokedTime = new ConcurrentHashMap<>();
|
||||
|
||||
// guards the check-then-act between a rule's existence and its evaluations, keyed
|
||||
// region + "|" + ruleName, so DeleteConfigRule can't race PutEvaluations/PutExternalEvaluation
|
||||
// into recreating a deleted rule's evaluation bucket for a later same-named rule to inherit
|
||||
private final ConcurrentHashMap<String, Object> ruleLocks = new ConcurrentHashMap<>();
|
||||
|
||||
// resourceArn -> {tagKey -> tagValue} (flat outer, mutable inner)
|
||||
private Map<String, Map<String, String>> tags = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -64,15 +120,20 @@ public class AwsConfigService {
|
||||
new TypeReference<Map<String, Map<String, ConfigRule>>>() {});
|
||||
this.conformancePacks = storageBacked("config-conformance-packs.json",
|
||||
new TypeReference<Map<String, Map<String, ConformancePack>>>() {});
|
||||
this.evaluations = storageBacked("config-evaluations.json",
|
||||
new TypeReference<Map<String, Map<String, Map<String, ConfigEvaluation>>>>() {});
|
||||
this.configurationRecorders = storageBacked("config-recorders.json",
|
||||
new TypeReference<Map<String, ConfigurationRecorder>>() {});
|
||||
this.deliveryChannels = storageBacked("config-delivery-channels.json",
|
||||
new TypeReference<Map<String, DeliveryChannel>>() {});
|
||||
this.retentionConfigurations = storageBacked("config-retention.json",
|
||||
new TypeReference<Map<String, RetentionConfiguration>>() {});
|
||||
this.tags = storageBacked("config-tags.json",
|
||||
new TypeReference<Map<String, Map<String, String>>>() {});
|
||||
normalizeRegionMaps(configRules);
|
||||
normalizeRegionMaps(conformancePacks);
|
||||
normalizeRegionMaps(tags);
|
||||
normalizeEvaluationMaps();
|
||||
}
|
||||
|
||||
private <V> Map<String, V> storageBacked(String fileName, TypeReference<Map<String, V>> typeReference) {
|
||||
@@ -89,6 +150,18 @@ public class AwsConfigService {
|
||||
}
|
||||
}
|
||||
|
||||
/** Same as {@link #normalizeRegionMaps} but for the doubly nested evaluations map. */
|
||||
private void normalizeEvaluationMaps() {
|
||||
for (Map.Entry<String, Map<String, Map<String, ConfigEvaluation>>> regionEntry
|
||||
: new ArrayList<>(evaluations.entrySet())) {
|
||||
Map<String, Map<String, ConfigEvaluation>> ruleMaps = new ConcurrentHashMap<>();
|
||||
for (Map.Entry<String, Map<String, ConfigEvaluation>> ruleEntry : regionEntry.getValue().entrySet()) {
|
||||
ruleMaps.put(ruleEntry.getKey(), new ConcurrentHashMap<>(ruleEntry.getValue()));
|
||||
}
|
||||
evaluations.put(regionEntry.getKey(), ruleMaps);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@link StorageBackedMap} only flushes on a top-level put, so an in-place mutation of an
|
||||
* inner map must be written back by re-putting the outer entry. */
|
||||
private <V> void persistRegion(Map<String, Map<String, V>> resources, String region) {
|
||||
@@ -100,72 +173,468 @@ public class AwsConfigService {
|
||||
|
||||
// --- Config Rules ---
|
||||
|
||||
public ConfigRule putConfigRule(String region, String ruleName, ConfigRuleSource source) {
|
||||
public ConfigRule putConfigRule(String region, ConfigRule requested) {
|
||||
if (requested == null || isBlank(requested.configRuleName())) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ConfigRuleName must be specified.", 400);
|
||||
}
|
||||
if (requested.source() == null || isBlank(requested.source().owner())) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"Source with Owner must be specified.", 400);
|
||||
}
|
||||
// The whole modeled ConfigRule is stored and echoed back, so every enum-typed member
|
||||
// it keeps is checked here rather than accepted verbatim.
|
||||
requireEnum(requested.source().owner(), VALID_RULE_OWNERS, "Source.Owner");
|
||||
requireEnum(requested.maximumExecutionFrequency(), VALID_EXECUTION_FREQUENCIES,
|
||||
"MaximumExecutionFrequency");
|
||||
requireEnum(requested.configRuleState(), VALID_RULE_STATES, "ConfigRuleState");
|
||||
if (requested.source().sourceDetails() != null) {
|
||||
for (SourceDetail detail : requested.source().sourceDetails()) {
|
||||
if (detail == null) {
|
||||
continue;
|
||||
}
|
||||
requireEnum(detail.eventSource(), VALID_EVENT_SOURCES, "SourceDetails.EventSource");
|
||||
requireEnum(detail.messageType(), VALID_MESSAGE_TYPES, "SourceDetails.MessageType");
|
||||
requireEnum(detail.maximumExecutionFrequency(), VALID_EXECUTION_FREQUENCIES,
|
||||
"SourceDetails.MaximumExecutionFrequency");
|
||||
}
|
||||
}
|
||||
if (requested.scope() != null && requested.scope().complianceResourceTypes() != null
|
||||
&& requested.scope().complianceResourceTypes().size() > MAX_COMPLIANCE_RESOURCE_TYPES) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"Scope.ComplianceResourceTypes accepts at most "
|
||||
+ MAX_COMPLIANCE_RESOURCE_TYPES + " values.", 400);
|
||||
}
|
||||
if (requested.evaluationModes() != null) {
|
||||
for (EvaluationModeConfiguration mode : requested.evaluationModes()) {
|
||||
requireEnum(mode == null ? null : mode.mode(), VALID_EVALUATION_MODES,
|
||||
"EvaluationModes.Mode");
|
||||
}
|
||||
}
|
||||
String ruleName = requested.configRuleName();
|
||||
Map<String, ConfigRule> store = rulesFor(region);
|
||||
ConfigRule existing = store.get(ruleName);
|
||||
String ruleId;
|
||||
String ruleArn;
|
||||
String state;
|
||||
if (existing != null) {
|
||||
ConfigRule updated = new ConfigRule(existing.configRuleName(), existing.configRuleArn(),
|
||||
existing.configRuleId(), existing.configRuleState(), source);
|
||||
store.put(ruleName, updated);
|
||||
persistRegion(configRules, region);
|
||||
return updated;
|
||||
ruleId = existing.configRuleId();
|
||||
ruleArn = existing.configRuleArn();
|
||||
state = existing.configRuleState();
|
||||
} else {
|
||||
ruleId = "config-rule-" + shortId();
|
||||
ruleArn = AwsArnUtils.Arn.of("config", region, regionResolver.getAccountId(),
|
||||
"config-rule/" + ruleId).toString();
|
||||
state = isBlank(requested.configRuleState()) ? "ACTIVE" : requested.configRuleState();
|
||||
ruleFirstActivatedTime.putIfAbsent(ruleKey(region, ruleName), now());
|
||||
}
|
||||
String ruleId = "config-rule-" + shortId();
|
||||
String ruleArn = AwsArnUtils.Arn.of("config", region, regionResolver.getAccountId(),
|
||||
"config-rule/" + ruleId).toString();
|
||||
ConfigRule rule = new ConfigRule(ruleName, ruleArn, ruleId, "ACTIVE", source);
|
||||
List<EvaluationModeConfiguration> evaluationModes =
|
||||
requested.evaluationModes() == null || requested.evaluationModes().isEmpty()
|
||||
? List.of(new EvaluationModeConfiguration("DETECTIVE"))
|
||||
: requested.evaluationModes();
|
||||
ConfigRule rule = new ConfigRule(ruleName, ruleArn, ruleId, requested.description(),
|
||||
requested.scope(), requested.source(), requested.inputParameters(),
|
||||
requested.maximumExecutionFrequency(), state, requested.createdBy(), evaluationModes);
|
||||
store.put(ruleName, rule);
|
||||
persistRegion(configRules, region);
|
||||
return rule;
|
||||
}
|
||||
|
||||
public void deleteConfigRule(String region, String ruleName) {
|
||||
Map<String, ConfigRule> store = rulesFor(region);
|
||||
if (store.remove(ruleName) == null) {
|
||||
throw new AwsException("NoSuchConfigRuleException",
|
||||
"The ConfigRule provided in the request is invalid. " +
|
||||
"Please check the configRule name.", 400);
|
||||
if (isBlank(ruleName)) {
|
||||
throw new AwsException("NoSuchConfigRuleException", NO_SUCH_CONFIG_RULE_MESSAGE, 400);
|
||||
}
|
||||
synchronized (lockFor(ruleKey(region, ruleName))) {
|
||||
Map<String, ConfigRule> store = rulesFor(region);
|
||||
if (store.remove(ruleName) == null) {
|
||||
throw new AwsException("NoSuchConfigRuleException", NO_SUCH_CONFIG_RULE_MESSAGE, 400);
|
||||
}
|
||||
persistRegion(configRules, region);
|
||||
Map<String, Map<String, ConfigEvaluation>> regionEvaluations = evaluations.get(region);
|
||||
if (regionEvaluations != null && regionEvaluations.remove(ruleName) != null) {
|
||||
persistRegion(evaluations, region);
|
||||
}
|
||||
ruleFirstActivatedTime.remove(ruleKey(region, ruleName));
|
||||
ruleLastInvokedTime.remove(ruleKey(region, ruleName));
|
||||
}
|
||||
persistRegion(configRules, region);
|
||||
}
|
||||
|
||||
public List<ConfigRule> describeConfigRules(String region, List<String> ruleNames) {
|
||||
Map<String, ConfigRule> store = rulesFor(region);
|
||||
if (ruleNames == null || ruleNames.isEmpty()) {
|
||||
return new ArrayList<>(store.values());
|
||||
if (ruleNames != null && ruleNames.size() > MAX_DESCRIBE_CONFIG_RULE_NAMES) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ConfigRuleNames accepts at most " + MAX_DESCRIBE_CONFIG_RULE_NAMES + " values.", 400);
|
||||
}
|
||||
Map<String, ConfigRule> store = rulesFor(region);
|
||||
List<ConfigRule> result = new ArrayList<>();
|
||||
for (String name : ruleNames) {
|
||||
ConfigRule rule = store.get(name);
|
||||
if (rule != null) {
|
||||
if (ruleNames == null || ruleNames.isEmpty()) {
|
||||
result.addAll(store.values());
|
||||
} else {
|
||||
for (String name : ruleNames) {
|
||||
ConfigRule rule = store.get(name);
|
||||
if (rule == null) {
|
||||
throw new AwsException("NoSuchConfigRuleException", NO_SUCH_CONFIG_RULE_MESSAGE, 400);
|
||||
}
|
||||
result.add(rule);
|
||||
}
|
||||
}
|
||||
result.sort(Comparator.comparing(ConfigRule::configRuleName));
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ConfigRuleEvaluationStatus> describeConfigRuleEvaluationStatus(String region, List<String> ruleNames) {
|
||||
List<ConfigRule> rules = describeConfigRules(region, ruleNames);
|
||||
List<ConfigRuleEvaluationStatus> result = new ArrayList<>();
|
||||
for (ConfigRule rule : rules) {
|
||||
result.add(new ConfigRuleEvaluationStatus(
|
||||
rule.configRuleName(),
|
||||
rule.configRuleArn(),
|
||||
rule.configRuleId(),
|
||||
true));
|
||||
public Paged<ConfigRule> describeConfigRulesPaged(String region, List<String> ruleNames, String nextToken) {
|
||||
return paginate(describeConfigRules(region, ruleNames), null, nextToken,
|
||||
25, 25, "InvalidParameterValueException");
|
||||
}
|
||||
|
||||
public Paged<ConfigRuleEvaluationStatus> describeConfigRuleEvaluationStatus(String region,
|
||||
List<String> ruleNames, Integer limit, String nextToken) {
|
||||
List<ConfigRuleEvaluationStatus> statuses = new ArrayList<>();
|
||||
for (ConfigRule rule : describeConfigRules(region, ruleNames)) {
|
||||
String key = ruleKey(region, rule.configRuleName());
|
||||
Map<String, ConfigEvaluation> ruleEvaluations =
|
||||
evaluationsFor(region).getOrDefault(rule.configRuleName(), Map.of());
|
||||
Long lastEvaluationTime = ruleEvaluations.values().stream()
|
||||
.map(ConfigEvaluation::resultRecordedTime)
|
||||
.filter(Objects::nonNull)
|
||||
.max(Long::compareTo)
|
||||
.orElse(ruleLastInvokedTime.get(key));
|
||||
boolean evaluationStarted = !ruleEvaluations.isEmpty() || ruleLastInvokedTime.containsKey(key);
|
||||
statuses.add(new ConfigRuleEvaluationStatus(
|
||||
rule.configRuleName(), rule.configRuleArn(), rule.configRuleId(),
|
||||
evaluationStarted, ruleFirstActivatedTime.get(key),
|
||||
lastEvaluationTime, lastEvaluationTime));
|
||||
}
|
||||
return result;
|
||||
return paginate(statuses, limit, nextToken, 150, 150, "InvalidParameterValueException");
|
||||
}
|
||||
|
||||
public void startConfigRulesEvaluation(String region, List<String> ruleNames) {
|
||||
Map<String, ConfigRule> store = rulesFor(region);
|
||||
for (String name : ruleNames) {
|
||||
if (!store.containsKey(name)) {
|
||||
throw new AwsException("NoSuchConfigRuleException",
|
||||
"The ConfigRule provided in the request is invalid. " +
|
||||
"Please check the configRule name.", 400);
|
||||
throw new AwsException("NoSuchConfigRuleException", NO_SUCH_CONFIG_RULE_MESSAGE, 400);
|
||||
}
|
||||
}
|
||||
for (String name : ruleNames) {
|
||||
ruleLastInvokedTime.put(ruleKey(region, name), now());
|
||||
}
|
||||
}
|
||||
|
||||
// --- Evaluations ---
|
||||
|
||||
public void putEvaluations(String region, String resultToken, List<ConfigEvaluation> newEvaluations,
|
||||
boolean testMode) {
|
||||
if (isBlank(resultToken)) {
|
||||
throw new AwsException("InvalidResultTokenException",
|
||||
"The specified ResultToken is not valid.", 400);
|
||||
}
|
||||
if (newEvaluations.size() > 100) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"The Evaluations list cannot contain more than 100 items.", 400);
|
||||
}
|
||||
newEvaluations.forEach(this::validateEvaluation);
|
||||
if (testMode) {
|
||||
return;
|
||||
}
|
||||
int separator = resultToken.indexOf(':');
|
||||
String ruleName = separator > 0 ? resultToken.substring(0, separator) : resultToken;
|
||||
synchronized (lockFor(ruleKey(region, ruleName))) {
|
||||
requireRule(region, ruleName);
|
||||
storeEvaluations(region, ruleName, newEvaluations);
|
||||
}
|
||||
}
|
||||
|
||||
public void putExternalEvaluation(String region, String ruleName, ConfigEvaluation evaluation) {
|
||||
validateEvaluation(evaluation);
|
||||
synchronized (lockFor(ruleKey(region, ruleName))) {
|
||||
requireRule(region, ruleName);
|
||||
storeEvaluations(region, ruleName, List.of(evaluation));
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteEvaluationResults(String region, String ruleName) {
|
||||
synchronized (lockFor(ruleKey(region, ruleName))) {
|
||||
requireRule(region, ruleName);
|
||||
Map<String, Map<String, ConfigEvaluation>> regionEvaluations = evaluations.get(region);
|
||||
if (regionEvaluations != null && regionEvaluations.remove(ruleName) != null) {
|
||||
persistRegion(evaluations, region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateEvaluation(ConfigEvaluation evaluation) {
|
||||
if (evaluation == null || isBlank(evaluation.complianceResourceType())
|
||||
|| isBlank(evaluation.complianceResourceId()) || isBlank(evaluation.complianceType())
|
||||
|| evaluation.orderingTimestamp() == null) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"Each evaluation must specify ComplianceResourceType, ComplianceResourceId, "
|
||||
+ "ComplianceType and OrderingTimestamp.", 400);
|
||||
}
|
||||
if (!VALID_COMPLIANCE_TYPES.contains(evaluation.complianceType())) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ComplianceType must be one of COMPLIANT, NON_COMPLIANT, NOT_APPLICABLE, "
|
||||
+ "INSUFFICIENT_DATA.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private void storeEvaluations(String region, String ruleName, List<ConfigEvaluation> newEvaluations) {
|
||||
long recordedTime = now();
|
||||
Map<String, ConfigEvaluation> ruleEvaluations = evaluationsFor(region)
|
||||
.computeIfAbsent(ruleName, r -> new ConcurrentHashMap<>());
|
||||
for (ConfigEvaluation evaluation : newEvaluations) {
|
||||
String key = resourceKey(evaluation.complianceResourceType(), evaluation.complianceResourceId());
|
||||
ruleEvaluations.compute(key, (ignoredKey, current) -> {
|
||||
if (current != null && current.orderingTimestamp() != null
|
||||
&& evaluation.orderingTimestamp() < current.orderingTimestamp()) {
|
||||
return current;
|
||||
}
|
||||
return new ConfigEvaluation(
|
||||
evaluation.complianceResourceType(),
|
||||
evaluation.complianceResourceId(),
|
||||
evaluation.complianceType(),
|
||||
evaluation.annotation(),
|
||||
evaluation.orderingTimestamp(),
|
||||
recordedTime,
|
||||
recordedTime);
|
||||
});
|
||||
}
|
||||
ruleLastInvokedTime.put(ruleKey(region, ruleName), recordedTime);
|
||||
persistRegion(evaluations, region);
|
||||
}
|
||||
|
||||
// --- Compliance ---
|
||||
|
||||
public Compliance complianceForRule(String region, String ruleName) {
|
||||
List<ConfigEvaluation> applicable = evaluationsFor(region)
|
||||
.getOrDefault(ruleName, Map.of()).values().stream()
|
||||
.filter(e -> !"NOT_APPLICABLE".equals(e.complianceType()))
|
||||
.toList();
|
||||
if (applicable.isEmpty()) {
|
||||
return new Compliance("INSUFFICIENT_DATA", null);
|
||||
}
|
||||
long nonCompliant = applicable.stream()
|
||||
.filter(e -> "NON_COMPLIANT".equals(e.complianceType()))
|
||||
.count();
|
||||
if (nonCompliant > 0) {
|
||||
return new Compliance("NON_COMPLIANT", contributorCount(nonCompliant, RULE_CONTRIBUTOR_CAP));
|
||||
}
|
||||
if (applicable.stream().anyMatch(e -> "INSUFFICIENT_DATA".equals(e.complianceType()))) {
|
||||
return new Compliance("INSUFFICIENT_DATA", null);
|
||||
}
|
||||
return new Compliance("COMPLIANT", null);
|
||||
}
|
||||
|
||||
public Paged<ComplianceByConfigRule> describeComplianceByConfigRule(String region, List<String> ruleNames,
|
||||
List<String> complianceTypes, String nextToken) {
|
||||
validateComplianceTypeFilter(complianceTypes);
|
||||
List<ComplianceByConfigRule> entries = new ArrayList<>();
|
||||
for (ConfigRule rule : describeConfigRules(region, ruleNames)) {
|
||||
Compliance compliance = complianceForRule(region, rule.configRuleName());
|
||||
if (matchesComplianceFilter(complianceTypes, compliance.complianceType())) {
|
||||
entries.add(new ComplianceByConfigRule(rule.configRuleName(), compliance));
|
||||
}
|
||||
}
|
||||
return paginate(entries, null, nextToken, 25, 25, "InvalidParameterValueException");
|
||||
}
|
||||
|
||||
public Paged<ComplianceByResource> describeComplianceByResource(String region, String resourceType,
|
||||
String resourceId, List<String> complianceTypes, Integer limit, String nextToken) {
|
||||
validateComplianceTypeFilter(complianceTypes);
|
||||
if (!isBlank(resourceId) && isBlank(resourceType)) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ResourceType must be specified when ResourceId is provided.", 400);
|
||||
}
|
||||
List<ComplianceByResource> entries = new ArrayList<>();
|
||||
for (List<ConfigEvaluation> resourceEvaluations
|
||||
: groupEvaluationsByResource(region, resourceType, resourceId).values()) {
|
||||
ConfigEvaluation first = resourceEvaluations.get(0);
|
||||
Compliance compliance = complianceForResource(resourceEvaluations);
|
||||
if (matchesComplianceFilter(complianceTypes, compliance.complianceType())) {
|
||||
entries.add(new ComplianceByResource(first.complianceResourceType(),
|
||||
first.complianceResourceId(), compliance));
|
||||
}
|
||||
}
|
||||
entries.sort(Comparator.comparing(ComplianceByResource::resourceType)
|
||||
.thenComparing(ComplianceByResource::resourceId));
|
||||
return paginate(entries, limit, nextToken, 10, 100, "InvalidParameterValueException");
|
||||
}
|
||||
|
||||
public Paged<EvaluationResult> getComplianceDetailsByConfigRule(String region, String ruleName,
|
||||
List<String> complianceTypes, Integer limit, String nextToken) {
|
||||
validateComplianceTypeFilter(complianceTypes);
|
||||
requireRule(region, ruleName);
|
||||
List<EvaluationResult> results = evaluationsFor(region)
|
||||
.getOrDefault(ruleName, Map.of()).values().stream()
|
||||
.filter(e -> matchesComplianceFilter(complianceTypes, e.complianceType()))
|
||||
.sorted(Comparator.comparing(ConfigEvaluation::complianceResourceType)
|
||||
.thenComparing(ConfigEvaluation::complianceResourceId))
|
||||
.map(e -> toEvaluationResult(ruleName, e))
|
||||
.collect(Collectors.toList());
|
||||
return paginate(results, limit, nextToken, 10, 100, "InvalidParameterValueException");
|
||||
}
|
||||
|
||||
public Paged<EvaluationResult> getComplianceDetailsByResource(String region, String resourceType,
|
||||
String resourceId, List<String> complianceTypes, String nextToken) {
|
||||
validateComplianceTypeFilter(complianceTypes);
|
||||
if (isBlank(resourceType) || isBlank(resourceId)) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ResourceType and ResourceId must be specified.", 400);
|
||||
}
|
||||
String key = resourceKey(resourceType, resourceId);
|
||||
List<EvaluationResult> results = new ArrayList<>();
|
||||
evaluationsFor(region).forEach((ruleName, ruleEvaluations) -> {
|
||||
ConfigEvaluation evaluation = ruleEvaluations.get(key);
|
||||
if (evaluation != null && matchesComplianceFilter(complianceTypes, evaluation.complianceType())) {
|
||||
results.add(toEvaluationResult(ruleName, evaluation));
|
||||
}
|
||||
});
|
||||
results.sort(Comparator.comparing(r ->
|
||||
r.evaluationResultIdentifier().evaluationResultQualifier().configRuleName()));
|
||||
return paginate(results, null, nextToken, 10, 10, "InvalidParameterValueException");
|
||||
}
|
||||
|
||||
public ComplianceSummary getComplianceSummaryByConfigRule(String region) {
|
||||
long compliant = 0;
|
||||
long nonCompliant = 0;
|
||||
for (String ruleName : rulesFor(region).keySet()) {
|
||||
String complianceType = complianceForRule(region, ruleName).complianceType();
|
||||
if ("COMPLIANT".equals(complianceType)) {
|
||||
compliant++;
|
||||
} else if ("NON_COMPLIANT".equals(complianceType)) {
|
||||
nonCompliant++;
|
||||
}
|
||||
}
|
||||
return new ComplianceSummary(contributorCount(compliant, RULE_CONTRIBUTOR_CAP),
|
||||
contributorCount(nonCompliant, RULE_CONTRIBUTOR_CAP), now());
|
||||
}
|
||||
|
||||
public List<ComplianceSummaryByResourceType> getComplianceSummaryByResourceType(String region,
|
||||
List<String> resourceTypes) {
|
||||
if (resourceTypes != null && resourceTypes.size() > 20) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ResourceTypes cannot contain more than 20 items.", 400);
|
||||
}
|
||||
Map<String, long[]> countsByType = new HashMap<>();
|
||||
for (List<ConfigEvaluation> resourceEvaluations
|
||||
: groupEvaluationsByResource(region, null, null).values()) {
|
||||
String type = resourceEvaluations.get(0).complianceResourceType();
|
||||
String complianceType = complianceForResource(resourceEvaluations).complianceType();
|
||||
long[] counts = countsByType.computeIfAbsent(type, t -> new long[2]);
|
||||
if ("COMPLIANT".equals(complianceType)) {
|
||||
counts[0]++;
|
||||
} else if ("NON_COMPLIANT".equals(complianceType)) {
|
||||
counts[1]++;
|
||||
}
|
||||
}
|
||||
long timestamp = now();
|
||||
if (resourceTypes == null || resourceTypes.isEmpty()) {
|
||||
long compliant = countsByType.values().stream().mapToLong(c -> c[0]).sum();
|
||||
long nonCompliant = countsByType.values().stream().mapToLong(c -> c[1]).sum();
|
||||
return List.of(new ComplianceSummaryByResourceType(null, new ComplianceSummary(
|
||||
contributorCount(compliant, RESOURCE_CONTRIBUTOR_CAP),
|
||||
contributorCount(nonCompliant, RESOURCE_CONTRIBUTOR_CAP), timestamp)));
|
||||
}
|
||||
List<ComplianceSummaryByResourceType> result = new ArrayList<>();
|
||||
for (String type : resourceTypes) {
|
||||
long[] counts = countsByType.getOrDefault(type, new long[2]);
|
||||
result.add(new ComplianceSummaryByResourceType(type, new ComplianceSummary(
|
||||
contributorCount(counts[0], RESOURCE_CONTRIBUTOR_CAP),
|
||||
contributorCount(counts[1], RESOURCE_CONTRIBUTOR_CAP), timestamp)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, List<ConfigEvaluation>> groupEvaluationsByResource(String region,
|
||||
String resourceType, String resourceId) {
|
||||
Map<String, List<ConfigEvaluation>> byResource = new HashMap<>();
|
||||
for (Map<String, ConfigEvaluation> ruleEvaluations : evaluationsFor(region).values()) {
|
||||
for (ConfigEvaluation evaluation : ruleEvaluations.values()) {
|
||||
if (!isBlank(resourceType) && !resourceType.equals(evaluation.complianceResourceType())) {
|
||||
continue;
|
||||
}
|
||||
if (!isBlank(resourceId) && !resourceId.equals(evaluation.complianceResourceId())) {
|
||||
continue;
|
||||
}
|
||||
String key = resourceKey(evaluation.complianceResourceType(),
|
||||
evaluation.complianceResourceId());
|
||||
byResource.computeIfAbsent(key, k -> new ArrayList<>()).add(evaluation);
|
||||
}
|
||||
}
|
||||
return byResource;
|
||||
}
|
||||
|
||||
private Compliance complianceForResource(List<ConfigEvaluation> resourceEvaluations) {
|
||||
long nonCompliant = resourceEvaluations.stream()
|
||||
.filter(e -> "NON_COMPLIANT".equals(e.complianceType()))
|
||||
.count();
|
||||
if (nonCompliant > 0) {
|
||||
return new Compliance("NON_COMPLIANT", contributorCount(nonCompliant, RULE_CONTRIBUTOR_CAP));
|
||||
}
|
||||
if (resourceEvaluations.stream().anyMatch(e -> "INSUFFICIENT_DATA".equals(e.complianceType()))) {
|
||||
return new Compliance("INSUFFICIENT_DATA", null);
|
||||
}
|
||||
if (resourceEvaluations.stream().anyMatch(e -> "COMPLIANT".equals(e.complianceType()))) {
|
||||
return new Compliance("COMPLIANT", null);
|
||||
}
|
||||
return new Compliance("NOT_APPLICABLE", null);
|
||||
}
|
||||
|
||||
private EvaluationResult toEvaluationResult(String ruleName, ConfigEvaluation evaluation) {
|
||||
return new EvaluationResult(
|
||||
new EvaluationResultIdentifier(
|
||||
new EvaluationResultQualifier(ruleName, evaluation.complianceResourceType(),
|
||||
evaluation.complianceResourceId(), "DETECTIVE"),
|
||||
evaluation.orderingTimestamp()),
|
||||
evaluation.complianceType(),
|
||||
evaluation.resultRecordedTime(),
|
||||
evaluation.configRuleInvokedTime(),
|
||||
evaluation.annotation(),
|
||||
null);
|
||||
}
|
||||
|
||||
private static boolean matchesComplianceFilter(List<String> complianceTypes, String complianceType) {
|
||||
return complianceTypes == null || complianceTypes.isEmpty() || complianceTypes.contains(complianceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@code ComplianceTypes} filter outside the modeled enum (or longer than the list's
|
||||
* {@code max: 3}) would otherwise match nothing and read to the caller as "no results"
|
||||
* instead of the rejection AWS answers.
|
||||
*/
|
||||
private static void validateComplianceTypeFilter(List<String> complianceTypes) {
|
||||
if (complianceTypes == null || complianceTypes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (complianceTypes.size() > MAX_COMPLIANCE_TYPE_FILTERS) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ComplianceTypes accepts at most " + MAX_COMPLIANCE_TYPE_FILTERS + " values.", 400);
|
||||
}
|
||||
for (String complianceType : complianceTypes) {
|
||||
requireEnum(complianceType, VALID_COMPLIANCE_TYPES, "ComplianceTypes");
|
||||
}
|
||||
}
|
||||
|
||||
/** Rejects a non-blank value that is not a member of the shape's enum; a null/blank value is left alone. */
|
||||
private static void requireEnum(String value, Set<String> allowed, String memberName) {
|
||||
if (isBlank(value) || allowed.contains(value)) {
|
||||
return;
|
||||
}
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"Value '" + value + "' at '" + memberName + "' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: ["
|
||||
+ allowed.stream().sorted().collect(Collectors.joining(", ")) + "]",
|
||||
400);
|
||||
}
|
||||
|
||||
private ComplianceContributorCount contributorCount(long count, int cap) {
|
||||
return new ComplianceContributorCount((int) Math.min(count, cap), count > cap);
|
||||
}
|
||||
|
||||
private ConfigRule requireRule(String region, String ruleName) {
|
||||
ConfigRule rule = isBlank(ruleName) ? null : rulesFor(region).get(ruleName);
|
||||
if (rule == null) {
|
||||
throw new AwsException("NoSuchConfigRuleException", NO_SUCH_CONFIG_RULE_MESSAGE, 400);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
// --- Configuration Recorder ---
|
||||
@@ -196,6 +665,18 @@ public class AwsConfigService {
|
||||
return List.of(recorder);
|
||||
}
|
||||
|
||||
public void deleteConfigurationRecorder(String region, String name) {
|
||||
ConfigurationRecorder recorder = configurationRecorders.get(region);
|
||||
if (recorder == null || !recorder.name().equals(name)) {
|
||||
throw new AwsException("NoSuchConfigurationRecorderException",
|
||||
"Cannot find configuration recorder with the specified name.", 400);
|
||||
}
|
||||
configurationRecorders.remove(region);
|
||||
recorderRunning.remove(region);
|
||||
recorderLastStartTime.remove(region);
|
||||
recorderLastStopTime.remove(region);
|
||||
}
|
||||
|
||||
public void startConfigurationRecorder(String region, String name) {
|
||||
ConfigurationRecorder recorder = configurationRecorders.get(region);
|
||||
if (recorder == null || !recorder.name().equals(name)) {
|
||||
@@ -203,7 +684,7 @@ public class AwsConfigService {
|
||||
"Cannot find configuration recorder with the specified name.", 400);
|
||||
}
|
||||
recorderRunning.put(region, true);
|
||||
recorderLastStartTime.put(region, System.currentTimeMillis() / 1000);
|
||||
recorderLastStartTime.put(region, now());
|
||||
}
|
||||
|
||||
public void stopConfigurationRecorder(String region, String name) {
|
||||
@@ -213,7 +694,7 @@ public class AwsConfigService {
|
||||
"Cannot find configuration recorder with the specified name.", 400);
|
||||
}
|
||||
recorderRunning.put(region, false);
|
||||
recorderLastStopTime.put(region, System.currentTimeMillis() / 1000);
|
||||
recorderLastStopTime.put(region, now());
|
||||
}
|
||||
|
||||
public List<ConfigurationRecorderStatus> describeConfigurationRecorderStatus(String region, List<String> names) {
|
||||
@@ -275,6 +756,58 @@ public class AwsConfigService {
|
||||
return List.of(channel);
|
||||
}
|
||||
|
||||
public void deleteDeliveryChannel(String region, String name) {
|
||||
DeliveryChannel channel = deliveryChannels.get(region);
|
||||
if (channel == null || !channel.name().equals(name)) {
|
||||
throw new AwsException("NoSuchDeliveryChannelException",
|
||||
"Cannot find delivery channel with the specified name.", 400);
|
||||
}
|
||||
if (recorderRunning.getOrDefault(region, false)) {
|
||||
throw new AwsException("LastDeliveryChannelDeleteFailedException",
|
||||
"You cannot delete the delivery channel you specified because the customer managed "
|
||||
+ "configuration recorder is running.", 400);
|
||||
}
|
||||
deliveryChannels.remove(region);
|
||||
}
|
||||
|
||||
// --- Retention Configuration ---
|
||||
|
||||
public RetentionConfiguration putRetentionConfiguration(String region, Integer retentionPeriodInDays) {
|
||||
if (retentionPeriodInDays == null || retentionPeriodInDays < 30 || retentionPeriodInDays > 2557) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"RetentionPeriodInDays must be between 30 and 2557.", 400);
|
||||
}
|
||||
RetentionConfiguration configuration = new RetentionConfiguration("default", retentionPeriodInDays);
|
||||
retentionConfigurations.put(region, configuration);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public List<RetentionConfiguration> describeRetentionConfigurations(String region, List<String> names) {
|
||||
RetentionConfiguration configuration = retentionConfigurations.get(region);
|
||||
if (names != null && !names.isEmpty()) {
|
||||
for (String name : names) {
|
||||
if (configuration == null || !configuration.name().equals(name)) {
|
||||
throw new AwsException("NoSuchRetentionConfigurationException",
|
||||
"Cannot find retention configuration with the specified name.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
return configuration == null ? Collections.emptyList() : List.of(configuration);
|
||||
}
|
||||
|
||||
public void deleteRetentionConfiguration(String region, String name) {
|
||||
if (isBlank(name)) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"RetentionConfigurationName must be specified.", 400);
|
||||
}
|
||||
RetentionConfiguration configuration = retentionConfigurations.get(region);
|
||||
if (configuration == null || !configuration.name().equals(name)) {
|
||||
throw new AwsException("NoSuchRetentionConfigurationException",
|
||||
"Cannot find retention configuration with the specified name.", 400);
|
||||
}
|
||||
retentionConfigurations.remove(region);
|
||||
}
|
||||
|
||||
// --- Conformance Packs ---
|
||||
|
||||
public ConformancePack putConformancePack(String region, String packName,
|
||||
@@ -308,33 +841,41 @@ public class AwsConfigService {
|
||||
|
||||
public List<ConformancePack> describeConformancePacks(String region, List<String> names) {
|
||||
Map<String, ConformancePack> store = packsFor(region);
|
||||
if (names == null || names.isEmpty()) {
|
||||
return new ArrayList<>(store.values());
|
||||
}
|
||||
List<ConformancePack> result = new ArrayList<>();
|
||||
for (String name : names) {
|
||||
ConformancePack pack = store.get(name);
|
||||
if (pack == null) {
|
||||
throw new AwsException("NoSuchConformancePackException",
|
||||
"Conformance pack '" + name + "' does not exist.", 400);
|
||||
if (names == null || names.isEmpty()) {
|
||||
result.addAll(store.values());
|
||||
} else {
|
||||
for (String name : names) {
|
||||
ConformancePack pack = store.get(name);
|
||||
if (pack == null) {
|
||||
throw new AwsException("NoSuchConformancePackException",
|
||||
"Conformance pack '" + name + "' does not exist.", 400);
|
||||
}
|
||||
result.add(pack);
|
||||
}
|
||||
result.add(pack);
|
||||
}
|
||||
result.sort(Comparator.comparing(ConformancePack::conformancePackName));
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ConformancePackStatusDetail> describeConformancePackStatus(String region, List<String> names) {
|
||||
List<ConformancePack> packs = describeConformancePacks(region, names);
|
||||
public Paged<ConformancePack> describeConformancePacksPaged(String region, List<String> names,
|
||||
Integer limit, String nextToken) {
|
||||
return paginate(describeConformancePacks(region, names), limit, nextToken,
|
||||
20, 20, "InvalidLimitException");
|
||||
}
|
||||
|
||||
public Paged<ConformancePackStatusDetail> describeConformancePackStatus(String region, List<String> names,
|
||||
Integer limit, String nextToken) {
|
||||
List<ConformancePackStatusDetail> result = new ArrayList<>();
|
||||
for (ConformancePack pack : packs) {
|
||||
for (ConformancePack pack : describeConformancePacks(region, names)) {
|
||||
result.add(new ConformancePackStatusDetail(
|
||||
pack.conformancePackName(),
|
||||
pack.conformancePackId(),
|
||||
pack.conformancePackArn(),
|
||||
"CREATE_SUCCESSFUL",
|
||||
System.currentTimeMillis() / 1000));
|
||||
now()));
|
||||
}
|
||||
return result;
|
||||
return paginate(result, limit, nextToken, 20, 20, "InvalidLimitException");
|
||||
}
|
||||
|
||||
// --- Tagging ---
|
||||
@@ -362,6 +903,38 @@ public class AwsConfigService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// --- Pagination ---
|
||||
|
||||
public record Paged<T>(List<T> items, String nextToken) {}
|
||||
|
||||
/** Offset-as-NextToken pagination over a pre-sorted list. A null or zero limit falls back to
|
||||
* the default page size; limits outside [1, maxLimit] fail with the op-specific error code. */
|
||||
private <T> Paged<T> paginate(List<T> items, Integer limit, String nextToken,
|
||||
int defaultPageSize, int maxLimit, String limitErrorCode) {
|
||||
int pageSize = defaultPageSize;
|
||||
if (limit != null && limit != 0) {
|
||||
if (limit < 0 || limit > maxLimit) {
|
||||
throw new AwsException(limitErrorCode,
|
||||
"Limit must be between 0 and " + maxLimit + ".", 400);
|
||||
}
|
||||
pageSize = limit;
|
||||
}
|
||||
int offset = 0;
|
||||
if (nextToken != null && !nextToken.isEmpty()) {
|
||||
try {
|
||||
offset = Integer.parseInt(nextToken);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("InvalidNextTokenException", INVALID_NEXT_TOKEN_MESSAGE, 400);
|
||||
}
|
||||
if (offset < 0 || offset > items.size()) {
|
||||
throw new AwsException("InvalidNextTokenException", INVALID_NEXT_TOKEN_MESSAGE, 400);
|
||||
}
|
||||
}
|
||||
int end = Math.min(offset + pageSize, items.size());
|
||||
List<T> page = new ArrayList<>(items.subList(offset, end));
|
||||
return new Paged<>(page, end < items.size() ? String.valueOf(end) : null);
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
private Map<String, ConfigRule> rulesFor(String region) {
|
||||
@@ -372,6 +945,30 @@ public class AwsConfigService {
|
||||
return conformancePacks.computeIfAbsent(region, r -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<String, Map<String, ConfigEvaluation>> evaluationsFor(String region) {
|
||||
return evaluations.computeIfAbsent(region, r -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private static String resourceKey(String resourceType, String resourceId) {
|
||||
return resourceType + "|" + resourceId;
|
||||
}
|
||||
|
||||
private static String ruleKey(String region, String ruleName) {
|
||||
return region + "|" + ruleName;
|
||||
}
|
||||
|
||||
private Object lockFor(String key) {
|
||||
return ruleLocks.computeIfAbsent(key, k -> new Object());
|
||||
}
|
||||
|
||||
private static boolean isBlank(String value) {
|
||||
return value == null || value.isBlank();
|
||||
}
|
||||
|
||||
private static long now() {
|
||||
return System.currentTimeMillis() / 1000;
|
||||
}
|
||||
|
||||
private static String shortId() {
|
||||
return UUID.randomUUID().toString().replace("-", "").substring(0, 12);
|
||||
}
|
||||
|
||||
+162
-44
@@ -2,21 +2,20 @@ package io.github.hectorvent.floci.services.configservice;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigEvaluation;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigRule;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigRuleEvaluationStatus;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigRuleSource;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorder;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorderStatus;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConformancePack;
|
||||
import io.github.hectorvent.floci.services.configservice.model.ConformancePackStatusDetail;
|
||||
import io.github.hectorvent.floci.services.configservice.model.DeliveryChannel;
|
||||
import io.github.hectorvent.floci.services.configservice.model.RetentionConfiguration;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -38,19 +37,32 @@ public class ConfigServiceJsonHandler {
|
||||
case "DeleteConfigRule" -> deleteConfigRule(request, region);
|
||||
case "DescribeConfigRules" -> describeConfigRules(request, region);
|
||||
case "DescribeComplianceByConfigRule" -> describeComplianceByConfigRule(request, region);
|
||||
case "DescribeComplianceByResource" -> describeComplianceByResource(request, region);
|
||||
case "DescribeConfigRuleEvaluationStatus" -> describeConfigRuleEvaluationStatus(request, region);
|
||||
case "StartConfigRulesEvaluation" -> startConfigRulesEvaluation(request, region);
|
||||
case "PutEvaluations" -> putEvaluations(request, region);
|
||||
case "PutExternalEvaluation" -> putExternalEvaluation(request, region);
|
||||
case "DeleteEvaluationResults" -> deleteEvaluationResults(request, region);
|
||||
case "GetComplianceDetailsByConfigRule" -> getComplianceDetailsByConfigRule(request, region);
|
||||
case "GetComplianceDetailsByResource" -> getComplianceDetailsByResource(request, region);
|
||||
case "GetComplianceSummaryByConfigRule" -> getComplianceSummaryByConfigRule(region);
|
||||
case "GetComplianceSummaryByResourceType" -> getComplianceSummaryByResourceType(request, region);
|
||||
case "PutConformancePack" -> putConformancePack(request, region);
|
||||
case "DeleteConformancePack" -> deleteConformancePack(request, region);
|
||||
case "DescribeConformancePacks" -> describeConformancePacks(request, region);
|
||||
case "DescribeConformancePackStatus" -> describeConformancePackStatus(request, region);
|
||||
case "PutConfigurationRecorder" -> putConfigurationRecorder(request, region);
|
||||
case "DescribeConfigurationRecorders" -> describeConfigurationRecorders(request, region);
|
||||
case "DeleteConfigurationRecorder" -> deleteConfigurationRecorder(request, region);
|
||||
case "StartConfigurationRecorder" -> startConfigurationRecorder(request, region);
|
||||
case "StopConfigurationRecorder" -> stopConfigurationRecorder(request, region);
|
||||
case "DescribeConfigurationRecorderStatus" -> describeConfigurationRecorderStatus(request, region);
|
||||
case "PutDeliveryChannel" -> putDeliveryChannel(request, region);
|
||||
case "DescribeDeliveryChannels" -> describeDeliveryChannels(request, region);
|
||||
case "DeleteDeliveryChannel" -> deleteDeliveryChannel(request, region);
|
||||
case "PutRetentionConfiguration" -> putRetentionConfiguration(request, region);
|
||||
case "DescribeRetentionConfigurations" -> describeRetentionConfigurations(request, region);
|
||||
case "DeleteRetentionConfiguration" -> deleteRetentionConfiguration(request, region);
|
||||
case "TagResource" -> tagResource(request);
|
||||
case "UntagResource" -> untagResource(request);
|
||||
case "ListTagsForResource" -> listTagsForResource(request);
|
||||
@@ -61,14 +73,10 @@ public class ConfigServiceJsonHandler {
|
||||
|
||||
// --- Config Rules ---
|
||||
|
||||
private Response putConfigRule(JsonNode req, String region) {
|
||||
private Response putConfigRule(JsonNode req, String region) throws Exception {
|
||||
JsonNode ruleNode = req.path("ConfigRule");
|
||||
String ruleName = ruleNode.path("ConfigRuleName").asText(null);
|
||||
JsonNode sourceNode = ruleNode.path("Source");
|
||||
ConfigRuleSource source = new ConfigRuleSource(
|
||||
sourceNode.path("Owner").asText(null),
|
||||
sourceNode.path("SourceIdentifier").asText(null));
|
||||
service.putConfigRule(region, ruleName, source);
|
||||
ConfigRule rule = ruleNode.isObject() ? mapper.treeToValue(ruleNode, ConfigRule.class) : null;
|
||||
service.putConfigRule(region, rule);
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@@ -79,35 +87,33 @@ public class ConfigServiceJsonHandler {
|
||||
}
|
||||
|
||||
private Response describeConfigRules(JsonNode req, String region) {
|
||||
List<String> ruleNames = extractStringList(req, "ConfigRuleNames");
|
||||
List<ConfigRule> rules = service.describeConfigRules(region, ruleNames);
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("ConfigRules", mapper.valueToTree(rules));
|
||||
return Response.ok(resp).build();
|
||||
AwsConfigService.Paged<ConfigRule> page = service.describeConfigRulesPaged(region,
|
||||
extractStringList(req, "ConfigRuleNames"), extractNextToken(req));
|
||||
return Response.ok(pagedResponse("ConfigRules", page)).build();
|
||||
}
|
||||
|
||||
private Response describeComplianceByConfigRule(JsonNode req, String region) {
|
||||
List<String> ruleNames = extractStringList(req, "ConfigRuleNames");
|
||||
List<ConfigRule> rules = service.describeConfigRules(region, ruleNames);
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
ArrayNode arr = resp.putArray("ComplianceByConfigRules");
|
||||
for (ConfigRule rule : rules) {
|
||||
ObjectNode entry = mapper.createObjectNode();
|
||||
entry.put("ConfigRuleName", rule.configRuleName());
|
||||
ObjectNode compliance = mapper.createObjectNode();
|
||||
compliance.put("ComplianceType", "INSUFFICIENT_DATA");
|
||||
entry.set("Compliance", compliance);
|
||||
arr.add(entry);
|
||||
}
|
||||
return Response.ok(resp).build();
|
||||
var page = service.describeComplianceByConfigRule(region,
|
||||
extractStringList(req, "ConfigRuleNames"),
|
||||
extractStringList(req, "ComplianceTypes"),
|
||||
extractNextToken(req));
|
||||
return Response.ok(pagedResponse("ComplianceByConfigRules", page)).build();
|
||||
}
|
||||
|
||||
private Response describeComplianceByResource(JsonNode req, String region) {
|
||||
var page = service.describeComplianceByResource(region,
|
||||
req.path("ResourceType").asText(null),
|
||||
req.path("ResourceId").asText(null),
|
||||
extractStringList(req, "ComplianceTypes"),
|
||||
extractLimit(req, "Limit"), extractNextToken(req));
|
||||
return Response.ok(pagedResponse("ComplianceByResources", page)).build();
|
||||
}
|
||||
|
||||
private Response describeConfigRuleEvaluationStatus(JsonNode req, String region) {
|
||||
List<String> ruleNames = extractStringList(req, "ConfigRuleNames");
|
||||
List<ConfigRuleEvaluationStatus> statuses = service.describeConfigRuleEvaluationStatus(region, ruleNames);
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("ConfigRulesEvaluationStatus", mapper.valueToTree(statuses));
|
||||
return Response.ok(resp).build();
|
||||
var page = service.describeConfigRuleEvaluationStatus(region,
|
||||
extractStringList(req, "ConfigRuleNames"),
|
||||
extractLimit(req, "Limit"), extractNextToken(req));
|
||||
return Response.ok(pagedResponse("ConfigRulesEvaluationStatus", page)).build();
|
||||
}
|
||||
|
||||
private Response startConfigRulesEvaluation(JsonNode req, String region) {
|
||||
@@ -116,6 +122,66 @@ public class ConfigServiceJsonHandler {
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
// --- Evaluations ---
|
||||
|
||||
private Response putEvaluations(JsonNode req, String region) throws Exception {
|
||||
JsonNode evaluationsNode = req.path("Evaluations");
|
||||
List<ConfigEvaluation> evaluations = evaluationsNode.isArray()
|
||||
? Arrays.asList(mapper.treeToValue(evaluationsNode, ConfigEvaluation[].class))
|
||||
: List.of();
|
||||
service.putEvaluations(region,
|
||||
req.path("ResultToken").asText(null),
|
||||
evaluations,
|
||||
req.path("TestMode").asBoolean(false));
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.putArray("FailedEvaluations");
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
private Response putExternalEvaluation(JsonNode req, String region) throws Exception {
|
||||
JsonNode evaluationNode = req.path("ExternalEvaluation");
|
||||
ConfigEvaluation evaluation = evaluationNode.isObject()
|
||||
? mapper.treeToValue(evaluationNode, ConfigEvaluation.class)
|
||||
: null;
|
||||
service.putExternalEvaluation(region, req.path("ConfigRuleName").asText(null), evaluation);
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response deleteEvaluationResults(JsonNode req, String region) {
|
||||
service.deleteEvaluationResults(region, req.path("ConfigRuleName").asText(null));
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response getComplianceDetailsByConfigRule(JsonNode req, String region) {
|
||||
var page = service.getComplianceDetailsByConfigRule(region,
|
||||
req.path("ConfigRuleName").asText(null),
|
||||
extractStringList(req, "ComplianceTypes"),
|
||||
extractLimit(req, "Limit"), extractNextToken(req));
|
||||
return Response.ok(pagedResponse("EvaluationResults", page)).build();
|
||||
}
|
||||
|
||||
private Response getComplianceDetailsByResource(JsonNode req, String region) {
|
||||
var page = service.getComplianceDetailsByResource(region,
|
||||
req.path("ResourceType").asText(null),
|
||||
req.path("ResourceId").asText(null),
|
||||
extractStringList(req, "ComplianceTypes"),
|
||||
extractNextToken(req));
|
||||
return Response.ok(pagedResponse("EvaluationResults", page)).build();
|
||||
}
|
||||
|
||||
private Response getComplianceSummaryByConfigRule(String region) {
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("ComplianceSummary", mapper.valueToTree(service.getComplianceSummaryByConfigRule(region)));
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
private Response getComplianceSummaryByResourceType(JsonNode req, String region) {
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("ComplianceSummariesByResourceType", mapper.valueToTree(
|
||||
service.getComplianceSummaryByResourceType(region, extractStringList(req, "ResourceTypes"))));
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
// --- Configuration Recorder ---
|
||||
|
||||
private Response putConfigurationRecorder(JsonNode req, String region) throws Exception {
|
||||
@@ -132,6 +198,11 @@ public class ConfigServiceJsonHandler {
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
private Response deleteConfigurationRecorder(JsonNode req, String region) {
|
||||
service.deleteConfigurationRecorder(region, req.path("ConfigurationRecorderName").asText(null));
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private Response startConfigurationRecorder(JsonNode req, String region) {
|
||||
String name = req.path("ConfigurationRecorderName").asText(null);
|
||||
service.startConfigurationRecorder(region, name);
|
||||
@@ -168,6 +239,34 @@ public class ConfigServiceJsonHandler {
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
private Response deleteDeliveryChannel(JsonNode req, String region) {
|
||||
service.deleteDeliveryChannel(region, req.path("DeliveryChannelName").asText(null));
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
// --- Retention Configuration ---
|
||||
|
||||
private Response putRetentionConfiguration(JsonNode req, String region) {
|
||||
Integer days = req.hasNonNull("RetentionPeriodInDays") ? req.path("RetentionPeriodInDays").asInt() : null;
|
||||
RetentionConfiguration configuration = service.putRetentionConfiguration(region, days);
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("RetentionConfiguration", mapper.valueToTree(configuration));
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
private Response describeRetentionConfigurations(JsonNode req, String region) {
|
||||
List<RetentionConfiguration> configurations = service.describeRetentionConfigurations(region,
|
||||
extractStringList(req, "RetentionConfigurationNames"));
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("RetentionConfigurations", mapper.valueToTree(configurations));
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
private Response deleteRetentionConfiguration(JsonNode req, String region) {
|
||||
service.deleteRetentionConfiguration(region, req.path("RetentionConfigurationName").asText(null));
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
// --- Conformance Packs ---
|
||||
|
||||
private Response putConformancePack(JsonNode req, String region) {
|
||||
@@ -187,19 +286,17 @@ public class ConfigServiceJsonHandler {
|
||||
}
|
||||
|
||||
private Response describeConformancePacks(JsonNode req, String region) {
|
||||
List<String> names = extractStringList(req, "ConformancePackNames");
|
||||
List<ConformancePack> packs = service.describeConformancePacks(region, names);
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("ConformancePackDetails", mapper.valueToTree(packs));
|
||||
return Response.ok(resp).build();
|
||||
var page = service.describeConformancePacksPaged(region,
|
||||
extractStringList(req, "ConformancePackNames"),
|
||||
extractLimit(req, "Limit"), extractNextToken(req));
|
||||
return Response.ok(pagedResponse("ConformancePackDetails", page)).build();
|
||||
}
|
||||
|
||||
private Response describeConformancePackStatus(JsonNode req, String region) {
|
||||
List<String> names = extractStringList(req, "ConformancePackNames");
|
||||
List<ConformancePackStatusDetail> statuses = service.describeConformancePackStatus(region, names);
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("ConformancePackStatusDetails", mapper.valueToTree(statuses));
|
||||
return Response.ok(resp).build();
|
||||
var page = service.describeConformancePackStatus(region,
|
||||
extractStringList(req, "ConformancePackNames"),
|
||||
extractLimit(req, "Limit"), extractNextToken(req));
|
||||
return Response.ok(pagedResponse("ConformancePackStatusDetails", page)).build();
|
||||
}
|
||||
|
||||
// --- Tagging ---
|
||||
@@ -239,4 +336,25 @@ public class ConfigServiceJsonHandler {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Integer extractLimit(JsonNode req) {
|
||||
return extractLimit(req, "MaxResults");
|
||||
}
|
||||
|
||||
private Integer extractLimit(JsonNode req, String fieldName) {
|
||||
return req.hasNonNull(fieldName) ? req.path(fieldName).asInt() : null;
|
||||
}
|
||||
|
||||
private String extractNextToken(JsonNode req) {
|
||||
return req.hasNonNull("NextToken") ? req.path("NextToken").asText() : null;
|
||||
}
|
||||
|
||||
private ObjectNode pagedResponse(String fieldName, AwsConfigService.Paged<?> page) {
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set(fieldName, mapper.valueToTree(page.items()));
|
||||
if (page.nextToken() != null) {
|
||||
resp.put("NextToken", page.nextToken());
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Compliance(
|
||||
@JsonProperty("ComplianceType") String complianceType,
|
||||
@JsonProperty("ComplianceContributorCount") ComplianceContributorCount complianceContributorCount) {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ComplianceByConfigRule(
|
||||
@JsonProperty("ConfigRuleName") String configRuleName,
|
||||
@JsonProperty("Compliance") Compliance compliance) {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ComplianceByResource(
|
||||
@JsonProperty("ResourceType") String resourceType,
|
||||
@JsonProperty("ResourceId") String resourceId,
|
||||
@JsonProperty("Compliance") Compliance compliance) {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ComplianceContributorCount(
|
||||
@JsonProperty("CappedCount") Integer cappedCount,
|
||||
@JsonProperty("CapExceeded") Boolean capExceeded) {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ComplianceSummary(
|
||||
@JsonProperty("CompliantResourceCount") ComplianceContributorCount compliantResourceCount,
|
||||
@JsonProperty("NonCompliantResourceCount") ComplianceContributorCount nonCompliantResourceCount,
|
||||
@JsonProperty("ComplianceSummaryTimestamp") Long complianceSummaryTimestamp) {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ComplianceSummaryByResourceType(
|
||||
@JsonProperty("ResourceType") String resourceType,
|
||||
@JsonProperty("ComplianceSummary") ComplianceSummary complianceSummary) {
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ConfigEvaluation(
|
||||
@JsonProperty("ComplianceResourceType") String complianceResourceType,
|
||||
@JsonProperty("ComplianceResourceId") String complianceResourceId,
|
||||
@JsonProperty("ComplianceType") String complianceType,
|
||||
@JsonProperty("Annotation") String annotation,
|
||||
@JsonProperty("OrderingTimestamp") Double orderingTimestamp,
|
||||
@JsonProperty("ResultRecordedTime") Long resultRecordedTime,
|
||||
@JsonProperty("ConfigRuleInvokedTime") Long configRuleInvokedTime) {
|
||||
}
|
||||
+9
-1
@@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@@ -12,6 +14,12 @@ public record ConfigRule(
|
||||
@JsonProperty("ConfigRuleName") String configRuleName,
|
||||
@JsonProperty("ConfigRuleArn") String configRuleArn,
|
||||
@JsonProperty("ConfigRuleId") String configRuleId,
|
||||
@JsonProperty("Description") String description,
|
||||
@JsonProperty("Scope") Scope scope,
|
||||
@JsonProperty("Source") ConfigRuleSource source,
|
||||
@JsonProperty("InputParameters") String inputParameters,
|
||||
@JsonProperty("MaximumExecutionFrequency") String maximumExecutionFrequency,
|
||||
@JsonProperty("ConfigRuleState") String configRuleState,
|
||||
@JsonProperty("Source") ConfigRuleSource source) {
|
||||
@JsonProperty("CreatedBy") String createdBy,
|
||||
@JsonProperty("EvaluationModes") List<EvaluationModeConfiguration> evaluationModes) {
|
||||
}
|
||||
+4
-1
@@ -12,5 +12,8 @@ public record ConfigRuleEvaluationStatus(
|
||||
@JsonProperty("ConfigRuleName") String configRuleName,
|
||||
@JsonProperty("ConfigRuleArn") String configRuleArn,
|
||||
@JsonProperty("ConfigRuleId") String configRuleId,
|
||||
@JsonProperty("FirstEvaluationStarted") Boolean firstEvaluationStarted) {
|
||||
@JsonProperty("FirstEvaluationStarted") Boolean firstEvaluationStarted,
|
||||
@JsonProperty("FirstActivatedTime") Long firstActivatedTime,
|
||||
@JsonProperty("LastSuccessfulInvocationTime") Long lastSuccessfulInvocationTime,
|
||||
@JsonProperty("LastSuccessfulEvaluationTime") Long lastSuccessfulEvaluationTime) {
|
||||
}
|
||||
+5
-1
@@ -5,10 +5,14 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ConfigRuleSource(
|
||||
@JsonProperty("Owner") String owner,
|
||||
@JsonProperty("SourceIdentifier") String sourceIdentifier) {
|
||||
@JsonProperty("SourceIdentifier") String sourceIdentifier,
|
||||
@JsonProperty("SourceDetails") List<SourceDetail> sourceDetails,
|
||||
@JsonProperty("CustomPolicyDetails") CustomPolicyDetails customPolicyDetails) {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record CustomPolicyDetails(
|
||||
@JsonProperty("PolicyRuntime") String policyRuntime,
|
||||
@JsonProperty("PolicyText") String policyText,
|
||||
@JsonProperty("EnableDebugLogDelivery") Boolean enableDebugLogDelivery) {
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record EvaluationModeConfiguration(
|
||||
@JsonProperty("Mode") String mode) {
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record EvaluationResult(
|
||||
@JsonProperty("EvaluationResultIdentifier") EvaluationResultIdentifier evaluationResultIdentifier,
|
||||
@JsonProperty("ComplianceType") String complianceType,
|
||||
@JsonProperty("ResultRecordedTime") Long resultRecordedTime,
|
||||
@JsonProperty("ConfigRuleInvokedTime") Long configRuleInvokedTime,
|
||||
@JsonProperty("Annotation") String annotation,
|
||||
@JsonProperty("ResultToken") String resultToken) {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record EvaluationResultIdentifier(
|
||||
@JsonProperty("EvaluationResultQualifier") EvaluationResultQualifier evaluationResultQualifier,
|
||||
@JsonProperty("OrderingTimestamp") Double orderingTimestamp) {
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record EvaluationResultQualifier(
|
||||
@JsonProperty("ConfigRuleName") String configRuleName,
|
||||
@JsonProperty("ResourceType") String resourceType,
|
||||
@JsonProperty("ResourceId") String resourceId,
|
||||
@JsonProperty("EvaluationMode") String evaluationMode) {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record RetentionConfiguration(
|
||||
@JsonProperty("Name") String name,
|
||||
@JsonProperty("RetentionPeriodInDays") Integer retentionPeriodInDays) {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record Scope(
|
||||
@JsonProperty("ComplianceResourceTypes") List<String> complianceResourceTypes,
|
||||
@JsonProperty("TagKey") String tagKey,
|
||||
@JsonProperty("TagValue") String tagValue,
|
||||
@JsonProperty("ComplianceResourceId") String complianceResourceId) {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record SourceDetail(
|
||||
@JsonProperty("EventSource") String eventSource,
|
||||
@JsonProperty("MessageType") String messageType,
|
||||
@JsonProperty("MaximumExecutionFrequency") String maximumExecutionFrequency) {
|
||||
}
|
||||
Reference in new issue
Block a user