From 53e8262c5a3e6247f10455891f99b0e37cd38761 Mon Sep 17 00:00:00 2001 From: Liren Tu Date: Thu, 12 May 2022 23:32:04 -0700 Subject: [PATCH] Replace host with jdbc_url --- .../integrations/source/postgres/PostgresSource.java | 8 +++----- .../integrations/source/postgres/PostgresSourceTest.java | 8 ++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/airbyte-integrations/connectors/source-postgres/src/main/java/io/airbyte/integrations/source/postgres/PostgresSource.java b/airbyte-integrations/connectors/source-postgres/src/main/java/io/airbyte/integrations/source/postgres/PostgresSource.java index bea9557ec1ae..bba6515a244c 100644 --- a/airbyte-integrations/connectors/source-postgres/src/main/java/io/airbyte/integrations/source/postgres/PostgresSource.java +++ b/airbyte-integrations/connectors/source-postgres/src/main/java/io/airbyte/integrations/source/postgres/PostgresSource.java @@ -351,15 +351,13 @@ public Set getPrivilegesTableForCurrentUser(final JdbcDatabase @VisibleForTesting static String getUsername(final JsonNode databaseConfig) { - final String host = databaseConfig.get("host") == null - // host can be null in test - ? "" - : databaseConfig.get("host").asText(); + final String jdbcUrl = databaseConfig.get("jdbc_url").asText(); final String username = databaseConfig.get("username").asText(); // Azure Postgres server has this username pattern: @. // Inside Postgres, the true username is just . - if (username.contains("@") && host.endsWith("azure.com")) { + // The jdbc_url is constructed in the toDatabaseConfigStatic method. + if (username.contains("@") && jdbcUrl.contains("azure.com:")) { final String[] tokens = username.split("@"); final String postgresUsername = tokens[0]; LOGGER.info("Azure username \"{}\" is detected; use \"{}\" to check permission", username, postgresUsername); diff --git a/airbyte-integrations/connectors/source-postgres/src/test/java/io/airbyte/integrations/source/postgres/PostgresSourceTest.java b/airbyte-integrations/connectors/source-postgres/src/test/java/io/airbyte/integrations/source/postgres/PostgresSourceTest.java index 3ded33399b4c..c8cd44c8adba 100644 --- a/airbyte-integrations/connectors/source-postgres/src/test/java/io/airbyte/integrations/source/postgres/PostgresSourceTest.java +++ b/airbyte-integrations/connectors/source-postgres/src/test/java/io/airbyte/integrations/source/postgres/PostgresSourceTest.java @@ -365,11 +365,15 @@ void testGetUsername() { final String username = "airbyte-user"; // normal host - final JsonNode normalConfig = Jsons.jsonNode(Map.of("username", username, "host", "airbyte.aws.com")); + final JsonNode normalConfig = Jsons.jsonNode(Map.of( + "username", username, + "jdbc_url", "jdbc:postgresql://airbyte.database.com:5432:airbyte")); assertEquals(username, PostgresSource.getUsername(normalConfig)); // azure host - final JsonNode azureConfig = Jsons.jsonNode(Map.of("username", username + "@airbyte", "host", "airbyte.azure.com")); + final JsonNode azureConfig = Jsons.jsonNode(Map.of( + "username", username + "@airbyte", + "jdbc_url", "jdbc:postgresql://airbyte.azure.com:5432:airbyte")); assertEquals(username, PostgresSource.getUsername(azureConfig)); }