mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
feat(eventbridge): add Connection API actions (#1897)
* feat(eventbridge): add Connection model and state enum * feat(eventbridge): wire connection storage through EventBridgeService * feat(eventbridge): implement CreateConnection * feat(eventbridge): implement DescribeConnection and ListConnections * feat(eventbridge): implement UpdateConnection and DeleteConnection * feat(eventbridge): build connection responses with credential sanitization * feat(eventbridge): dispatch Connection actions in EventBridgeHandler * test(eventbridge): add Connection lifecycle integration test * test(eventbridge): cover connection secret stripping and validation errors * docs(eventbridge): document Connection actions * fix(eventbridge): register ConnectionState for reflection and validate auth type changes * chore: remove stray PR body helper file * fix(eventbridge): default IsValueSecret to true when omitted on connection parameters IsValueSecret is optional on Connection header/query/body parameters, and AWS treats an omitted flag as secret. Reading it with asBoolean(false) inverted that default, so a parameter that simply didn't set the flag came back in cleartext from DescribeConnection instead of masked. Reported by @abanna on PR #1897. * test(eventbridge): cover DescribeConnection masking when IsValueSecret is omitted Reproduces the leak abanna reported on PR #1897: a header parameter that doesn't set IsValueSecret must still come back masked, not in cleartext. Fails against the pre-fix asBoolean(false) default.
This commit is contained in:
1 parent
846e78db12
commit
36a55f5060
8 files changed
+680
No files matched your search
@@ -34,6 +34,11 @@
|
||||
| `UpdateArchive` | - |
|
||||
| `DeleteArchive` | - |
|
||||
| `ListArchives` | - |
|
||||
| `CreateConnection` | Create a connection for API destinations (credential values are stored but never returned) |
|
||||
| `DescribeConnection` | Get connection details with credential values stripped |
|
||||
| `UpdateConnection` | Update connection description, auth type, or auth parameters |
|
||||
| `DeleteConnection` | Delete a connection |
|
||||
| `ListConnections` | List connections, optionally filtered by name prefix or state |
|
||||
| `StartReplay` | - |
|
||||
| `DescribeReplay` | - |
|
||||
| `CancelReplay` | - |
|
||||
|
||||
+179
@@ -6,6 +6,8 @@ import io.github.hectorvent.floci.core.common.AwsJson11Controller;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Archive;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ArchiveState;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.BatchParameters;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Connection;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ConnectionState;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.EventBus;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.InputTransformer;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Replay;
|
||||
@@ -77,6 +79,11 @@ public class EventBridgeHandler {
|
||||
case "UpdateArchive" -> handleUpdateArchive(request, region);
|
||||
case "DeleteArchive" -> handleDeleteArchive(request, region);
|
||||
case "ListArchives" -> handleListArchives(request, region);
|
||||
case "CreateConnection" -> handleCreateConnection(request, region);
|
||||
case "DescribeConnection" -> handleDescribeConnection(request, region);
|
||||
case "UpdateConnection" -> handleUpdateConnection(request, region);
|
||||
case "DeleteConnection" -> handleDeleteConnection(request, region);
|
||||
case "ListConnections" -> handleListConnections(request, region);
|
||||
case "StartReplay" -> handleStartReplay(request, region);
|
||||
case "DescribeReplay" -> handleDescribeReplay(request, region);
|
||||
case "CancelReplay" -> handleCancelReplay(request, region);
|
||||
@@ -465,6 +472,73 @@ public class EventBridgeHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Connections ────────────────────────────
|
||||
|
||||
private Response handleCreateConnection(JsonNode request, String region) {
|
||||
Connection connection = eventBridgeService.createConnection(
|
||||
request.path("Name").asText(null),
|
||||
request.path("Description").asText(null),
|
||||
request.path("AuthorizationType").asText(null),
|
||||
objectAsJson(request.path("AuthParameters")),
|
||||
objectAsJson(request.path("InvocationConnectivityParameters")),
|
||||
request.path("KmsKeyIdentifier").asText(null),
|
||||
region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("ConnectionArn", connection.getConnectionArn());
|
||||
response.put("ConnectionState", connection.getConnectionState().name());
|
||||
response.put("CreationTime", connection.getCreationTime().getEpochSecond());
|
||||
response.put("LastModifiedTime", connection.getLastModifiedTime().getEpochSecond());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeConnection(JsonNode request, String region) {
|
||||
String name = request.path("Name").asText(null);
|
||||
Connection connection = eventBridgeService.describeConnection(name, region);
|
||||
return Response.ok(buildConnectionNode(connection, true)).build();
|
||||
}
|
||||
|
||||
private Response handleUpdateConnection(JsonNode request, String region) {
|
||||
Connection connection = eventBridgeService.updateConnection(
|
||||
request.path("Name").asText(null),
|
||||
request.path("Description").asText(null),
|
||||
request.path("AuthorizationType").asText(null),
|
||||
objectAsJson(request.path("AuthParameters")),
|
||||
objectAsJson(request.path("InvocationConnectivityParameters")),
|
||||
request.path("KmsKeyIdentifier").asText(null),
|
||||
region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("ConnectionArn", connection.getConnectionArn());
|
||||
response.put("ConnectionState", connection.getConnectionState().name());
|
||||
response.put("CreationTime", connection.getCreationTime().getEpochSecond());
|
||||
response.put("LastModifiedTime", connection.getLastModifiedTime().getEpochSecond());
|
||||
response.put("LastAuthorizedTime", connection.getLastAuthorizedTime().getEpochSecond());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteConnection(JsonNode request, String region) {
|
||||
String name = request.path("Name").asText(null);
|
||||
Connection connection = eventBridgeService.deleteConnection(name, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("ConnectionArn", connection.getConnectionArn());
|
||||
response.put("ConnectionState", ConnectionState.DELETING.name());
|
||||
response.put("CreationTime", connection.getCreationTime().getEpochSecond());
|
||||
response.put("LastModifiedTime", connection.getLastModifiedTime().getEpochSecond());
|
||||
response.put("LastAuthorizedTime", connection.getLastAuthorizedTime().getEpochSecond());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleListConnections(JsonNode request, String region) {
|
||||
String namePrefix = request.path("NamePrefix").asText(null);
|
||||
ConnectionState state = parseConnectionState(request.path("ConnectionState").asText(null));
|
||||
List<Connection> connections = eventBridgeService.listConnections(namePrefix, state, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode connectionsArray = response.putArray("Connections");
|
||||
for (Connection connection : connections) {
|
||||
connectionsArray.add(buildConnectionNode(connection, false));
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Replays ────────────────────────────
|
||||
|
||||
private Response handleStartReplay(JsonNode request, String region) {
|
||||
@@ -627,6 +701,96 @@ public class EventBridgeHandler {
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode buildConnectionNode(Connection connection, boolean full) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("Name", connection.getName());
|
||||
node.put("ConnectionArn", connection.getConnectionArn());
|
||||
node.put("ConnectionState", connection.getConnectionState().name());
|
||||
node.put("AuthorizationType", connection.getAuthorizationType());
|
||||
if (connection.getStateReason() != null) {
|
||||
node.put("StateReason", connection.getStateReason());
|
||||
}
|
||||
if (connection.getCreationTime() != null) {
|
||||
node.put("CreationTime", connection.getCreationTime().getEpochSecond());
|
||||
}
|
||||
if (connection.getLastModifiedTime() != null) {
|
||||
node.put("LastModifiedTime", connection.getLastModifiedTime().getEpochSecond());
|
||||
}
|
||||
if (connection.getLastAuthorizedTime() != null) {
|
||||
node.put("LastAuthorizedTime", connection.getLastAuthorizedTime().getEpochSecond());
|
||||
}
|
||||
if (full) {
|
||||
if (connection.getDescription() != null) {
|
||||
node.put("Description", connection.getDescription());
|
||||
}
|
||||
node.put("SecretArn", connection.getSecretArn());
|
||||
if (connection.getKmsKeyIdentifier() != null) {
|
||||
node.put("KmsKeyIdentifier", connection.getKmsKeyIdentifier());
|
||||
}
|
||||
JsonNode authParameters = sanitizeAuthParameters(connection.getAuthParameters());
|
||||
if (authParameters != null) {
|
||||
node.set("AuthParameters", authParameters);
|
||||
}
|
||||
JsonNode connectivity = readJson(connection.getInvocationConnectivityParameters());
|
||||
if (connectivity != null) {
|
||||
node.set("InvocationConnectivityParameters", connectivity);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips secret values from stored connection auth parameters, matching what
|
||||
* AWS DescribeConnection returns: credential fields are removed and invocation
|
||||
* http parameter values flagged as secret are masked.
|
||||
*/
|
||||
private JsonNode sanitizeAuthParameters(String authParametersJson) {
|
||||
JsonNode parsed = readJson(authParametersJson);
|
||||
if (!(parsed instanceof ObjectNode authParameters)) {
|
||||
return parsed;
|
||||
}
|
||||
if (authParameters.path("ApiKeyAuthParameters") instanceof ObjectNode apiKey) {
|
||||
apiKey.remove("ApiKeyValue");
|
||||
}
|
||||
if (authParameters.path("BasicAuthParameters") instanceof ObjectNode basic) {
|
||||
basic.remove("Password");
|
||||
}
|
||||
if (authParameters.path("OAuthParameters") instanceof ObjectNode oauth) {
|
||||
if (oauth.path("ClientParameters") instanceof ObjectNode client) {
|
||||
client.remove("ClientSecret");
|
||||
}
|
||||
maskSecretHttpParameters(oauth.path("OAuthHttpParameters"));
|
||||
}
|
||||
maskSecretHttpParameters(authParameters.path("InvocationHttpParameters"));
|
||||
return authParameters;
|
||||
}
|
||||
|
||||
private void maskSecretHttpParameters(JsonNode httpParameters) {
|
||||
if (!httpParameters.isObject()) {
|
||||
return;
|
||||
}
|
||||
for (String field : List.of("BodyParameters", "HeaderParameters", "QueryStringParameters")) {
|
||||
for (JsonNode parameter : httpParameters.path(field)) {
|
||||
// IsValueSecret is optional; an omitted flag means "treat as secret" on AWS.
|
||||
if (parameter instanceof ObjectNode param && param.path("IsValueSecret").asBoolean(true)) {
|
||||
param.put("Value", "*");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JsonNode readJson(String json) {
|
||||
if (json == null || json.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.readTree(json);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Failed to parse stored connection parameters: {0}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ObjectNode buildReplayNode(Replay replay, boolean full) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("ReplayName", replay.getReplayName());
|
||||
@@ -672,6 +836,21 @@ public class EventBridgeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private ConnectionState parseConnectionState(String state) {
|
||||
if (state == null || state.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return ConnectionState.valueOf(state);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String objectAsJson(JsonNode node) {
|
||||
return (node.isObject() && !node.isEmpty()) ? node.toString() : null;
|
||||
}
|
||||
|
||||
private ReplayState parseReplayState(String state) {
|
||||
if (state == null || state.isBlank()) return null;
|
||||
try {
|
||||
|
||||
+141
@@ -11,6 +11,8 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Archive;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ArchiveState;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ArchivedEvent;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Connection;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ConnectionState;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.EventBus;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Replay;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.ReplayState;
|
||||
@@ -36,6 +38,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class EventBridgeService {
|
||||
@@ -48,6 +51,7 @@ public class EventBridgeService {
|
||||
private final StorageBackend<String, Archive> archiveStore;
|
||||
private final StorageBackend<String, List<ArchivedEvent>> archivedEventStore;
|
||||
private final StorageBackend<String, Replay> replayStore;
|
||||
private final StorageBackend<String, Connection> connectionStore;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final RuleScheduler ruleScheduler;
|
||||
@@ -77,6 +81,8 @@ public class EventBridgeService {
|
||||
new TypeReference<Map<String, List<ArchivedEvent>>>() {}),
|
||||
storageFactory.create("eventbridge", "eventbridge-replays.json",
|
||||
new TypeReference<Map<String, Replay>>() {}),
|
||||
storageFactory.create("eventbridge", "eventbridge-connections.json",
|
||||
new TypeReference<Map<String, Connection>>() {}),
|
||||
regionResolver, objectMapper, ruleScheduler, invoker, replayDispatcher,
|
||||
resourceGroupsTaggingService
|
||||
);
|
||||
@@ -88,6 +94,7 @@ public class EventBridgeService {
|
||||
StorageBackend<String, Archive> archiveStore,
|
||||
StorageBackend<String, List<ArchivedEvent>> archivedEventStore,
|
||||
StorageBackend<String, Replay> replayStore,
|
||||
StorageBackend<String, Connection> connectionStore,
|
||||
RegionResolver regionResolver,
|
||||
ObjectMapper objectMapper,
|
||||
RuleScheduler ruleScheduler,
|
||||
@@ -100,6 +107,7 @@ public class EventBridgeService {
|
||||
this.archiveStore = archiveStore;
|
||||
this.archivedEventStore = archivedEventStore;
|
||||
this.replayStore = replayStore;
|
||||
this.connectionStore = connectionStore;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
this.ruleScheduler = ruleScheduler;
|
||||
@@ -1209,6 +1217,135 @@ public class EventBridgeService {
|
||||
});
|
||||
}
|
||||
|
||||
// ──────────────────────────── Connections ────────────────────────────
|
||||
|
||||
private static final Pattern CONNECTION_NAME_PATTERN =
|
||||
Pattern.compile("[\\.\\-_A-Za-z0-9]+");
|
||||
|
||||
public Connection createConnection(String name, String description, String authorizationType,
|
||||
String authParameters, String invocationConnectivityParameters,
|
||||
String kmsKeyIdentifier, String region) {
|
||||
validateConnectionName(name);
|
||||
validateAuthorizationType(authorizationType);
|
||||
if (authParameters == null) {
|
||||
throw new AwsException("ValidationException", "AuthParameters is required.", 400);
|
||||
}
|
||||
String key = connectionKey(region, name);
|
||||
if (connectionStore.get(key).isPresent()) {
|
||||
throw new AwsException("ResourceAlreadyExistsException",
|
||||
"Connection " + name + " already exists.", 400);
|
||||
}
|
||||
String connectionId = UUID.randomUUID().toString();
|
||||
Instant now = Instant.now();
|
||||
Connection connection = new Connection();
|
||||
connection.setName(name);
|
||||
connection.setConnectionArn(regionResolver.buildArn("events", region,
|
||||
"connection/" + name + "/" + connectionId));
|
||||
connection.setDescription(description);
|
||||
connection.setAuthorizationType(authorizationType);
|
||||
connection.setAuthParameters(authParameters);
|
||||
connection.setInvocationConnectivityParameters(invocationConnectivityParameters);
|
||||
connection.setKmsKeyIdentifier(kmsKeyIdentifier);
|
||||
connection.setSecretArn(regionResolver.buildArn("secretsmanager", region,
|
||||
"secret:events!connection/" + name + "/" + connectionId));
|
||||
connection.setConnectionState(ConnectionState.AUTHORIZED);
|
||||
connection.setCreationTime(now);
|
||||
connection.setLastModifiedTime(now);
|
||||
connection.setLastAuthorizedTime(now);
|
||||
connectionStore.put(key, connection);
|
||||
LOG.infov("Created connection: {0} with authorization type {1}", name, authorizationType);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public Connection describeConnection(String name, String region) {
|
||||
return connectionStore.get(connectionKey(region, name))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Connection " + name + " does not exist.", 404));
|
||||
}
|
||||
|
||||
public Connection updateConnection(String name, String description, String authorizationType,
|
||||
String authParameters, String invocationConnectivityParameters,
|
||||
String kmsKeyIdentifier, String region) {
|
||||
String key = connectionKey(region, name);
|
||||
Connection connection = connectionStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Connection " + name + " does not exist.", 404));
|
||||
if (authorizationType != null) {
|
||||
validateAuthorizationType(authorizationType);
|
||||
if (!authorizationType.equals(connection.getAuthorizationType()) && authParameters == null) {
|
||||
throw new AwsException("ValidationException",
|
||||
"AuthParameters must be provided when changing AuthorizationType.", 400);
|
||||
}
|
||||
connection.setAuthorizationType(authorizationType);
|
||||
}
|
||||
if (description != null) {
|
||||
connection.setDescription(description);
|
||||
}
|
||||
if (authParameters != null) {
|
||||
connection.setAuthParameters(authParameters);
|
||||
}
|
||||
if (invocationConnectivityParameters != null) {
|
||||
connection.setInvocationConnectivityParameters(invocationConnectivityParameters);
|
||||
}
|
||||
if (kmsKeyIdentifier != null) {
|
||||
connection.setKmsKeyIdentifier(kmsKeyIdentifier);
|
||||
}
|
||||
Instant now = Instant.now();
|
||||
connection.setConnectionState(ConnectionState.AUTHORIZED);
|
||||
connection.setLastModifiedTime(now);
|
||||
connection.setLastAuthorizedTime(now);
|
||||
connectionStore.put(key, connection);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public Connection deleteConnection(String name, String region) {
|
||||
String key = connectionKey(region, name);
|
||||
Connection connection = connectionStore.get(key)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Connection " + name + " does not exist.", 404));
|
||||
connectionStore.delete(key);
|
||||
LOG.infov("Deleted connection: {0}", name);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public List<Connection> listConnections(String namePrefix, ConnectionState state, String region) {
|
||||
String prefix = "connection:" + region + ":";
|
||||
return connectionStore.scan(k -> {
|
||||
if (!k.startsWith(prefix)) return false;
|
||||
Connection c = connectionStore.get(k).orElse(null);
|
||||
if (c == null) return false;
|
||||
if (namePrefix != null && !namePrefix.isBlank()
|
||||
&& !c.getName().startsWith(namePrefix)) {
|
||||
return false;
|
||||
}
|
||||
if (state != null && state != c.getConnectionState()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private static void validateConnectionName(String name) {
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("ValidationException", "Connection name is required.", 400);
|
||||
}
|
||||
if (name.length() > 64 || !CONNECTION_NAME_PATTERN.matcher(name).matches()) {
|
||||
throw new AwsException("ValidationException",
|
||||
"Connection name must match [\\.\\-_A-Za-z0-9]+ and be at most 64 characters.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateAuthorizationType(String authorizationType) {
|
||||
if (authorizationType == null || authorizationType.isBlank()) {
|
||||
throw new AwsException("ValidationException", "AuthorizationType is required.", 400);
|
||||
}
|
||||
switch (authorizationType) {
|
||||
case "BASIC", "OAUTH_CLIENT_CREDENTIALS", "API_KEY" -> { }
|
||||
default -> throw new AwsException("ValidationException",
|
||||
"AuthorizationType must be one of BASIC, OAUTH_CLIENT_CREDENTIALS, API_KEY.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private void captureToArchives(Map<String, Object> entry, String busStoreKey,
|
||||
String eventId, String region, String accountId) {
|
||||
EventBus bus = accountGet(busStore, accountId, busStoreKey).orElse(null);
|
||||
@@ -1389,6 +1526,10 @@ public class EventBridgeService {
|
||||
return "replay:" + region + ":" + replayName;
|
||||
}
|
||||
|
||||
private static String connectionKey(String region, String connectionName) {
|
||||
return "connection:" + region + ":" + connectionName;
|
||||
}
|
||||
|
||||
private static String archiveNameFromArn(String arn) {
|
||||
if (arn == null) return null;
|
||||
int idx = arn.lastIndexOf("archive/");
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@RegisterForReflection
|
||||
public class Connection {
|
||||
|
||||
private String name;
|
||||
private String connectionArn;
|
||||
private String description;
|
||||
private String authorizationType;
|
||||
private ConnectionState connectionState;
|
||||
private String stateReason;
|
||||
// Raw request JSON, including secret values; responses must sanitize before returning.
|
||||
private String authParameters;
|
||||
private String invocationConnectivityParameters;
|
||||
private String secretArn;
|
||||
private String kmsKeyIdentifier;
|
||||
private Instant creationTime;
|
||||
private Instant lastModifiedTime;
|
||||
private Instant lastAuthorizedTime;
|
||||
|
||||
public Connection() {}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getConnectionArn() { return connectionArn; }
|
||||
public void setConnectionArn(String connectionArn) { this.connectionArn = connectionArn; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public String getAuthorizationType() { return authorizationType; }
|
||||
public void setAuthorizationType(String authorizationType) { this.authorizationType = authorizationType; }
|
||||
|
||||
public ConnectionState getConnectionState() { return connectionState; }
|
||||
public void setConnectionState(ConnectionState connectionState) { this.connectionState = connectionState; }
|
||||
|
||||
public String getStateReason() { return stateReason; }
|
||||
public void setStateReason(String stateReason) { this.stateReason = stateReason; }
|
||||
|
||||
public String getAuthParameters() { return authParameters; }
|
||||
public void setAuthParameters(String authParameters) { this.authParameters = authParameters; }
|
||||
|
||||
public String getInvocationConnectivityParameters() { return invocationConnectivityParameters; }
|
||||
public void setInvocationConnectivityParameters(String invocationConnectivityParameters) {
|
||||
this.invocationConnectivityParameters = invocationConnectivityParameters;
|
||||
}
|
||||
|
||||
public String getSecretArn() { return secretArn; }
|
||||
public void setSecretArn(String secretArn) { this.secretArn = secretArn; }
|
||||
|
||||
public String getKmsKeyIdentifier() { return kmsKeyIdentifier; }
|
||||
public void setKmsKeyIdentifier(String kmsKeyIdentifier) { this.kmsKeyIdentifier = kmsKeyIdentifier; }
|
||||
|
||||
public Instant getCreationTime() { return creationTime; }
|
||||
public void setCreationTime(Instant creationTime) { this.creationTime = creationTime; }
|
||||
|
||||
public Instant getLastModifiedTime() { return lastModifiedTime; }
|
||||
public void setLastModifiedTime(Instant lastModifiedTime) { this.lastModifiedTime = lastModifiedTime; }
|
||||
|
||||
public Instant getLastAuthorizedTime() { return lastAuthorizedTime; }
|
||||
public void setLastAuthorizedTime(Instant lastAuthorizedTime) { this.lastAuthorizedTime = lastAuthorizedTime; }
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public enum ConnectionState {
|
||||
CREATING,
|
||||
UPDATING,
|
||||
DELETING,
|
||||
AUTHORIZED,
|
||||
DEAUTHORIZED,
|
||||
AUTHORIZING,
|
||||
DEAUTHORIZING,
|
||||
ACTIVE,
|
||||
FAILED_CONNECTIVITY
|
||||
}
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
package io.github.hectorvent.floci.services.eventbridge;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class EventBridgeConnectionIntegrationTest {
|
||||
|
||||
private static final String EB_CT = "application/x-amz-json-1.1";
|
||||
|
||||
private static String connectionArn;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createConnection() {
|
||||
connectionArn = given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.CreateConnection")
|
||||
.body("""
|
||||
{
|
||||
"Name": "test-http-ingress-connection",
|
||||
"Description": "Connection integration test",
|
||||
"AuthorizationType": "API_KEY",
|
||||
"AuthParameters": {
|
||||
"ApiKeyAuthParameters": {
|
||||
"ApiKeyName": "x-api-key",
|
||||
"ApiKeyValue": "super-secret-value"
|
||||
},
|
||||
"InvocationHttpParameters": {
|
||||
"HeaderParameters": [
|
||||
{"Key": "x-tenant", "Value": "acme", "IsValueSecret": false},
|
||||
{"Key": "x-token", "Value": "hidden-token", "IsValueSecret": true}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ConnectionArn", startsWith("arn:aws:events:us-east-1:000000000000:connection/test-http-ingress-connection/"))
|
||||
.body("ConnectionState", equalTo("AUTHORIZED"))
|
||||
.body("CreationTime", notNullValue())
|
||||
.body("LastModifiedTime", notNullValue())
|
||||
.extract().jsonPath().getString("ConnectionArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createDuplicateConnectionFails() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.CreateConnection")
|
||||
.body("""
|
||||
{
|
||||
"Name": "test-http-ingress-connection",
|
||||
"AuthorizationType": "API_KEY",
|
||||
"AuthParameters": {
|
||||
"ApiKeyAuthParameters": {"ApiKeyName": "k", "ApiKeyValue": "v"}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ResourceAlreadyExistsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void describeConnection() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeConnection")
|
||||
.body("{\"Name\":\"test-http-ingress-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("Name", equalTo("test-http-ingress-connection"))
|
||||
.body("ConnectionArn", equalTo(connectionArn))
|
||||
.body("ConnectionState", equalTo("AUTHORIZED"))
|
||||
.body("AuthorizationType", equalTo("API_KEY"))
|
||||
.body("Description", equalTo("Connection integration test"))
|
||||
.body("SecretArn", startsWith("arn:aws:secretsmanager:us-east-1:000000000000:secret:events!connection/"))
|
||||
.body("CreationTime", notNullValue())
|
||||
.body("LastAuthorizedTime", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void describeConnectionStripsSecrets() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeConnection")
|
||||
.body("{\"Name\":\"test-http-ingress-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("AuthParameters.ApiKeyAuthParameters.ApiKeyName", equalTo("x-api-key"))
|
||||
.body("AuthParameters.ApiKeyAuthParameters.ApiKeyValue", nullValue())
|
||||
.body("AuthParameters.InvocationHttpParameters.HeaderParameters[0].Value", equalTo("acme"))
|
||||
.body("AuthParameters.InvocationHttpParameters.HeaderParameters[1].Value", equalTo("*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void updateChangingAuthTypeWithoutAuthParametersFails() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.UpdateConnection")
|
||||
.body("""
|
||||
{
|
||||
"Name": "test-http-ingress-connection",
|
||||
"AuthorizationType": "BASIC"
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void updateConnection() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.UpdateConnection")
|
||||
.body("""
|
||||
{
|
||||
"Name": "test-http-ingress-connection",
|
||||
"Description": "Updated description",
|
||||
"AuthorizationType": "BASIC",
|
||||
"AuthParameters": {
|
||||
"BasicAuthParameters": {"Username": "user", "Password": "pass"}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ConnectionArn", equalTo(connectionArn))
|
||||
.body("ConnectionState", equalTo("AUTHORIZED"));
|
||||
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeConnection")
|
||||
.body("{\"Name\":\"test-http-ingress-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("Description", equalTo("Updated description"))
|
||||
.body("AuthorizationType", equalTo("BASIC"))
|
||||
.body("AuthParameters.BasicAuthParameters.Username", equalTo("user"))
|
||||
.body("AuthParameters.BasicAuthParameters.Password", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void listConnections() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.ListConnections")
|
||||
.body("{\"NamePrefix\":\"test-http-ingress\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("Connections", hasSize(1))
|
||||
.body("Connections[0].Name", equalTo("test-http-ingress-connection"))
|
||||
.body("Connections[0].ConnectionArn", equalTo(connectionArn))
|
||||
.body("Connections[0].ConnectionState", equalTo("AUTHORIZED"))
|
||||
.body("Connections[0].AuthParameters", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void describeMissingConnectionFails() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeConnection")
|
||||
.body("{\"Name\":\"no-such-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void invalidAuthorizationTypeFails() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.CreateConnection")
|
||||
.body("""
|
||||
{
|
||||
"Name": "bad-auth-connection",
|
||||
"AuthorizationType": "MAGIC",
|
||||
"AuthParameters": {
|
||||
"ApiKeyAuthParameters": {"ApiKeyName": "k", "ApiKeyValue": "v"}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void deleteConnection() {
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DeleteConnection")
|
||||
.body("{\"Name\":\"test-http-ingress-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("ConnectionArn", equalTo(connectionArn))
|
||||
.body("ConnectionState", equalTo("DELETING"));
|
||||
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeConnection")
|
||||
.body("{\"Name\":\"test-http-ingress-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void describeConnectionTreatsOmittedIsValueSecretAsSecret() {
|
||||
// IsValueSecret is optional; AWS treats an omitted flag as secret. A header
|
||||
// parameter that doesn't set it must still come back masked, not in cleartext.
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.CreateConnection")
|
||||
.body("""
|
||||
{
|
||||
"Name": "test-omitted-secret-flag-connection",
|
||||
"AuthorizationType": "API_KEY",
|
||||
"AuthParameters": {
|
||||
"ApiKeyAuthParameters": {"ApiKeyName": "k", "ApiKeyValue": "v"},
|
||||
"InvocationHttpParameters": {
|
||||
"HeaderParameters": [
|
||||
{"Key": "X-Internal-Token", "Value": "hunter2"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DescribeConnection")
|
||||
.body("{\"Name\":\"test-omitted-secret-flag-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("AuthParameters.InvocationHttpParameters.HeaderParameters[0].Value", equalTo("*"));
|
||||
|
||||
given()
|
||||
.contentType(EB_CT)
|
||||
.header("X-Amz-Target", "AWSEvents.DeleteConnection")
|
||||
.body("{\"Name\":\"test-omitted-secret-flag-connection\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
}
|
||||
+1
@@ -48,6 +48,7 @@ class EventBridgeSchedulerIntegrationTest {
|
||||
eventBridgeService = new EventBridgeService(
|
||||
busStore, ruleStore, targetStore,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new RegionResolver(REGION, ACCOUNT),
|
||||
new ObjectMapper(), scheduler, invoker, replayDispatcher,
|
||||
new ResourceGroupsTaggingService(null));
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ class EventBridgeServiceTest {
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(),
|
||||
new RegionResolver("us-east-1", "000000000000"),
|
||||
new ObjectMapper(),
|
||||
null,
|
||||
|
||||
Reference in new issue
Block a user