summaryrefslogtreecommitdiffstats
path: root/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java
blob: 8269597db0fef4055d6e478d933582b3338f1b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.woorea.openstack.keystone.utils;

import java.util.List;

import com.woorea.openstack.keystone.model.Access.Service;

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");
	}

}