bug 10325: renamed apiKey/secretKey to userApiKey/userSecretKey in updateUser api call

This reverts commit 927508215de383bdcc5b2e289e5103e011d72843.
This commit is contained in:
alena 2011-06-16 11:30:41 -07:00
parent ae6907dd01
commit cad16ed27f
4 changed files with 9 additions and 25 deletions

View File

@ -24,7 +24,7 @@ public class ApiConstants {
public static final String ACCOUNT_ID = "accountid";
public static final String ALGORITHM = "algorithm";
public static final String ALLOCATED_ONLY = "allocatedonly";
public static final String API_KEY = "apikey";
public static final String API_KEY = "userapikey";
public static final String APPLIED = "applied";
public static final String AVAILABLE = "available";
public static final String BITS = "bits";
@ -144,7 +144,7 @@ public class ApiConstants {
public static final String RESOURCE_TYPE = "resourcetype";
public static final String SCHEDULE = "schedule";
public static final String SCOPE = "scope";
public static final String SECRET_KEY = "secretkey";
public static final String SECRET_KEY = "usersecretkey";
public static final String SECURITY_GROUP_IDS = "securitygroupids";
public static final String SECURITY_GROUP_NAMES = "securitygroupnames";
public static final String SECURITY_GROUP_NAME = "securitygroupname";

View File

@ -41,7 +41,7 @@ public class UpdateUserCmd extends BaseCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="The API key for the user. Must be specified with secretKey")
@Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="The API key for the user. Must be specified with userSecretKey")
private String apiKey;
@Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, description="email")
@ -59,7 +59,7 @@ public class UpdateUserCmd extends BaseCmd {
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, description="Hashed password (default is MD5). If you wish to use any other hasing algorithm, you would need to write a custom authentication adapter")
private String password;
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="The secret key for the user. Must be specified with apiKey")
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="The secret key for the user. Must be specified with userApiKey")
private String secretKey;
@Parameter(name=ApiConstants.TIMEZONE, type=CommandType.STRING, description="Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")

View File

@ -19,6 +19,7 @@ package com.cloud.api.response;
import java.util.Date;
import com.cloud.api.ApiConstants;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@ -59,10 +60,10 @@ public class UserResponse extends BaseResponse {
@SerializedName("timezone") @Param(description="the timezone user was created in")
private String timezone;
@SerializedName("apikey") @Param(description="the api key of the user")
@SerializedName(ApiConstants.API_KEY) @Param(description="the api key of the user")
private String apiKey;
@SerializedName("secretkey") @Param(description="the secret key of the user")
@SerializedName(ApiConstants.SECRET_KEY) @Param(description="the secret key of the user")
private String secretKey;
public Long getId() {

View File

@ -1400,8 +1400,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
String secretKey = cmd.getSecretKey();
String timeZone = cmd.getTimezone();
String userName = cmd.getUsername();
long callerUserId = UserContext.current().getCallerUserId();
// Input validation
UserVO user = _userDao.getUser(id);
@ -1409,24 +1407,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
if (user == null) {
throw new InvalidParameterValueException("unable to find user by id");
}
if (apiKey != null) {
Long apiKeyOwnerId = null;
Pair<User, Account> apiKeyOwner = _accountDao.findUserAccountByApiKey(apiKey);
if (apiKeyOwner != null) {
apiKeyOwnerId = apiKeyOwner.first().getId();
}
if ((apiKeyOwnerId == null || callerUserId != apiKeyOwnerId) && secretKey == null) {
throw new InvalidParameterValueException("Please provide an api key/secret key pair");
} else if (apiKeyOwnerId != null && callerUserId == apiKeyOwnerId && id != callerUserId) {
// No need to update api key if provided api key belongs to the caller and caller updates api key for someone else
apiKey = null;
}
}
if (apiKey == null && secretKey != null) {
throw new InvalidParameterValueException("Please provide an api key/secret key pair");
if ((apiKey == null && secretKey != null) || (apiKey != null && secretKey == null)) {
throw new InvalidParameterValueException("Please provide an userApiKey/userSecretKey pair");
}
// If the account is an admin type, return an error. We do not allow this