summaryrefslogtreecommitdiffstats
path: root/keystone-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'keystone-client/src')
-rw-r--r--keystone-client/src/main/java/com/woorea/openstack/keystone/Keystone.java104
-rw-r--r--keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneTokenProvider.java92
-rw-r--r--keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java52
-rw-r--r--keystone-client/src/main/java/com/woorea/openstack/keystone/v3/Keystone.java119
4 files changed, 188 insertions, 179 deletions
diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/Keystone.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/Keystone.java
index 38d42f0..c8d8e09 100644
--- a/keystone-client/src/main/java/com/woorea/openstack/keystone/Keystone.java
+++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/Keystone.java
@@ -1,5 +1,7 @@
package com.woorea.openstack.keystone;
+import com.woorea.openstack.base.client.OpenStackClient;
+import com.woorea.openstack.base.client.OpenStackClientConnector;
import com.woorea.openstack.keystone.api.EndpointsResource;
import com.woorea.openstack.keystone.api.RolesResource;
import com.woorea.openstack.keystone.api.ServicesResource;
@@ -7,59 +9,55 @@ import com.woorea.openstack.keystone.api.TenantsResource;
import com.woorea.openstack.keystone.api.TokensResource;
import com.woorea.openstack.keystone.api.UsersResource;
-import com.woorea.openstack.base.client.OpenStackClient;
-import com.woorea.openstack.base.client.OpenStackClientConnector;
-
public class Keystone extends OpenStackClient {
-
- private final TokensResource TOKENS;
-
- private final TenantsResource TENANTS;
-
- private final UsersResource USERS;
-
- private final RolesResource ROLES;
-
- private final ServicesResource SERVICES;
-
- private final EndpointsResource ENDPOINTS;
-
- public Keystone(String endpoint, OpenStackClientConnector connector) {
- super(endpoint, connector);
- TOKENS = new TokensResource(this);
- TENANTS = new TenantsResource(this);
- USERS = new UsersResource(this);
- ROLES = new RolesResource(this);
- SERVICES = new ServicesResource(this);
- ENDPOINTS = new EndpointsResource(this);
- }
-
- public Keystone(String endpoint) {
- this(endpoint, null);
- }
-
- public TokensResource tokens() {
- return TOKENS;
- }
-
- public TenantsResource tenants() {
- return TENANTS;
- }
-
- public UsersResource users() {
- return USERS;
- }
-
- public RolesResource roles() {
- return ROLES;
- }
-
- public ServicesResource services() {
- return SERVICES;
- }
-
- public EndpointsResource endpoints() {
- return ENDPOINTS;
- }
+ private final TokensResource tokens;
+
+ private final TenantsResource tenants;
+
+ private final UsersResource users;
+
+ private final RolesResource roles;
+
+ private final ServicesResource services;
+
+ private final EndpointsResource endpoints;
+
+ public Keystone(String endpoint, OpenStackClientConnector connector) {
+ super(endpoint, connector);
+ tokens = new TokensResource(this);
+ tenants = new TenantsResource(this);
+ users = new UsersResource(this);
+ roles = new RolesResource(this);
+ services = new ServicesResource(this);
+ endpoints = new EndpointsResource(this);
+ }
+
+ public Keystone(String endpoint) {
+ this(endpoint, null);
+ }
+
+ public TokensResource tokens() {
+ return tokens;
+ }
+
+ public TenantsResource tenants() {
+ return tenants;
+ }
+
+ public UsersResource users() {
+ return users;
+ }
+
+ public RolesResource roles() {
+ return roles;
+ }
+
+ public ServicesResource services() {
+ return services;
+ }
+
+ public EndpointsResource endpoints() {
+ return endpoints;
+ }
}
diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneTokenProvider.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneTokenProvider.java
index fb5127a..3396492 100644
--- a/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneTokenProvider.java
+++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneTokenProvider.java
@@ -1,56 +1,56 @@
package com.woorea.openstack.keystone.utils;
-import java.util.concurrent.ConcurrentHashMap;
-
import com.woorea.openstack.base.client.OpenStackTokenProvider;
import com.woorea.openstack.keystone.Keystone;
import com.woorea.openstack.keystone.model.Access;
import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
+import java.util.concurrent.ConcurrentHashMap;
public class KeystoneTokenProvider {
- protected Keystone keystone;
-
- protected String username;
-
- protected String password;
-
- ConcurrentHashMap<String, Access> hashTenantAccess;
-
- public KeystoneTokenProvider(String endpoint, String username, String password) {
- this.keystone = new Keystone(endpoint);
- this.username = username;
- this.password = password;
- this.hashTenantAccess = new ConcurrentHashMap<String, Access>();
- }
-
- public Access getAccessByTenant(String tenantName) {
- Access access = hashTenantAccess.get(tenantName);
- if (access == null) {
- access = keystone.tokens().authenticate(new UsernamePassword(username, password))
- .withTenantName(tenantName)
- .execute();
- hashTenantAccess.put(tenantName, access);
- }
- return access;
- }
-
- public void expireAccessByTenant(String tenantName) {
- hashTenantAccess.remove(tenantName);
- }
-
- public OpenStackTokenProvider getProviderByTenant(final String tenantName) {
- final KeystoneTokenProvider keystoneTokenProvider = this;
- return new OpenStackTokenProvider() {
- @Override
- public String getToken() {
- return keystoneTokenProvider.getAccessByTenant(tenantName)
- .getToken().getId();
- }
- @Override
- public void expireToken() {
- keystoneTokenProvider.expireAccessByTenant(tenantName);
- }
- };
- }
+ protected Keystone keystone;
+
+ protected String username;
+
+ protected String password;
+
+ protected ConcurrentHashMap<String, Access> hashTenantAccess;
+
+ public KeystoneTokenProvider(String endpoint, String username, String password) {
+ keystone = new Keystone(endpoint);
+ this.username = username;
+ this.password = password;
+ hashTenantAccess = new ConcurrentHashMap<>();
+ }
+
+ public Access getAccessByTenant(String tenantName) {
+ Access access = hashTenantAccess.get(tenantName);
+ if (access == null) {
+ access = keystone.tokens().authenticate(new UsernamePassword(username, password))
+ .withTenantName(tenantName)
+ .execute();
+ hashTenantAccess.put(tenantName, access);
+ }
+ return access;
+ }
+
+ public void expireAccessByTenant(String tenantName) {
+ hashTenantAccess.remove(tenantName);
+ }
+
+ public OpenStackTokenProvider getProviderByTenant(final String tenantName) {
+ final KeystoneTokenProvider keystoneTokenProvider = this;
+ return new OpenStackTokenProvider() {
+ @Override
+ public String getToken() {
+ return keystoneTokenProvider.getAccessByTenant(tenantName)
+ .getToken().getId();
+ }
+
+ @Override
+ public void expireToken() {
+ keystoneTokenProvider.expireAccessByTenant(tenantName);
+ }
+ };
+ }
}
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;
+ }
}
diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/v3/Keystone.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/v3/Keystone.java
index 6ff889c..841b620 100644
--- a/keystone-client/src/main/java/com/woorea/openstack/keystone/v3/Keystone.java
+++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/v3/Keystone.java
@@ -1,73 +1,72 @@
package com.woorea.openstack.keystone.v3;
+import com.woorea.openstack.base.client.OpenStackClient;
+import com.woorea.openstack.base.client.OpenStackClientConnector;
import com.woorea.openstack.keystone.v3.api.DomainsResource;
import com.woorea.openstack.keystone.v3.api.EndpointsResource;
+import com.woorea.openstack.keystone.v3.api.ProjectsResource;
import com.woorea.openstack.keystone.v3.api.RolesResource;
import com.woorea.openstack.keystone.v3.api.ServicesResource;
-import com.woorea.openstack.keystone.v3.api.ProjectsResource;
import com.woorea.openstack.keystone.v3.api.TokensResource;
import com.woorea.openstack.keystone.v3.api.UsersResource;
-import com.woorea.openstack.base.client.OpenStackClient;
-import com.woorea.openstack.base.client.OpenStackClientConnector;
public class Keystone extends OpenStackClient {
-
- private final TokensResource TOKENS;
-
- private final DomainsResource DOMAINS;
-
- private final ProjectsResource PROJECTS;
-
- private final UsersResource USERS;
-
- private final RolesResource ROLES;
-
- private final ServicesResource SERVICES;
-
- private final EndpointsResource ENDPOINTS;
-
- public Keystone(String endpoint, OpenStackClientConnector connector) {
- super(endpoint, connector);
- TOKENS = new TokensResource(this);
- DOMAINS = new DomainsResource(this);
- PROJECTS = new ProjectsResource(this);
- USERS = new UsersResource(this);
- ROLES = new RolesResource(this);
- SERVICES = new ServicesResource(this);
- ENDPOINTS = new EndpointsResource(this);
- }
-
- public Keystone(String endpoint) {
- this(endpoint, null);
- }
-
- public TokensResource tokens() {
- return TOKENS;
- }
-
- public DomainsResource domains() {
- return DOMAINS;
- }
-
- public ProjectsResource projects() {
- return PROJECTS;
- }
-
- public UsersResource users() {
- return USERS;
- }
-
- public RolesResource roles() {
- return ROLES;
- }
-
- public ServicesResource services() {
- return SERVICES;
- }
-
- public EndpointsResource endpoints() {
- return ENDPOINTS;
- }
+ private final TokensResource tokens;
+
+ private final DomainsResource domains;
+
+ private final ProjectsResource projects;
+
+ private final UsersResource users;
+
+ private final RolesResource roles;
+
+ private final ServicesResource services;
+
+ private final EndpointsResource endpoints;
+
+ public Keystone(String endpoint, OpenStackClientConnector connector) {
+ super(endpoint, connector);
+ tokens = new TokensResource(this);
+ domains = new DomainsResource(this);
+ projects = new ProjectsResource(this);
+ users = new UsersResource(this);
+ roles = new RolesResource(this);
+ services = new ServicesResource(this);
+ endpoints = new EndpointsResource(this);
+ }
+
+ public Keystone(String endpoint) {
+ this(endpoint, null);
+ }
+
+ public TokensResource tokens() {
+ return tokens;
+ }
+
+ public DomainsResource domains() {
+ return domains;
+ }
+
+ public ProjectsResource projects() {
+ return projects;
+ }
+
+ public UsersResource users() {
+ return users;
+ }
+
+ public RolesResource roles() {
+ return roles;
+ }
+
+ public ServicesResource services() {
+ return services;
+ }
+
+ public EndpointsResource endpoints() {
+ return endpoints;
+ }
}