summaryrefslogtreecommitdiffstats
path: root/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java')
-rw-r--r--keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java52
1 files changed, 32 insertions, 20 deletions
diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java
index 8269597..b41c092 100644
--- a/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java
+++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java
@@ -1,28 +1,40 @@
package com.woorea.openstack.keystone.utils;
-import java.util.List;
-
import com.woorea.openstack.keystone.model.Access.Service;
+import java.util.List;
public class KeystoneUtils {
- public static String findEndpointURL(List<Service> serviceCatalog, String type, String region, String facing) {
- for(Service service : serviceCatalog) {
- if(type.equals(service.getType())) {
- for(Service.Endpoint endpoint : service.getEndpoints()) {
- if(region == null || region.equals(endpoint.getRegion())) {
- if(endpoint.getPublicURL() != null && facing.equals("public")) {
- return endpoint.getPublicURL();
- } else if(endpoint.getInternalURL() != null && facing.equals("internal")) {
- return endpoint.getInternalURL();
- } else if(endpoint.getAdminURL() != null && facing.equals("admin")) {
- return endpoint.getAdminURL();
- }
- }
- }
- }
- }
- throw new RuntimeException("endpoint url not found");
- }
+ private KeystoneUtils() {
+ }
+
+ public static String findEndpointURL(List<Service> serviceCatalog, String type, String region, String facing) {
+ for (Service service : serviceCatalog) {
+ if (type.equals(service.getType())) {
+ for (Service.Endpoint endpoint : service.getEndpoints()) {
+ String url = handleServiceEndPoints(endpoint, region, facing);
+ if (url != null) {
+ return url;
+ }
+ }
+ }
+ }
+ throw new RuntimeException("endpoint url not found");
+ }
+ private static String handleServiceEndPoints(Service.Endpoint endpoint, String region, String facing) {
+ if (region == null || region.equals(endpoint.getRegion())) {
+ switch (facing) {
+ case "public":
+ return endpoint.getPublicURL();
+ case "internal":
+ return endpoint.getInternalURL();
+ case "admin":
+ return endpoint.getAdminURL();
+ default:
+ return null;
+ }
+ }
+ return null;
+ }
}