Skip to content

Commit d53cfd4

Browse files
committed
Add multi proxy support
1 parent 6384cfb commit d53cfd4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/main/java/org/cloudfoundry/community/servicebroker/postgresql/service/PostgreSQLDatabase.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.annotation.PostConstruct;
1212
import javax.validation.constraints.NotNull;
1313
import java.math.BigInteger;
14+
import java.net.URI;
1415
import java.security.SecureRandom;
1516
import java.sql.*;
1617
import java.util.Collections;
@@ -216,19 +217,22 @@ public String bindRoleToDatabase(String serviceInstanceId, String bindingId) thr
216217
//executeUpdate("ALTER DEFAULT PRIVILEGES FOR ROLE \""+serviceInstanceId+"\" IN SCHEMA public GRANT ALL ON TABLES TO \"" + bindingId + "\"");
217218
//executeUpdate("ALTER DEFAULT PRIVILEGES FOR ROLE \""+serviceInstanceId+"\" IN SCHEMA public GRANT ALL ON SEQUENCES TO \"" + bindingId + "\"");
218219
//executeUpdate("ALTER DEFAULT PRIVILEGES FOR ROLE \""+serviceInstanceId+"\" IN SCHEMA public GRANT ALL ON FUNCTIONS TO \"" + bindingId + "\"");
219-
220+
String s_uri = jdbcTemplate.getDataSource().getConnection().getMetaData().getURL().replace("jdbc:postgresql://", "").split("/")[0];
220221
// Support multi-proxy
221-
String uri = jdbcTemplate.getDataSource().getConnection().getMetaData().getURL().replace("jdbc:postgresql://", "").split("/")[0];
222-
String dbURL = String.format("postgres://%s:%s@%s/%s",serviceInstanceId, findServiceInstance(serviceInstanceId).getCredentials(), uri , serviceInstanceId);
223-
/*
224-
String dbURL = String.format("postgres://%s:%s@%s:%d/%s",
225-
// hack for multibinding
226-
serviceInstanceId,
227-
findServiceInstance(serviceInstanceId).getCredentials(),
228-
//bindingId, passwd,
229-
uri.getHost(), uri.getPort() == -1 ? 5432 : uri.getPort(), serviceInstanceId);
230-
231-
*/
222+
String dbURL="";
223+
if (s_uri.contains(",")){
224+
dbURL = String.format("postgres://%s:%s@%s/%s",serviceInstanceId, findServiceInstance(serviceInstanceId).getCredentials(), s_uri , serviceInstanceId);
225+
}else{
226+
227+
URI uri = new URI(jdbcTemplate.getDataSource().getConnection().getMetaData().getURL().replace("jdbc:", ""));
228+
dbURL = String.format("postgres://%s:%s@%s:%d/%s",
229+
// hack for multibinding
230+
serviceInstanceId,
231+
findServiceInstance(serviceInstanceId).getCredentials(),
232+
//bindingId, passwd,
233+
uri.getHost(), uri.getPort() == -1 ? 5432 : uri.getPort(), serviceInstanceId);
234+
}
235+
232236
return dbURL;
233237
}
234238

0 commit comments

Comments
 (0)