summaryrefslogtreecommitdiffstats
path: root/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java
diff options
context:
space:
mode:
authorBharat saraswal <bharat.saraswal@huawei.com>2017-09-22 19:58:54 +0530
committerBharat saraswal <bharat.saraswal@huawei.com>2017-09-22 19:58:54 +0530
commitd897c0fba26ce6eeba41dbfc93e2da93f6125bd8 (patch)
tree7fa131f16d1d7cf08798ac61079ab0e96769f93d /keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java
parenta34455305b0c42a66017aa0e3935f00020351001 (diff)
Resolved below sonar issues.
removed redundant code. changed nested if condition to switch case. added method for resuablity of string builder. rename variable to follow camelCase. removed tab char and changed them with spaces. Issue-ID:SO-98 Change-Id: If4cf02dede7903ed8b35e4e6879b8691d4f3c48d Signed-off-by: Bharat saraswal <bharat.saraswal@huawei.com>
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;
+ }
}