Skip to content

Commit

Permalink
feat: 增加 pg ssl 的 mode 字段
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron3S committed Sep 13, 2024
1 parent e499de3 commit 793b536
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.sql.SQLException;
import java.util.Properties;

public class PostgresqlConnectionManager extends BaseConnectionManager {

private static final String jdbcUrlTemplate = "jdbc:postgresql://${host}:${port}/${db}?useUnicode=true&characterEncoding=UTF-8";
Expand Down Expand Up @@ -38,6 +39,7 @@ protected void setSSLProps(Properties props) {
var caCert = (String) this.getConnectInfo().getOptions().get("caCert");
var clientCert = (String) this.getConnectInfo().getOptions().get("clientCert");
var clientKey = (String) this.getConnectInfo().getOptions().get("clientKey");
var sslMode = (String) this.getConnectInfo().getOptions().get("pgSSLMode");

var sslManager = new SSLCertManager();
sslManager.setCaCert(caCert);
Expand All @@ -47,7 +49,7 @@ protected void setSSLProps(Properties props) {

try {
props.setProperty("ssl", "true");
props.setProperty("sslmode", "verify-full");
props.setProperty("sslmode", sslMode);
props.setProperty("sslrootcert", sslManager.getCaCertPath());
props.setProperty("sslcert", sslManager.getClientCertPath());
props.setProperty("sslkey", sslManager.getClientCertKeyPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private Datasource createDatasource(ServiceOuterClass.TokenResponse tokenResp) {
dbConnectInfo.getOptions().put("caCert", asset.getSpecific().getCaCert());
dbConnectInfo.getOptions().put("clientCert", asset.getSpecific().getClientCert());
dbConnectInfo.getOptions().put("clientKey", asset.getSpecific().getClientKey());
dbConnectInfo.getOptions().put("pgSSLMode", asset.getSpecific().getPgSslMode());
}
return DatasourceFactory.fromConnectInfo(dbConnectInfo);
}
Expand Down
Loading

0 comments on commit 793b536

Please sign in to comment.