Skip to content

Commit

Permalink
Replace host with jdbc_url
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliren committed May 13, 2022
1 parent 90d9c07 commit 53e8262
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,13 @@ public Set<JdbcPrivilegeDto> 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: <username>@<host>.
// Inside Postgres, the true username is just <username>.
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

2 comments on commit 53e8262

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube Report

SonarQube report for Airbyte Connectors Source Postgres Strict Encrypt(#12834)

Measures

Name Value Name Value Name Value
Duplicated Blocks 0 Code Smells 0 Reliability Rating A
Lines to Cover 11 Coverage 54.5 Lines of Code 27
Duplicated Lines (%) 0.0 Bugs 0 Quality Gate Status OK
Vulnerabilities 0 Security Rating A Blocker Issues 0
Critical Issues 0 Major Issues 0 Minor Issues 0

Coverage (54.5%)

File Coverage File Coverage
src/main/java/io/airbyte/integrations/source/postgres/PostgresSourceStrictEncrypt.java 54.5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube Report

SonarQube report for Airbyte Connectors Source Postgres(#12834)

Measures

Name Value Name Value Name Value
Quality Gate Status OK Lines to Cover 277 Duplicated Lines (%) 0.0
Lines of Code 546 Vulnerabilities 0 Coverage 80.2
Bugs 0 Code Smells 13 Reliability Rating A
Security Rating A Duplicated Blocks 0 Blocker Issues 2
Critical Issues 6 Major Issues 4 Minor Issues 0

Detected Issues

Rule File Description Message
java:S1192 (CRITICAL) postgres/PostgresSource.java:102 String literals should not be duplicated Define a constant instead of duplicating this literal "username" 3 times.
java:S2479 (CRITICAL) postgres/PostgresSource.java:280 Whitespace and control characters in literals should be explicit Remove the non-escaped \u0009 character from this literal.
java:S1192 (CRITICAL) postgres/PostgresSource.java:88 String literals should not be duplicated Define a constant instead of duplicating this literal "schemas" 3 times.
java:S1135 (INFO) postgres/PostgresSource.java:71 Track uses of "TODO" tags Complete the task associated to this TODO comment.
java:S1192 (CRITICAL) postgres/PostgresCdcProperties.java:14 String literals should not be duplicated Define a constant instead of duplicating this literal "replication_method" 3 times.
java:S1192 (CRITICAL) postgres/PostgresSource.java:165 String literals should not be duplicated Define a constant instead of duplicating this literal "replication_method" 6 times.
java:S1118 (MAJOR) postgres/PostgresUtils.java:9 Utility classes should not have public constructors Add a private constructor to hide the implicit public one.
java:S2187 (BLOCKER) postgres/CdcPostgresSourcePgoutputTest.java:7 TestCases should contain tests Add some tests to this class.
java:S2187 (BLOCKER) postgres/CdcPostgresSourceWal2jsonTest.java:7 TestCases should contain tests Add some tests to this class.
java:S1118 (MAJOR) postgres/PostgresCdcProperties.java:10 Utility classes should not have public constructors Add a private constructor to hide the implicit public one.
java:S112 (MAJOR) postgres/PostgresCdcTargetPosition.java:48 Generic exceptions should never be thrown Define and throw a dedicated exception instead of using a generic one.
java:S112 (MAJOR) postgres/PostgresSource.java:213 Generic exceptions should never be thrown Define and throw a dedicated exception instead of using a generic one.
java:S1192 (CRITICAL) postgres/PostgresSource.java:105 String literals should not be duplicated Define a constant instead of duplicating this literal "password" 3 times.

Coverage (80.2%)

File Coverage File Coverage
src/main/java/io/airbyte/integrations/source/postgres/PostgresCdcConnectorMetadataInjector.java 100.0 src/main/java/io/airbyte/integrations/source/postgres/PostgresCdcProperties.java 90.9
src/main/java/io/airbyte/integrations/source/postgres/PostgresCdcSavedInfoFetcher.java 83.3 src/main/java/io/airbyte/integrations/source/postgres/PostgresCdcStateHandler.java 100.0
src/main/java/io/airbyte/integrations/source/postgres/PostgresCdcTargetPosition.java 81.3 src/main/java/io/airbyte/integrations/source/postgres/PostgresSource.java 90.1
src/main/java/io/airbyte/integrations/source/postgres/PostgresSourceOperations.java 62.8 src/main/java/io/airbyte/integrations/source/postgres/PostgresUtils.java 50.0

Please sign in to comment.