mirror of https://github.com/apache/jclouds.git
Implemented createUser global admin API and live test
This commit is contained in:
parent
f25289bf0f
commit
8591bdb111
|
@ -19,10 +19,13 @@
|
|||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.CreateUserOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
|
@ -43,6 +46,17 @@ import javax.ws.rs.core.MediaType;
|
|||
@QueryParams(keys = "response", values = "json")
|
||||
public interface GlobalUserAsyncClient extends DomainUserAsyncClient {
|
||||
|
||||
/**
|
||||
* @see GlobalUserClient#createUser
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "createUser")
|
||||
@SelectJson("user")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<User>createUser(@QueryParam("username") String userName, @QueryParam("account") String accountName,
|
||||
@QueryParam("email") String email, @QueryParam("password") String hashedPassword,
|
||||
@QueryParam("firstname") String firstName, @QueryParam("lastname") String lastName, CreateUserOptions... options);
|
||||
|
||||
/**
|
||||
* @see GlobalUserClient#deleteUser
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.options.CreateUserOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +37,15 @@ import org.jclouds.concurrent.Timeout;
|
|||
public interface GlobalUserClient extends DomainUserClient {
|
||||
|
||||
|
||||
/**
|
||||
* Create an user for an account that already exists
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
User createUser(String userName, String accountName, String email, String hashedPassword,
|
||||
String firstName, String lastName, CreateUserOptions... options);
|
||||
|
||||
|
||||
/**
|
||||
* Delete an user with the specified ID
|
||||
*
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.cloudstack.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Optional fields for user creation
|
||||
*
|
||||
* @author Andrei Savu
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/createUser.html"
|
||||
* />
|
||||
*/
|
||||
public class CreateUserOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final CreateUserOptions NONE = new CreateUserOptions();
|
||||
|
||||
/**
|
||||
* @param domainId The domain for the resource
|
||||
*/
|
||||
public CreateUserOptions domainId(long domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timezone Specifies a timezone for this command. For more information
|
||||
* on the timezone parameter, see Time Zone Format.
|
||||
*/
|
||||
public CreateUserOptions timezone(String timezone) {
|
||||
this.queryParameters.replaceValues("timezone", ImmutableSet.of(timezone));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see CreateUserOptions#domainId
|
||||
*/
|
||||
public static CreateUserOptions domainId(long domainId) {
|
||||
CreateUserOptions options = new CreateUserOptions();
|
||||
return options.domainId(domainId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateUserOptions#timezone
|
||||
*/
|
||||
public static CreateUserOptions timezone(String timezone) {
|
||||
CreateUserOptions options = new CreateUserOptions();
|
||||
return options.timezone(timezone);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,13 +18,45 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobaUserClient}
|
||||
*
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GlobalUserClientLiveTest")
|
||||
public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
private Account createTestAccount() {
|
||||
return globalAdminClient.getAccountClient().createAccount(
|
||||
prefix + "-account", Account.Type.USER, "dummy@example.com",
|
||||
"First", "Last", "hashed-password");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUser() {
|
||||
Account testAccount = createTestAccount();
|
||||
User testUser = null;
|
||||
try {
|
||||
testUser = globalAdminClient.getUserClient().createUser(prefix + "-user",
|
||||
testAccount.getName(), "dummy2@example.com", "md5-password", "First", "Last");
|
||||
|
||||
assertNotNull(testUser);
|
||||
assertEquals(testUser.getName(), prefix + "-user");
|
||||
assertEquals(testUser.getAccount(), prefix + "-account");
|
||||
|
||||
} finally {
|
||||
if (testUser != null) {
|
||||
globalAdminClient.getUserClient().deleteUser(testUser.getId());
|
||||
}
|
||||
globalAdminClient.getAccountClient().deleteAccount(testAccount.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue