feat(iot): support SetV2LoggingOptions and GetV2LoggingOptions (#8945)

* feat(iot): support SetV2LoggingOptions and GetV2LoggingOptions
* fix(iot): keep omitted V2 logging options and require role and level on first set
* fix(iot): validate SetV2LoggingOptions log level and member types
* fix(iot): answer SetV2LoggingOptions with an empty body
* test(iot): cover V2 logging setup, updates, errors and account scoping in the SDK suite
* test(iot): sign V2 logging requests with the shared EnforcementFixtures.auth helper
* test(iot): cover V2 logging persistence and document eventConfigurations and verbose limits
* docs(iot): count the V2 logging routes in the service matrix
* fix(iot): reject a SetV2LoggingOptions body that is not a JSON object
* fix(iot): reject a blank roleArn in SetV2LoggingOptions
* fix(iot): serialize the SetV2LoggingOptions read-merge-write
* test(iot): share one IoT client builder in the SDK fixtures
* fix(iot): stop refusing a blank roleArn in SetV2LoggingOptions
* fix(iot): build the V2 log level refusal with SmithyValidationErrors
* refactor(iot): share IoT request body readers between logging and fleet indexing
This commit is contained in:
rajp33 authored and GitHub committed 2026-11-19 19:14:50 -04:00
1 parent b8632351e8
commit 9f959a3f27
13 files changed
+589 -27

No files matched your search

@@ -55,6 +55,7 @@ import io.floci.aws.services.iot.IotController;
import io.floci.aws.services.iot.IotDataController;
import io.floci.aws.services.iot.IotDomainConfigurationController;
import io.floci.aws.services.iot.IotFleetIndexingController;
import io.floci.aws.services.iot.IotLoggingController;
import io.floci.aws.services.lakeformation.LakeFormationController;
import io.floci.aws.services.lambda.LambdaController;
import io.floci.aws.services.lambda.durable.DurableExecutionController;
@@ -755,7 +756,8 @@ public class ResolvedServiceCatalog {
// signs under its own name while IotController serves its /things/*/jobs routes
Set.of(), Set.of("iot", "execute-api", "iot-jobs-data"), Set.of(),
Set.of(IotController.class, IotDomainConfigurationController.class,
IotAuthorizerController.class, IotFleetIndexingController.class)),
IotAuthorizerController.class, IotFleetIndexingController.class,
IotLoggingController.class)),
descriptor("iotdata", "iotdata", config.services().iotdata().enabled(), true,
"iot", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
protocols(ServiceProtocol.REST_JSON),
@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -36,6 +35,10 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.floci.aws.services.iot.IotRequestBody.requireObject;
import static io.floci.aws.services.iot.IotRequestBody.serializationError;
import static io.floci.aws.services.iot.IotRequestBody.text;
/**
* AWS IoT fleet indexing: UpdateIndexingConfiguration, GetIndexingConfiguration, DescribeIndex and
* a bounded SearchIndex. One configuration per account and region; a region never updated is OFF.
@@ -117,9 +120,7 @@ public class IotFleetIndexingService {
}
public void updateIndexingConfiguration(JsonNode request, String region) {
if (!request.isObject()) {
throw serializationError("request body", JsonNodeType.OBJECT);
}
requireObject(request);
String groupPrefix = "thingGroupIndexingConfiguration";
JsonNode thingNode = object(request.path("thingIndexingConfiguration"), "thingIndexingConfiguration");
JsonNode groupNode = object(request.path(groupPrefix), groupPrefix);
@@ -172,9 +173,7 @@ public class IotFleetIndexingService {
* whatever was deleted before it. It also carries a checksum, so an edited token is invalid.
*/
public IotService.Page<ObjectNode> searchIndex(JsonNode request, String accountId, String region) {
if (!request.isObject()) {
throw serializationError("request body", JsonNodeType.OBJECT);
}
requireObject(request);
String queryString = text(request.path("queryString"), "queryString");
JsonNode maxResults = request.path("maxResults");
if (present(maxResults) && !maxResults.isNumber()) {
@@ -525,27 +524,10 @@ public class IotFleetIndexingService {
return values;
}
/** A string member, null when it is absent or null. */
private static String text(JsonNode node, String path) {
if (!present(node)) {
return null;
}
if (!node.isTextual()) {
throw serializationError(path, JsonNodeType.STRING);
}
return node.asText();
}
private static boolean present(JsonNode node) {
return !node.isMissingNode() && !node.isNull();
}
/** A member of the wrong JSON type fails before any validation, as AWS fails to deserialize it. */
private static AwsException serializationError(String path, JsonNodeType expected) {
return new AwsException("SerializationException",
path + " must be a JSON " + expected.name().toLowerCase(Locale.ROOT), 400);
}
private static AwsException invalid(String message) {
return new AwsException("InvalidRequestException", message, 400);
}
@@ -0,0 +1,49 @@
package io.floci.aws.services.iot;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.services.iot.model.IotV2LoggingOptions;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@Path("/v2LoggingOptions")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class IotLoggingController {
private final IotLoggingService loggingService;
private final RegionResolver regionResolver;
private final ObjectMapper objectMapper;
@Inject
public IotLoggingController(IotLoggingService loggingService, RegionResolver regionResolver,
ObjectMapper objectMapper) {
this.loggingService = loggingService;
this.regionResolver = regionResolver;
this.objectMapper = objectMapper;
}
@POST
public Response setV2LoggingOptions(@Context HttpHeaders headers, String body) {
loggingService.setV2LoggingOptions(IotRequestBody.read(objectMapper, body),
regionResolver.resolveRegion(headers));
return Response.ok().build();
}
@GET
public Response getV2LoggingOptions(@Context HttpHeaders headers) {
IotV2LoggingOptions options = loggingService.getV2LoggingOptions(regionResolver.resolveRegion(headers));
return Response.ok(objectMapper.createObjectNode()
.put("roleArn", options.roleArn())
.put("defaultLogLevel", options.defaultLogLevel())
.put("disableAllLogs", options.disableAllLogs())).build();
}
}
@@ -0,0 +1,76 @@
package io.floci.aws.services.iot;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.SmithyValidationErrors;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.iot.model.IotV2LoggingOptions;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static io.floci.aws.services.iot.IotRequestBody.requireObject;
import static io.floci.aws.services.iot.IotRequestBody.serializationError;
import static io.floci.aws.services.iot.IotRequestBody.text;
@ApplicationScoped
public class IotLoggingService {
private static final List<String> LOG_LEVELS = List.of("DEBUG", "INFO", "ERROR", "WARN", "DISABLED");
private final StorageBackend<String, IotV2LoggingOptions> store;
private final Object lock = new Object();
@Inject
public IotLoggingService(StorageFactory storageFactory) {
this(storageFactory.create("iot", "iot-v2-logging-options.json",
new TypeReference<Map<String, IotV2LoggingOptions>>() {}));
}
IotLoggingService(StorageBackend<String, IotV2LoggingOptions> store) {
this.store = store;
}
public void setV2LoggingOptions(JsonNode request, String region) {
requireObject(request);
String roleArn = text(request.path("roleArn"), "roleArn");
String defaultLogLevel = text(request.path("defaultLogLevel"), "defaultLogLevel");
Boolean disableAllLogs = bool(request.path("disableAllLogs"), "disableAllLogs");
if (defaultLogLevel != null && !LOG_LEVELS.contains(defaultLogLevel)) {
throw SmithyValidationErrors.exception("InvalidRequestException",
SmithyValidationErrors.notInEnum(defaultLogLevel, "defaultLogLevel", LOG_LEVELS));
}
synchronized (lock) {
Optional<IotV2LoggingOptions> current = store.get(region);
if (current.isEmpty() && (roleArn == null || defaultLogLevel == null)) {
throw new AwsException("InvalidRequestException",
"roleArn and defaultLogLevel are required for the initial setup.", 400);
}
IotV2LoggingOptions prior = current.orElse(new IotV2LoggingOptions(null, null, false));
store.put(region, new IotV2LoggingOptions(roleArn != null ? roleArn : prior.roleArn(),
defaultLogLevel != null ? defaultLogLevel : prior.defaultLogLevel(),
disableAllLogs != null ? disableAllLogs : prior.disableAllLogs()));
}
}
public IotV2LoggingOptions getV2LoggingOptions(String region) {
return store.get(region).orElseThrow(() ->
new AwsException("NotConfiguredException", "V2 logging options are not configured.", 404));
}
private static Boolean bool(JsonNode node, String member) {
if (node.isMissingNode() || node.isNull()) {
return null;
}
if (!node.isBoolean()) {
throw serializationError(member, JsonNodeType.BOOLEAN);
}
return node.booleanValue();
}
}
@@ -4,8 +4,11 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import io.floci.aws.core.common.AwsException;
import java.util.Locale;
/**
* Reads an AWS IoT REST-JSON request body. AWS rejects a malformed body, and content after the
* JSON value, with {@code SerializationException}.
@@ -23,4 +26,27 @@ final class IotRequestBody {
throw new AwsException("SerializationException", e.getOriginalMessage(), 400);
}
}
static void requireObject(JsonNode request) {
if (!request.isObject()) {
throw serializationError("request body", JsonNodeType.OBJECT);
}
}
/** A string member, null when it is absent or null. */
static String text(JsonNode node, String path) {
if (node.isMissingNode() || node.isNull()) {
return null;
}
if (!node.isTextual()) {
throw serializationError(path, JsonNodeType.STRING);
}
return node.textValue();
}
/** A member of the wrong JSON type fails before any validation, as AWS fails to deserialize it. */
static AwsException serializationError(String path, JsonNodeType expected) {
return new AwsException("SerializationException",
path + " must be a JSON " + expected.name().toLowerCase(Locale.ROOT), 400);
}
}
@@ -0,0 +1,7 @@
package io.floci.aws.services.iot.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public record IotV2LoggingOptions(String roleArn, String defaultLogLevel, boolean disableAllLogs) {
}