Skip to content

Commit

Permalink
Add ssl options (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkass committed Mar 20, 2019
1 parent 050a555 commit 6d696ba
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/main/java/com/disneystreaming/pg2k4j/CommandLineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,60 @@ public static void main(final String[] args) {
)
private String slotName;

@CommandLine.Option(
names = {"--pgsslmode"},
description = "Refer to "
+ "https://jdbc.postgresql.org/development/privateapi/org/"
+ "postgresql/PGProperty.html#SSL_MODE "
+ "for description and valid values.",
required = false,
defaultValue = PostgresConfiguration.DEFAULT_SSL_MODE
)
private String sslMode;

@CommandLine.Option(
names = {"--pgpathtorootcert"},
description = "Refer to "
+ "https://jdbc.postgresql.org/development/privateapi/org/"
+ "postgresql/PGProperty.html#SSL_ROOT_CERT "
+ "for description. "
+ "Example: /path/to/rds-combined-ca-bundle.pem",
required = false
)
private String pathToRootCert;

@CommandLine.Option(
names = {"--pgpathtosslcert"},
description = "Refer to "
+ "https://jdbc.postgresql.org/development/privateapi/org/"
+ "postgresql/PGProperty.html#SSL_CERT "
+ "for description. "
+ "Example: /path/to/sslcert.pem",
required = false
)
private String pathToSslCert;

@CommandLine.Option(
names = {"--pgpathtosslkey"},
description = "Refer to "
+ "https://jdbc.postgresql.org/development/privateapi/org/"
+ "postgresql/PGProperty.html#SSL_KEY "
+ "for description. "
+ "Example: /path/to/sslkey.pem",
required = false
)
private String pathToSslKey;

@CommandLine.Option(
names = {"--pgsslpassword"},
description = "Refer to "
+ "https://jdbc.postgresql.org/development/privateapi/org/"
+ "postgresql/PGProperty.html#SSL_PASSWORD "
+ "for description. ",
required = false
)
private String sslPassword;

@CommandLine.Option(names = {"-h", "--help"}, usageHelp = true,
description = "Display this message")
private boolean usageHelpRequested;
Expand Down Expand Up @@ -214,4 +268,30 @@ public String getPassword() {
public String getPort() {
return pgPort;
}

@Override
public String getSslMode() {
return sslMode;
}

@Override
public String getPathToRootCert() {
return pathToRootCert;
}

@Override
public String getSslPassword() {
return sslPassword;
}

@Override
public String getPathToSslKey() {
return pathToSslKey;
}

@Override
public String getPathToSslCert() {
return pathToSslCert;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface PostgresConfiguration {

String DEFAULT_PORT = "5432";
String MIN_SERVER_VERSION = "10.3";
String DEFAULT_SSL_MODE = "disable";

default String getPort() {
return DEFAULT_PORT;
Expand All @@ -54,6 +55,26 @@ default String getUrl() {
getPort(), getDatabase());
}

default String getPathToRootCert() {
return null;
}

default String getSslPassword() {
return null;
}

default String getPathToSslKey() {
return null;
}

default String getPathToSslCert() {
return null;
}

default String getSslMode() {
return DEFAULT_SSL_MODE;
}

default Properties getReplicationProperties() {
Properties properties = getQueryConnectionProperties();
PGProperty.PREFER_QUERY_MODE.set(properties, getQueryMode());
Expand All @@ -67,6 +88,11 @@ default Properties getQueryConnectionProperties() {
PGProperty.PASSWORD.set(properties, getPassword());
PGProperty.ASSUME_MIN_SERVER_VERSION.set(properties,
getMinServerVersion());
PGProperty.SSL_MODE.set(properties, getSslMode());
PGProperty.SSL_ROOT_CERT.set(properties, getPathToRootCert());
PGProperty.SSL_CERT.set(properties, getPathToSslCert());
PGProperty.SSL_PASSWORD.set(properties, getSslPassword());
PGProperty.SSL_KEY.set(properties, getPathToSslKey());
return properties;
}

Expand Down

0 comments on commit 6d696ba

Please sign in to comment.