Added support for "host" in addition to "hostname" in credentials for RedisServiceInfoCreator.

This commit is contained in:
Scott Frederick
2014-05-28 13:02:58 -05:00
parent 1a535476bb
commit d0ab849909
6 changed files with 26 additions and 19 deletions

View File

@@ -20,12 +20,9 @@ public class AmqpServiceInfoCreator extends CloudFoundryServiceInfoCreator<AmqpS
Map<String,Object> credentials = (Map<String, Object>) serviceData.get("credentials");
String id = (String) serviceData.get("name");
String uri = (String) credentials.get("uri");
if (uri == null || uri.length() == 0) {
uri = (String) credentials.get("url");
}
String uri = getStringFromCredentials(credentials, "uri", "url");
return new AmqpServiceInfo(id, uri);
}

View File

@@ -57,6 +57,15 @@ public abstract class CloudFoundryServiceInfoCreator<SI extends ServiceInfo> imp
return false;
}
protected String getStringFromCredentials(Map<String, Object> credentials, String... keys) {
for (String key : keys) {
if (credentials.containsKey(key)) {
return (String) credentials.get(key);
}
}
return null;
}
public String getUriScheme() {
return uriScheme;
}

View File

@@ -22,7 +22,7 @@ public class MongoServiceInfoCreator extends CloudFoundryServiceInfoCreator<Mong
String id = (String) serviceData.get("name");
String uri = (String) ((credentials.get("uri") == null) ? credentials.get("url") : credentials.get("uri"));
String uri = getStringFromCredentials(credentials, "uri", "url");
return new MongoServiceInfo(id, uri);
}

View File

@@ -21,12 +21,10 @@ public class RedisServiceInfoCreator extends CloudFoundryServiceInfoCreator<Redi
String id = (String) serviceData.get("name");
String uri = (String) credentials.get("uri");
String uri = getStringFromCredentials(credentials, "uri", "url");
if (uri == null) {
uri = (String) credentials.get("url");
}
if (uri == null) {
String host = (String) credentials.get("hostname");
String host = getStringFromCredentials(credentials, "hostname", "host");
Integer port = Integer.parseInt(credentials.get("port").toString());
String password = (String) credentials.get("password");

View File

@@ -24,20 +24,20 @@ public abstract class RelationalServiceInfoCreator<SI extends RelationalServiceI
String id = (String) serviceData.get("name");
String uri;
if (credentials.containsKey("uri")) {
uri = credentials.get("uri").toString();
} else {
String host = (String) credentials.get("host");
String uri = getStringFromCredentials(credentials, "uri", "url");
if (uri == null) {
String host = getStringFromCredentials(credentials, "hostname", "host");
int port = Integer.parseInt(credentials.get("port").toString()); // allows the port attribute to be quoted or plain
String username = (String) credentials.get("user");
String username = getStringFromCredentials(credentials, "user", "username");
String password = (String) credentials.get("password");
String database = (String) credentials.get("name");
uri = new UriInfo(getUriScheme(), host, port, username, password, database).toString();
}
return createServiceInfo(id, uri);
}
}

View File

@@ -84,7 +84,10 @@ public class UriInfo {
return new URI(scheme, userInfo, host, port, cleanedPath, query, null);
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
String details = String.format("Error creating URI with components: " +
"scheme=%s, userInfo=%s, host=%s, port=%d, path=%s, query=%s",
scheme, userInfo, host, port, cleanedPath, query);
throw new IllegalArgumentException(details, e);
}
}