diff options
Diffstat (limited to 'keystone-client/src/main')
3 files changed, 331 insertions, 328 deletions
diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java index a073241..c521a61 100644 --- a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java +++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TenantsResource.java @@ -8,205 +8,214 @@ import com.woorea.openstack.base.client.Entity; import com.woorea.openstack.base.client.HttpMethod; import com.woorea.openstack.base.client.OpenStackClient; import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.keystone.model.Metadata; import com.woorea.openstack.keystone.model.Roles; import com.woorea.openstack.keystone.model.Tenant; import com.woorea.openstack.keystone.model.Tenants; import com.woorea.openstack.keystone.model.Users; -import com.woorea.openstack.keystone.model.Metadata; public class TenantsResource { - - private OpenStackClient client; - - public TenantsResource(OpenStackClient client) { - this.client = client; - } - - public List list() { - return new List(); - } - - public Create create(Tenant tenant) { - return new Create(tenant); - } - - public Show show(String id) { - return new Show(id); - } - - public Update update(String id, Tenant tenant) { - return new Update(id, tenant); - } - - public Delete delete(String id) { - return new Delete(id); - } - - public ListUsers listUsers(String tenantId) { - return new ListUsers(tenantId); - } - - public AddUser addUser(String tenantId, String userId, String roleId) { - return new AddUser(tenantId, userId, roleId); - } - - public RemoveUser removeUser(String tenantId, String userId, String roleId) { - return new RemoveUser(tenantId, userId, roleId); - } - - public ListUserRoles listUserRoles(String tenantId, String userId) { - return new ListUserRoles(tenantId, userId); - } - - public ShowMetadata showMetadata(String id) { - return new ShowMetadata(id); - } - - public CreateOrUpdateMetadata createOrUpdateMetadata(String id,Metadata metadata) { - return new CreateOrUpdateMetadata(id,metadata); - } - - public ReplaceMetadata replaceMetadata(String id,Metadata metadata) { - return new ReplaceMetadata(id,metadata); - } - - public ShowMetadataItem showMetadataItem(String id,String key) { - return new ShowMetadataItem(id,key); - } - - public CreateOrUpdateMetadataItem createOrUpdateMetadataItem(String id,String key,Metadata metadata) { - return new CreateOrUpdateMetadataItem(id,key,metadata); - } - - public DeleteMetadataItem deleteMetadataItem(String id, String key) { - return new DeleteMetadataItem(id,key); - } - - public class List extends OpenStackRequest<Tenants> { - - public List() { - super(client, HttpMethod.GET, "/tenants", null, Tenants.class); - } - - } - - public class Create extends OpenStackRequest<Tenant> { - - private Tenant tenant; - - public Create(Tenant tenant) { - super(client, HttpMethod.POST, "/tenants", Entity.json(tenant), Tenant.class); - this.tenant = tenant; - } - - } - - public class Show extends OpenStackRequest<Tenant> { - - public Show(String id) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(id).toString(), null, Tenant.class); - } - - } - - public class Update extends OpenStackRequest<Tenant> { - - private Tenant tenant; - - public Update(String id, Tenant tenant) { - super(client, HttpMethod.PUT, new StringBuilder("/tenants/").append(id).toString(), Entity.json(tenant), Tenant.class); - this.tenant = tenant; - } - - } - - public class Delete extends OpenStackRequest<Void> { - - public Delete(String id) { - super(client, HttpMethod.DELETE, new StringBuilder("/tenants/").append(id).toString(), null, Void.class); - } - - } - - public class ListUsers extends OpenStackRequest<Users> { - - public ListUsers(String tenantId) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/users").toString(), null, Users.class); - } - - } - - public class AddUser extends OpenStackRequest<Void> { - - public AddUser(String tenantId, String userId, String roleId) { - super(client, HttpMethod.PUT, new StringBuilder("/tenants/").append(tenantId).append("/users/").append(userId).append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); - } - - } - - public class RemoveUser extends OpenStackRequest<Void> { - - public RemoveUser(String tenantId, String userId, String roleId) { - super(client, HttpMethod.DELETE, new StringBuilder("/tenants/").append(tenantId).append("/users/").append(userId).append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); - } - - } - - public class ListUserRoles extends OpenStackRequest<Roles> { - - public ListUserRoles(String tenantId, String userId) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/users/").append(userId).append("/roles").toString(), null, Roles.class); - } - - } - - /** - * The following APIs support Tenant-level metadata. This is a feature supported - * by the DCP/LCP (i.e. AIC cloud), but not native Openstack. The full API as - * documented by AIC is implemented below. - */ - public class ShowMetadata extends OpenStackRequest<Metadata> { - - public ShowMetadata(String tenantId) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/metadata"), null, Metadata.class); - } - - } - - public class CreateOrUpdateMetadata extends OpenStackRequest<Metadata> { - - public CreateOrUpdateMetadata(String tenantId,Metadata metadata) { - super(client, HttpMethod.POST, new StringBuilder("/tenants/").append(tenantId).append("/metadata"), Entity.json(metadata), Metadata.class); - } - - } - public class ReplaceMetadata extends OpenStackRequest<Metadata> { - - public ReplaceMetadata(String tenantId,Metadata metadata) { - super(client, HttpMethod.PUT, new StringBuilder("/tenants/").append(tenantId).append("/metadata"), Entity.json(metadata), Metadata.class); - } - - } - - public class ShowMetadataItem extends OpenStackRequest<Metadata> { - - public ShowMetadataItem(String tenantId, String key) { - super(client, HttpMethod.GET, new StringBuilder("/tenants/").append(tenantId).append("/metadata").append(key), null, Metadata.class); - } - - } - public class CreateOrUpdateMetadataItem extends OpenStackRequest<Metadata> { - - public CreateOrUpdateMetadataItem(String tenantId,String key,Metadata metadata) { - super(client, HttpMethod.POST, new StringBuilder("/tenants/").append(tenantId).append("/metadata").append(key), Entity.json(metadata), Metadata.class); - } - - } - public class DeleteMetadataItem extends OpenStackRequest<Void> { - - public DeleteMetadataItem(String tenantId,String key) { - super(client, HttpMethod.DELETE, new StringBuilder("/tenants/").append(tenantId).append("/metadata/").append(key), null, Void.class); - } - - } - } + + private static final String TENANTS = "/tenants/"; + private static final String USERS = "/users/"; + private static final String METADATA = "/metadata"; + private final OpenStackClient client; + + public TenantsResource(OpenStackClient client) { + this.client = client; + } + + public List list() { + return new List(); + } + + public Create create(Tenant tenant) { + return new Create(tenant); + } + + public Show show(String id) { + return new Show(id); + } + + public Update update(String id, Tenant tenant) { + return new Update(id, tenant); + } + + public Delete delete(String id) { + return new Delete(id); + } + + public ListUsers listUsers(String tenantId) { + return new ListUsers(tenantId); + } + + public AddUser addUser(String tenantId, String userId, String roleId) { + return new AddUser(tenantId, userId, roleId); + } + + public RemoveUser removeUser(String tenantId, String userId, String roleId) { + return new RemoveUser(tenantId, userId, roleId); + } + + public ListUserRoles listUserRoles(String tenantId, String userId) { + return new ListUserRoles(tenantId, userId); + } + + public ShowMetadata showMetadata(String id) { + return new ShowMetadata(id); + } + + public CreateOrUpdateMetadata createOrUpdateMetadata(String id, Metadata metadata) { + return new CreateOrUpdateMetadata(id, metadata); + } + + public ReplaceMetadata replaceMetadata(String id, Metadata metadata) { + return new ReplaceMetadata(id, metadata); + } + + public ShowMetadataItem showMetadataItem(String id, String key) { + return new ShowMetadataItem(id, key); + } + + public CreateOrUpdateMetadataItem createOrUpdateMetadataItem(String id, String key, Metadata metadata) { + return new CreateOrUpdateMetadataItem(id, key, metadata); + } + + public DeleteMetadataItem deleteMetadataItem(String id, String key) { + return new DeleteMetadataItem(id, key); + } + + public class List extends OpenStackRequest<Tenants> { + + public List() { + super(client, HttpMethod.GET, "/tenants", null, Tenants.class); + } + } + + public class Create extends OpenStackRequest<Tenant> { + + private Tenant tenant; + + public Create(Tenant tenant) { + super(client, HttpMethod.POST, "/tenants", Entity.json(tenant), Tenant.class); + this.tenant = tenant; + } + } + + public class Show extends OpenStackRequest<Tenant> { + + public Show(String id) { + super(client, HttpMethod.GET, getTenantsString(id).toString(), null, Tenant.class); + } + } + + public class Update extends OpenStackRequest<Tenant> { + + private Tenant tenant; + + public Update(String id, Tenant tenant) { + super(client, HttpMethod.PUT, getTenantsString(id).toString(), Entity.json(tenant), + Tenant.class); + this.tenant = tenant; + } + } + + public class Delete extends OpenStackRequest<Void> { + + public Delete(String id) { + super(client, HttpMethod.DELETE, getTenantsString(id).toString(), null, Void.class); + } + } + + public class ListUsers extends OpenStackRequest<Users> { + + public ListUsers(String tenantId) { + super(client, HttpMethod.GET,getTenantsString(tenantId).append("/users").toString(), + null, Users.class); + } + } + + public class AddUser extends OpenStackRequest<Void> { + + public AddUser(String tenantId, String userId, String roleId) { + super(client, HttpMethod.PUT, + getTenantsString(tenantId).append(USERS).append(userId) + .append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); + } + } + + public class RemoveUser extends OpenStackRequest<Void> { + + public RemoveUser(String tenantId, String userId, String roleId) { + super(client, HttpMethod.DELETE, + getTenantsString(tenantId).append(USERS).append(userId) + .append("/roles/OS-KSADM/").append(roleId).toString(), null, Void.class); + } + } + + public class ListUserRoles extends OpenStackRequest<Roles> { + + public ListUserRoles(String tenantId, String userId) { + super(client, HttpMethod.GET, + getTenantsString(tenantId).append(USERS).append(userId).append("/roles") + .toString(), null, Roles.class); + } + } + + /** + * The following APIs support Tenant-level metadata. This is a feature supported + * by the DCP/LCP (i.e. AIC cloud), but not native Openstack. The full API as + * documented by AIC is implemented below. + */ + public class ShowMetadata extends OpenStackRequest<Metadata> { + + public ShowMetadata(String tenantId) { + super(client, HttpMethod.GET, getTenantsString(tenantId).append(METADATA), null, Metadata.class); + } + } + + public class CreateOrUpdateMetadata extends OpenStackRequest<Metadata> { + + public CreateOrUpdateMetadata(String tenantId, Metadata metadata) { + super(client, HttpMethod.POST, getTenantsString(tenantId).append(METADATA), Entity.json(metadata), + Metadata.class); + } + } + + public class ReplaceMetadata extends OpenStackRequest<Metadata> { + + public ReplaceMetadata(String tenantId, Metadata metadata) { + super(client, HttpMethod.PUT, getTenantsString(tenantId).append(METADATA), Entity.json(metadata), + Metadata.class); + } + } + + public class ShowMetadataItem extends OpenStackRequest<Metadata> { + + public ShowMetadataItem(String tenantId, String key) { + super(client, HttpMethod.GET, + getTenantsString(tenantId).append(METADATA).append(key), null, Metadata.class); + } + } + + public class CreateOrUpdateMetadataItem extends OpenStackRequest<Metadata> { + + public CreateOrUpdateMetadataItem(String tenantId, String key, Metadata metadata) { + super(client, HttpMethod.POST, + getTenantsString(tenantId).append(METADATA).append(key), Entity.json(metadata), + Metadata.class); + } + } + + public class DeleteMetadataItem extends OpenStackRequest<Void> { + + public DeleteMetadataItem(String tenantId, String key) { + super(client, HttpMethod.DELETE, + getTenantsString(tenantId).append("/metadata/").append(key), null, Void.class); + } + } + + private StringBuilder getTenantsString(String tenantId) { + return new StringBuilder(TENANTS).append(tenantId); + } +} diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java index 06da8ca..d5bfe22 100644 --- a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java +++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/TokensResource.java @@ -15,63 +15,57 @@ import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; import com.woorea.openstack.keystone.model.authentication.UsernamePassword; public class TokensResource { - - private final OpenStackClient CLIENT; - - public TokensResource(OpenStackClient client) { - CLIENT = client; - } - - public Authenticate.Builder authenticate() { - return new Authenticate().new Builder(); - } - - public Authenticate authenticate(Authentication authentication) { - return new Authenticate(authentication); - } - - public class Authenticate extends OpenStackRequest<Access> { - - private Authentication authentication; - - public Authenticate() { - - } - - public Authenticate(Authentication authentication) { - super(CLIENT, HttpMethod.POST, "/tokens", Entity.json(authentication), Access.class); - this.authentication = authentication; - } - - public Authenticate withTenantId(String tenantId) { - authentication.setTenantId(tenantId); - return this; - } - - public Authenticate withTenantName(String tenantName) { - authentication.setTenantName(tenantName); - return this; - } - - public class Builder { - - public Authenticate withUsernamePassword(String username, String password) { - Authentication authentication = new UsernamePassword(username, password); - return new Authenticate(authentication); - } - - public Authenticate withToken(String token) { - Authentication authentication = new TokenAuthentication(token); - return new Authenticate(authentication); - } - - public Authenticate withAccessKey(String accessKey, String secretKey) { - Authentication authentication = new AccessKey(accessKey, secretKey); - return new Authenticate(authentication); - } - - } - - } - + + private final OpenStackClient client; + + public TokensResource(OpenStackClient client) { + this.client = client; + } + + public Authenticate.Builder authenticate() { + return new Authenticate().new Builder(); + } + + public Authenticate authenticate(Authentication authentication) { + return new Authenticate(authentication); + } + + public class Authenticate extends OpenStackRequest<Access> { + + private Authentication authentication; + + public Authenticate() { + + } + + public Authenticate(Authentication authentication) { + super(client, HttpMethod.POST, "/tokens", Entity.json(authentication), Access.class); + this.authentication = authentication; + } + + public Authenticate withTenantId(String tenantId) { + authentication.setTenantId(tenantId); + return this; + } + + public Authenticate withTenantName(String tenantName) { + authentication.setTenantName(tenantName); + return this; + } + + public class Builder { + + public Authenticate withUsernamePassword(String username, String password) { + return new Authenticate(new UsernamePassword(username, password)); + } + + public Authenticate withToken(String token) { + return new Authenticate(new TokenAuthentication(token)); + } + + public Authenticate withAccessKey(String accessKey, String secretKey) { + return new Authenticate(new AccessKey(accessKey, secretKey)); + } + } + } } diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java index dbb897c..94a5b68 100644 --- a/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java +++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/api/UsersResource.java @@ -9,77 +9,77 @@ import com.woorea.openstack.keystone.model.User; import com.woorea.openstack.keystone.model.Users; public class UsersResource { - - private OpenStackClient client; - - public UsersResource(OpenStackClient client) { - this.client = client; - } - - public List list() { - return new List(); - } - - public Create create(User user) { - return new Create(user); - } - - public Show show(String id) { - return new Show(id); - } - - public Update update(String id, User user) { - return new Update(id, user); - } - - public Delete delete(String id) { - return new Delete(id); - } - - public class List extends OpenStackRequest<Users> { - - public List() { - super(client, HttpMethod.GET, "/users", null, Users.class); - } - - } - - public class Create extends OpenStackRequest<User> { - - private User user; - - public Create(User user) { - super(client, HttpMethod.POST, "/users", Entity.json(user), User.class); - this.user = user; - } - - } - - public class Show extends OpenStackRequest<User> { - - public Show(String id) { - super(client, HttpMethod.GET, new StringBuilder("/users/").append(id).toString(), null, User.class); - } - - } - - public class Update extends OpenStackRequest<User> { - - private User user; - - public Update(String id, User user) { - super(client, HttpMethod.PUT, new StringBuilder("/users/").append(id).toString(), Entity.json(user), User.class); - this.user = user; - } - - } - - public class Delete extends OpenStackRequest<Void> { - - public Delete(String id) { - super(client, HttpMethod.DELETE, new StringBuilder("/users/").append(id).toString(), null, Void.class); - } - - } - + + private static final String USERS = "/users/"; + private OpenStackClient client; + + public UsersResource(OpenStackClient client) { + this.client = client; + } + + public List list() { + return new List(); + } + + public Create create(User user) { + return new Create(user); + } + + public Show show(String id) { + return new Show(id); + } + + public Update update(String id, User user) { + return new Update(id, user); + } + + public Delete delete(String id) { + return new Delete(id); + } + + public class List extends OpenStackRequest<Users> { + + public List() { + super(client, HttpMethod.GET, "/users", null, Users.class); + } + } + + public class Create extends OpenStackRequest<User> { + + private User user; + + public Create(User user) { + super(client, HttpMethod.POST, "/users", Entity.json(user), User.class); + this.user = user; + } + } + + public class Show extends OpenStackRequest<User> { + + public Show(String id) { + super(client, HttpMethod.GET, getUserString(id), null, User.class); + } + } + + public class Update extends OpenStackRequest<User> { + + private User user; + + public Update(String id, User user) { + super(client, HttpMethod.PUT, getUserString(id), Entity.json(user), + User.class); + this.user = user; + } + } + + public class Delete extends OpenStackRequest<Void> { + + public Delete(String id) { + super(client, HttpMethod.DELETE, getUserString(id), null, Void.class); + } + } + + private String getUserString(String id) { + return USERS + id; + } } |