feat(glue): Data Catalog connections (#3939)

* feat(glue): Data Catalog connections

Add CreateConnection, GetConnection, GetConnections, UpdateConnection,
DeleteConnection, BatchDeleteConnection and TestConnection. A connection
precedes every job and crawler in a Glue stack and Terraform reads it on
each plan, so without it a stack with an aws_glue_connection could not
get past its first plan.

Behaviour follows the Glue API reference: HidePassword omits PASSWORD
and ENCRYPTED_PASSWORD, UpdateConnection redefines the connection rather
than merging into it, ConnectionInput is validated against the documented
limits and enumerations, credentials are accepted and never returned,
and TestConnection accepts a well-formed request with an empty body
without opening a socket.

Closes #3938

* feat(glue): cap BatchDeleteConnection at 25 names and document HidePassword's scope

The API reference caps ConnectionNameList at 25 entries; a longer list
is now InvalidInputException. HidePassword's coverage of the Kafka
credential keys is not documented by AWS, so the docs page states that
Floci removes PASSWORD and ENCRYPTED_PASSWORD only.
This commit is contained in:
David authored and GitHub committed 2026-09-20 12:29:28 -04:00
1 parent 957542d172
commit a793776c1a
13 files changed
+1539 -2

No files matched your search

@@ -0,0 +1,264 @@
package io.github.hectorvent.floci.services.glue;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* The Data Catalog connection lifecycle over the JSON 1.1 protocol, in the order Terraform's
* aws_glue_connection drives it: create with tags, read on every refresh, update by full
* redefinition, delete. Each test uses its own names so the suite can run in any order.
*/
@QuarkusTest
class GlueConnectionIntegrationTest {
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
private static String unique(String prefix) {
return prefix + "-" + UUID.randomUUID().toString().substring(0, 8);
}
private static void createJdbcConnection(String name, String tagsJson) {
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.CreateConnection")
.body("""
{
"ConnectionInput": {
"Name": "%s",
"Description": "orders database",
"ConnectionType": "JDBC",
"MatchCriteria": ["orders"],
"ConnectionProperties": {
"JDBC_CONNECTION_URL": "jdbc:postgresql://db.internal:5432/orders",
"USERNAME": "app",
"PASSWORD": "s3cret"
},
"PhysicalConnectionRequirements": {
"SubnetId": "subnet-0123456789abcdef0",
"SecurityGroupIdList": ["sg-0123456789abcdef0"],
"AvailabilityZone": "us-east-1a"
}
}%s
}
""".formatted(name, tagsJson))
.when().post("/")
.then()
.statusCode(200)
.body("CreateConnectionStatus", equalTo("READY"));
}
@Test
void createConnection_thenGetConnection_returnsTheDefinitionWithServiceOwnedFields() {
String name = unique("orders");
createJdbcConnection(name, "");
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.GetConnection")
.body("{\"Name\": \"%s\"}".formatted(name))
.when().post("/")
.then()
.statusCode(200)
.body("Connection.Name", equalTo(name))
.body("Connection.ConnectionType", equalTo("JDBC"))
.body("Connection.Description", equalTo("orders database"))
.body("Connection.ConnectionProperties.PASSWORD", equalTo("s3cret"))
.body("Connection.PhysicalConnectionRequirements.SubnetId", equalTo("subnet-0123456789abcdef0"))
.body("Connection.Status", equalTo("READY"))
.body("Connection.ConnectionSchemaVersion", equalTo(1))
.body("Connection.CreationTime", notNullValue())
.body("Connection.LastUpdatedTime", notNullValue());
}
@Test
void getConnection_hidePassword_omitsThePasswordAndKeepsTheRest() {
String name = unique("hidden");
createJdbcConnection(name, "");
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.GetConnection")
.body("{\"Name\": \"%s\", \"HidePassword\": true}".formatted(name))
.when().post("/")
.then()
.statusCode(200)
.body("Connection.ConnectionProperties", not(hasKey("PASSWORD")))
.body("Connection.ConnectionProperties.USERNAME", equalTo("app"));
}
@Test
void getConnections_filterByType_returnsOnlyMatchingConnections() {
String jdbc = unique("jdbc");
createJdbcConnection(jdbc, "");
String kafka = unique("kafka");
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.CreateConnection")
.body("""
{
"ConnectionInput": {
"Name": "%s",
"ConnectionType": "KAFKA",
"ConnectionProperties": {"KAFKA_BOOTSTRAP_SERVERS": "broker:9092"}
}
}
""".formatted(kafka))
.when().post("/")
.then().statusCode(200);
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.GetConnections")
.body("{\"Filter\": {\"ConnectionType\": \"KAFKA\"}, \"MaxResults\": 100}")
.when().post("/")
.then()
.statusCode(200)
.body("ConnectionList.findAll { it.ConnectionType == 'KAFKA' }.Name", hasItem(kafka))
.body("ConnectionList.findAll { it.ConnectionType != 'KAFKA' }.size()", equalTo(0))
.body("NextToken", nullValue());
}
@Test
void updateConnection_redefinesTheConnection_droppingMembersLeftOut() {
String name = unique("redefined");
createJdbcConnection(name, "");
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.UpdateConnection")
.body("""
{
"Name": "%s",
"ConnectionInput": {
"Name": "%s",
"ConnectionType": "JDBC",
"ConnectionProperties": {
"JDBC_CONNECTION_URL": "jdbc:postgresql://db2.internal:5432/orders",
"SECRET_ID": "prod/orders"
}
}
}
""".formatted(name, name))
.when().post("/")
.then().statusCode(200);
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.GetConnection")
.body("{\"Name\": \"%s\"}".formatted(name))
.when().post("/")
.then()
.statusCode(200)
.body("Connection.ConnectionProperties.JDBC_CONNECTION_URL", equalTo("jdbc:postgresql://db2.internal:5432/orders"))
.body("Connection.ConnectionProperties.SECRET_ID", equalTo("prod/orders"))
.body("Connection.ConnectionProperties", not(hasKey("PASSWORD")))
.body("Connection", not(hasKey("Description")))
.body("Connection", not(hasKey("PhysicalConnectionRequirements")));
}
@Test
void createConnectionWithTags_tagsReadableThroughGlueAndResourceGroupsTagging() {
String name = unique("tagged");
String arn = "arn:aws:glue:us-east-1:000000000000:connection/" + name;
createJdbcConnection(name, ",\n \"Tags\": {\"env\": \"dev\"}");
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.GetTags")
.body("{\"ResourceArn\": \"%s\"}".formatted(arn))
.when().post("/")
.then()
.statusCode(200)
.body("Tags.env", equalTo("dev"));
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "ResourceGroupsTaggingAPI_20170126.GetResources")
.body("{\"ResourceARNList\": [\"%s\"]}".formatted(arn))
.when().post("/")
.then()
.statusCode(200)
.body("ResourceTagMappingList.size()", equalTo(1))
.body("ResourceTagMappingList[0].ResourceARN", equalTo(arn))
.body("ResourceTagMappingList[0].Tags[0].Key", equalTo("env"))
.body("ResourceTagMappingList[0].Tags[0].Value", equalTo("dev"));
}
@Test
void deleteConnection_removesIt_andASecondDeleteIsEntityNotFound() {
String name = unique("deleted");
createJdbcConnection(name, "");
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.DeleteConnection")
.body("{\"ConnectionName\": \"%s\"}".formatted(name))
.when().post("/")
.then().statusCode(200);
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.DeleteConnection")
.body("{\"ConnectionName\": \"%s\"}".formatted(name))
.when().post("/")
.then()
.statusCode(400)
.body("__type", equalTo("EntityNotFoundException"));
}
@Test
void batchDeleteConnection_reportsMissingNamesInErrors() {
String name = unique("batch");
createJdbcConnection(name, "");
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.BatchDeleteConnection")
.body("{\"ConnectionNameList\": [\"%s\", \"%s-absent\"]}".formatted(name, name))
.when().post("/")
.then()
.statusCode(200)
.body("Succeeded[0]", equalTo(name))
.body("Errors.'%s-absent'.ErrorCode".formatted(name), equalTo("EntityNotFoundException"));
}
@Test
void createConnection_unknownPropertyKey_isInvalidInput() {
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.CreateConnection")
.body("""
{
"ConnectionInput": {
"Name": "%s",
"ConnectionType": "JDBC",
"ConnectionProperties": {"HOSTNAME": "db"}
}
}
""".formatted(unique("bad")))
.when().post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidInputException"));
}
@Test
void testConnection_acceptsAnInlineDefinitionWithAnEmptyBody() {
given().contentType(CONTENT_TYPE)
.header("X-Amz-Target", "AWSGlue.TestConnection")
.body("""
{
"TestConnectionInput": {
"ConnectionType": "JDBC",
"ConnectionProperties": {"JDBC_CONNECTION_URL": "jdbc:mysql://h:3306/d"}
}
}
""")
.when().post("/")
.then().statusCode(200);
}
}
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -624,4 +625,116 @@ class GlueJsonHandlerTest {
return AccountAwareStorageBackend.inMemory("000000000000");
}
}
private ObjectNode connectionInput(String name) {
ObjectNode input = mapper.createObjectNode();
input.put("Name", name);
input.put("ConnectionType", "JDBC");
input.put("Description", "orders db");
input.putArray("MatchCriteria").add("orders");
ObjectNode properties = input.putObject("ConnectionProperties");
properties.put("JDBC_CONNECTION_URL", "jdbc:postgresql://db.internal:5432/orders");
properties.put("USERNAME", "app");
properties.put("PASSWORD", "s3cret");
ObjectNode placement = input.putObject("PhysicalConnectionRequirements");
placement.put("SubnetId", "subnet-0123456789abcdef0");
placement.putArray("SecurityGroupIdList").add("sg-0123456789abcdef0");
placement.put("AvailabilityZone", "us-east-1a");
return input;
}
/**
* The wire shape a Glue client reads back: CreateConnection answers with its status, and
* GetConnection returns the definition under "Connection" with numeric timestamps and no
* null-valued members, which is how the AWS SDK and the Terraform provider expect it.
*/
@Test
void createAndGetConnectionRoundTripTheDefinitionOnTheWire() throws Exception {
ObjectNode create = mapper.createObjectNode();
create.set("ConnectionInput", connectionInput("orders"));
create.putObject("Tags").put("env", "dev");
Response created = handler.handle("CreateConnection", create, REGION);
assertEquals(200, created.getStatus());
assertEquals("READY", mapper.valueToTree(created.getEntity()).get("CreateConnectionStatus").asText());
Response got = handler.handle("GetConnection", mapper.createObjectNode().put("Name", "orders"), REGION);
assertEquals(200, got.getStatus());
JsonNode connection = mapper.valueToTree(got.getEntity()).get("Connection");
assertEquals("orders", connection.get("Name").asText());
assertEquals("JDBC", connection.get("ConnectionType").asText());
assertEquals("s3cret", connection.get("ConnectionProperties").get("PASSWORD").asText());
assertEquals("subnet-0123456789abcdef0", connection.get("PhysicalConnectionRequirements").get("SubnetId").asText());
assertEquals("READY", connection.get("Status").asText());
assertEquals(1, connection.get("ConnectionSchemaVersion").asInt());
assertTrue(connection.get("CreationTime").isNumber());
assertTrue(connection.get("LastUpdatedTime").isNumber());
assertFalse(connection.has("LastUpdatedBy"));
assertFalse(connection.has("AuthenticationConfiguration"));
ObjectNode tags = mapper.createObjectNode();
tags.put("ResourceArn", "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":connection/orders");
JsonNode tagBody = mapper.valueToTree(handler.handle("GetTags", tags, REGION).getEntity());
assertEquals("dev", tagBody.get("Tags").get("env").asText());
}
@Test
void getConnectionsHonoursHidePasswordAndTheFilter() throws Exception {
ObjectNode create = mapper.createObjectNode();
create.set("ConnectionInput", connectionInput("orders"));
handler.handle("CreateConnection", create, REGION);
ObjectNode kafkaInput = connectionInput("events");
kafkaInput.put("ConnectionType", "KAFKA");
kafkaInput.putObject("ConnectionProperties").put("KAFKA_BOOTSTRAP_SERVERS", "broker:9092");
ObjectNode createKafka = mapper.createObjectNode();
createKafka.set("ConnectionInput", kafkaInput);
handler.handle("CreateConnection", createKafka, REGION);
ObjectNode list = mapper.createObjectNode();
list.put("HidePassword", true);
list.putObject("Filter").put("ConnectionType", "JDBC");
JsonNode body = mapper.valueToTree(handler.handle("GetConnections", list, REGION).getEntity());
assertEquals(1, body.get("ConnectionList").size());
JsonNode orders = body.get("ConnectionList").get(0);
assertEquals("orders", orders.get("Name").asText());
assertFalse(orders.get("ConnectionProperties").has("PASSWORD"));
assertEquals("app", orders.get("ConnectionProperties").get("USERNAME").asText());
assertFalse(body.has("NextToken"));
}
@Test
void updateDeleteAndBatchDeleteConnectionAnswerWithTheDocumentedBodies() throws Exception {
ObjectNode create = mapper.createObjectNode();
create.set("ConnectionInput", connectionInput("orders"));
handler.handle("CreateConnection", create, REGION);
ObjectNode update = mapper.createObjectNode();
update.put("Name", "orders");
ObjectNode redefinition = connectionInput("orders");
redefinition.remove("Description");
update.set("ConnectionInput", redefinition);
Response updated = handler.handle("UpdateConnection", update, REGION);
assertEquals(200, updated.getStatus());
assertEquals(0, mapper.valueToTree(updated.getEntity()).size());
JsonNode afterUpdate = mapper.valueToTree(
handler.handle("GetConnection", mapper.createObjectNode().put("Name", "orders"), REGION).getEntity())
.get("Connection");
assertFalse(afterUpdate.has("Description"));
ObjectNode batch = mapper.createObjectNode();
batch.putArray("ConnectionNameList").add("orders").add("absent");
JsonNode batchBody = mapper.valueToTree(handler.handle("BatchDeleteConnection", batch, REGION).getEntity());
assertEquals("orders", batchBody.get("Succeeded").get(0).asText());
assertEquals("EntityNotFoundException", batchBody.get("Errors").get("absent").get("ErrorCode").asText());
AwsException gone = assertThrows(AwsException.class, () -> handler.handle(
"DeleteConnection", mapper.createObjectNode().put("ConnectionName", "orders"), REGION));
assertEquals("EntityNotFoundException", gone.getErrorCode());
ObjectNode test = mapper.createObjectNode();
ObjectNode inline = test.putObject("TestConnectionInput");
inline.put("ConnectionType", "JDBC");
inline.putObject("ConnectionProperties").put("JDBC_CONNECTION_URL", "jdbc:mysql://h:3306/d");
assertEquals(200, handler.handle("TestConnection", test, REGION).getStatus());
}
}
@@ -10,7 +10,11 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.glue.model.Classifier;
import io.github.hectorvent.floci.services.glue.model.Column;
import io.github.hectorvent.floci.services.glue.model.Database;
import io.github.hectorvent.floci.services.glue.model.Connection;
import io.github.hectorvent.floci.services.glue.model.ConnectionInput;
import io.github.hectorvent.floci.services.glue.model.Crawler;
import io.github.hectorvent.floci.services.glue.model.AuthenticationConfiguration;
import io.github.hectorvent.floci.services.glue.model.PhysicalConnectionRequirements;
import io.github.hectorvent.floci.services.glue.model.CrawlerTargets;
import io.github.hectorvent.floci.services.glue.model.Job;
import io.github.hectorvent.floci.services.glue.model.JobCommand;
@@ -35,6 +39,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import java.util.concurrent.CountDownLatch;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -88,6 +93,7 @@ class GlueServiceTest {
new InMemoryStorage<String, Job>(),
new InMemoryStorage<String, Crawler>(),
new InMemoryStorage<String, Classifier>(),
new InMemoryStorage<String, Connection>(),
schemaRegistryService, regionResolver, new ResourceGroupsTaggingService(null));
glueService.createDatabase(new Database("db1"));
}
@@ -1385,7 +1391,7 @@ class GlueServiceTest {
assertEquals("plain", errors.get(0).tableName());
assertEquals(1, glueService.getTableVersions("db1", "plain").size(), "only the current version is left");
List<String> tooMany = java.util.stream.IntStream.rangeClosed(1, 101)
List<String> tooMany = IntStream.rangeClosed(1, 101)
.mapToObj(String::valueOf).toList();
AwsException overCap = assertThrows(AwsException.class,
() -> glueService.batchDeleteTableVersions("db1", "plain", tooMany));
@@ -1480,6 +1486,240 @@ class GlueServiceTest {
assertNull(second.nextToken());
}
// ---- Connections -----------------------------------------------------------------------
private static ConnectionInput jdbcConnection(String name) {
ConnectionInput input = new ConnectionInput();
input.setName(name);
input.setConnectionType("JDBC");
input.setDescription("orders db");
input.setMatchCriteria(List.of("orders", "reporting"));
Map<String, String> properties = new LinkedHashMap<>();
properties.put("JDBC_CONNECTION_URL", "jdbc:postgresql://db.internal:5432/orders");
properties.put("USERNAME", "app");
properties.put("PASSWORD", "s3cret");
input.setConnectionProperties(properties);
PhysicalConnectionRequirements placement = new PhysicalConnectionRequirements();
placement.setSubnetId("subnet-0123456789abcdef0");
placement.setSecurityGroupIdList(List.of("sg-0123456789abcdef0"));
placement.setAvailabilityZone("us-east-1a");
input.setPhysicalConnectionRequirements(placement);
return input;
}
@Test
void connectionCanBeCreatedFetchedUpdatedAndDeleted() {
assertEquals("READY", glueService.createConnection(jdbcConnection("orders"), null, REGION));
Connection fetched = glueService.getConnection("orders", false);
assertEquals("orders", fetched.getName());
assertEquals("JDBC", fetched.getConnectionType());
assertEquals("orders db", fetched.getDescription());
assertEquals("s3cret", fetched.getConnectionProperties().get("PASSWORD"));
assertEquals("subnet-0123456789abcdef0", fetched.getPhysicalConnectionRequirements().getSubnetId());
assertEquals("READY", fetched.getStatus());
assertEquals(1, fetched.getConnectionSchemaVersion());
assertNotNull(fetched.getCreationTime());
assertEquals(fetched.getCreationTime(), fetched.getLastUpdatedTime());
// UpdateConnection redefines the connection: the description left out of the input is
// gone afterwards, the name and creation time survive, and the update time moves.
ConnectionInput redefinition = new ConnectionInput();
redefinition.setName("orders");
redefinition.setConnectionType("JDBC");
redefinition.setConnectionProperties(Map.of("JDBC_CONNECTION_URL", "jdbc:postgresql://db2.internal:5432/orders"));
glueService.updateConnection("orders", redefinition);
Connection updated = glueService.getConnection("orders", false);
assertEquals("jdbc:postgresql://db2.internal:5432/orders", updated.getConnectionProperties().get("JDBC_CONNECTION_URL"));
assertNull(updated.getConnectionProperties().get("PASSWORD"));
assertNull(updated.getDescription());
assertNull(updated.getPhysicalConnectionRequirements());
assertEquals(fetched.getCreationTime(), updated.getCreationTime());
assertFalse(updated.getLastUpdatedTime().isBefore(fetched.getLastUpdatedTime()));
glueService.deleteConnection("orders", REGION);
AwsException ex = assertThrows(AwsException.class, () -> glueService.getConnection("orders", false));
assertEquals("EntityNotFoundException", ex.getErrorCode());
}
@Test
void connectionRejectsDuplicateCreationAndUpdateOfAMissingOne() {
glueService.createConnection(jdbcConnection("dup"), null, REGION);
AwsException duplicate = assertThrows(AwsException.class,
() -> glueService.createConnection(jdbcConnection("dup"), null, REGION));
assertEquals("AlreadyExistsException", duplicate.getErrorCode());
AwsException missing = assertThrows(AwsException.class,
() -> glueService.updateConnection("absent", jdbcConnection("absent")));
assertEquals("EntityNotFoundException", missing.getErrorCode());
AwsException missingDelete = assertThrows(AwsException.class,
() -> glueService.deleteConnection("absent", REGION));
assertEquals("EntityNotFoundException", missingDelete.getErrorCode());
}
@Test
void connectionInputIsValidatedAgainstTheApiReference() {
ConnectionInput noName = jdbcConnection("x");
noName.setName(" ");
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.createConnection(noName, null, REGION)).getErrorCode());
ConnectionInput longName = jdbcConnection("n".repeat(256));
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.createConnection(longName, null, REGION)).getErrorCode());
ConnectionInput unknownType = jdbcConnection("t");
unknownType.setConnectionType("FTP");
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.createConnection(unknownType, null, REGION)).getErrorCode());
ConnectionInput noProperties = jdbcConnection("p");
noProperties.setConnectionProperties(null);
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.createConnection(noProperties, null, REGION)).getErrorCode());
ConnectionInput unknownKey = jdbcConnection("k");
unknownKey.setConnectionProperties(Map.of("HOSTNAME", "db"));
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.createConnection(unknownKey, null, REGION)).getErrorCode());
ConnectionInput tooManyCriteria = jdbcConnection("m");
tooManyCriteria.setMatchCriteria(List.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"));
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.createConnection(tooManyCriteria, null, REGION)).getErrorCode());
// A NETWORK connection carries no properties at all, only VPC placement.
ConnectionInput network = jdbcConnection("vpc-only");
network.setConnectionType("NETWORK");
network.setConnectionProperties(Map.of());
assertEquals("READY", glueService.createConnection(network, null, REGION));
}
@Test
void hidePasswordDropsThePasswordPropertiesAndNothingElse() {
ConnectionInput input = jdbcConnection("hidden");
Map<String, String> properties = new LinkedHashMap<>(input.getConnectionProperties());
properties.put("ENCRYPTED_PASSWORD", "AQICAHg...");
properties.put("SECRET_ID", "prod/orders");
input.setConnectionProperties(properties);
glueService.createConnection(input, null, REGION);
Connection hidden = glueService.getConnection("hidden", true);
assertNull(hidden.getConnectionProperties().get("PASSWORD"));
assertNull(hidden.getConnectionProperties().get("ENCRYPTED_PASSWORD"));
assertEquals("app", hidden.getConnectionProperties().get("USERNAME"));
assertEquals("prod/orders", hidden.getConnectionProperties().get("SECRET_ID"));
// The stored connection is untouched: a later read without the flag has the password.
assertEquals("s3cret", glueService.getConnection("hidden", false).getConnectionProperties().get("PASSWORD"));
assertEquals("s3cret",
glueService.getConnections(null, null, null, false, null, null).items().get(0)
.getConnectionProperties().get("PASSWORD"));
assertNull(glueService.getConnections(null, null, null, true, null, null).items().get(0)
.getConnectionProperties().get("PASSWORD"));
}
@Test
void getConnectionsFiltersByCriteriaTypeAndSchemaVersionAndPages() {
glueService.createConnection(jdbcConnection("b-orders"), null, REGION);
ConnectionInput kafka = jdbcConnection("a-events");
kafka.setConnectionType("KAFKA");
kafka.setMatchCriteria(List.of("events"));
kafka.setConnectionProperties(Map.of("KAFKA_BOOTSTRAP_SERVERS", "broker:9092"));
glueService.createConnection(kafka, null, REGION);
ConnectionInput saas = jdbcConnection("c-crm");
saas.setConnectionType("SALESFORCE");
saas.setMatchCriteria(null);
saas.setConnectionProperties(Map.of("ROLE_ARN", "arn:aws:iam::000000000000:role/crm"));
AuthenticationConfiguration auth = new AuthenticationConfiguration();
auth.setAuthenticationType("OAUTH2");
auth.setSecretArn("arn:aws:secretsmanager:us-east-1:000000000000:secret:crm");
auth.setBasicAuthenticationCredentials(Map.of("Username", "u", "Password", "p"));
saas.setAuthenticationConfiguration(auth);
glueService.createConnection(saas, null, REGION);
List<Connection> all = glueService.getConnections(null, null, null, false, null, null).items();
assertEquals(List.of("a-events", "b-orders", "c-crm"), all.stream().map(Connection::getName).toList());
assertEquals(List.of("b-orders"),
glueService.getConnections(List.of("orders", "reporting"), null, null, false, null, null)
.items().stream().map(Connection::getName).toList());
assertTrue(glueService.getConnections(List.of("orders", "missing"), null, null, false, null, null)
.items().isEmpty());
assertEquals(List.of("a-events"),
glueService.getConnections(null, "KAFKA", null, false, null, null)
.items().stream().map(Connection::getName).toList());
assertEquals(List.of("c-crm"),
glueService.getConnections(null, null, 2, false, null, null)
.items().stream().map(Connection::getName).toList());
// A credential given on create never comes back on a read.
Connection crm = glueService.getConnection("c-crm", false);
assertEquals("OAUTH2", crm.getAuthenticationConfiguration().getAuthenticationType());
assertNull(crm.getAuthenticationConfiguration().getBasicAuthenticationCredentials());
GlueService.Page<Connection> first = glueService.getConnections(null, null, null, false, 2, null);
assertEquals(2, first.items().size());
assertNotNull(first.nextToken());
GlueService.Page<Connection> second = glueService.getConnections(null, null, null, false, 2, first.nextToken());
assertEquals(List.of("c-crm"), second.items().stream().map(Connection::getName).toList());
assertNull(second.nextToken());
}
@Test
void batchDeleteConnectionReportsTheMissingNamesAndDeletesTheRest() {
glueService.createConnection(jdbcConnection("keep-a"), null, REGION);
glueService.createConnection(jdbcConnection("keep-b"), null, REGION);
GlueService.BatchDeleteConnectionResult result =
glueService.batchDeleteConnections(List.of("keep-a", "absent", "keep-b"), REGION);
assertEquals(List.of("keep-a", "keep-b"), result.succeeded());
assertEquals(1, result.errors().size());
assertEquals("EntityNotFoundException", result.errors().get("absent").errorCode());
assertTrue(glueService.getConnections(null, null, null, false, null, null).items().isEmpty());
// The reference caps ConnectionNameList at 25 entries.
List<String> twentySix = IntStream.rangeClosed(1, 26).mapToObj(i -> "c" + i).toList();
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.batchDeleteConnections(twentySix, REGION)).getErrorCode());
}
@Test
void testConnectionAcceptsAnExistingNameOrAWellFormedInlineDefinition() {
glueService.createConnection(jdbcConnection("probe"), null, REGION);
glueService.testConnection("probe", null, null);
glueService.testConnection(null, "JDBC", Map.of("JDBC_CONNECTION_URL", "jdbc:mysql://h:3306/d"));
assertEquals("EntityNotFoundException",
assertThrows(AwsException.class, () -> glueService.testConnection("absent", null, null)).getErrorCode());
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.testConnection(null, "JDBC", null)).getErrorCode());
assertEquals("InvalidInputException",
assertThrows(AwsException.class, () -> glueService.testConnection(null, null, Map.of())).getErrorCode());
}
@Test
void connectionTagsAreKeptUnderTheConnectionArnAndRemovedOnDelete() {
glueService.createConnection(jdbcConnection("tagged"), Map.of("env", "dev"), REGION);
String arn = "arn:aws:glue:" + REGION + ":" + ACCOUNT_ID + ":connection/tagged";
assertEquals("dev", glueService.getTags(arn, REGION).get("env"));
glueService.tagResource(arn, Map.of("team", "data"), REGION);
assertEquals("data", glueService.getTags(arn, REGION).get("team"));
glueService.untagResource(arn, List.of("env"), REGION);
assertNull(glueService.getTags(arn, REGION).get("env"));
glueService.deleteConnection("tagged", REGION);
assertEquals("EntityNotFoundException",
assertThrows(AwsException.class, () -> glueService.getTags(arn, REGION)).getErrorCode());
}
private static List<String> names(GlueService.Page<Table> page) {
return page.items().stream().map(Table::getName).toList();
}