Skip to content

Commit cad16ed

Browse files
committed
bug 10325: renamed apiKey/secretKey to userApiKey/userSecretKey in updateUser api call
This reverts commit 927508215de383bdcc5b2e289e5103e011d72843.
1 parent ae6907d commit cad16ed

4 files changed

Lines changed: 9 additions & 25 deletions

File tree

‎api/src/com/cloud/api/ApiConstants.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ApiConstants {
2424
public static final String ACCOUNT_ID = "accountid";
2525
public static final String ALGORITHM = "algorithm";
2626
public static final String ALLOCATED_ONLY = "allocatedonly";
27-
public static final String API_KEY = "apikey";
27+
public static final String API_KEY = "userapikey";
2828
public static final String APPLIED = "applied";
2929
public static final String AVAILABLE = "available";
3030
public static final String BITS = "bits";
@@ -144,7 +144,7 @@ public class ApiConstants {
144144
public static final String RESOURCE_TYPE = "resourcetype";
145145
public static final String SCHEDULE = "schedule";
146146
public static final String SCOPE = "scope";
147-
public static final String SECRET_KEY = "secretkey";
147+
public static final String SECRET_KEY = "usersecretkey";
148148
public static final String SECURITY_GROUP_IDS = "securitygroupids";
149149
public static final String SECURITY_GROUP_NAMES = "securitygroupnames";
150150
public static final String SECURITY_GROUP_NAME = "securitygroupname";

‎api/src/com/cloud/api/commands/UpdateUserCmd.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class UpdateUserCmd extends BaseCmd {
4141
//////////////// API parameters /////////////////////
4242
/////////////////////////////////////////////////////
4343

44-
@Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="The API key for the user. Must be specified with secretKey")
44+
@Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="The API key for the user. Must be specified with userSecretKey")
4545
private String apiKey;
4646

4747
@Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, description="email")
@@ -59,7 +59,7 @@ public class UpdateUserCmd extends BaseCmd {
5959
@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")
6060
private String password;
6161

62-
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="The secret key for the user. Must be specified with apiKey")
62+
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="The secret key for the user. Must be specified with userApiKey")
6363
private String secretKey;
6464

6565
@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.")

‎api/src/com/cloud/api/response/UserResponse.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.Date;
2121

22+
import com.cloud.api.ApiConstants;
2223
import com.cloud.serializer.Param;
2324
import com.google.gson.annotations.SerializedName;
2425

@@ -59,10 +60,10 @@ public class UserResponse extends BaseResponse {
5960
@SerializedName("timezone") @Param(description="the timezone user was created in")
6061
private String timezone;
6162

62-
@SerializedName("apikey") @Param(description="the api key of the user")
63+
@SerializedName(ApiConstants.API_KEY) @Param(description="the api key of the user")
6364
private String apiKey;
6465

65-
@SerializedName("secretkey") @Param(description="the secret key of the user")
66+
@SerializedName(ApiConstants.SECRET_KEY) @Param(description="the secret key of the user")
6667
private String secretKey;
6768

6869
public Long getId() {

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,33 +1400,16 @@ public UserAccount updateUser(UpdateUserCmd cmd) {
14001400
String secretKey = cmd.getSecretKey();
14011401
String timeZone = cmd.getTimezone();
14021402
String userName = cmd.getUsername();
1403-
1404-
long callerUserId = UserContext.current().getCallerUserId();
14051403

14061404
// Input validation
14071405
UserVO user = _userDao.getUser(id);
14081406

14091407
if (user == null) {
14101408
throw new InvalidParameterValueException("unable to find user by id");
14111409
}
1412-
1413-
if (apiKey != null) {
1414-
Long apiKeyOwnerId = null;
1415-
Pair<User, Account> apiKeyOwner = _accountDao.findUserAccountByApiKey(apiKey);
1416-
if (apiKeyOwner != null) {
1417-
apiKeyOwnerId = apiKeyOwner.first().getId();
1418-
}
1419-
1420-
if ((apiKeyOwnerId == null || callerUserId != apiKeyOwnerId) && secretKey == null) {
1421-
throw new InvalidParameterValueException("Please provide an api key/secret key pair");
1422-
} else if (apiKeyOwnerId != null && callerUserId == apiKeyOwnerId && id != callerUserId) {
1423-
// No need to update api key if provided api key belongs to the caller and caller updates api key for someone else
1424-
apiKey = null;
1425-
}
1426-
}
14271410

1428-
if (apiKey == null && secretKey != null) {
1429-
throw new InvalidParameterValueException("Please provide an api key/secret key pair");
1411+
if ((apiKey == null && secretKey != null) || (apiKey != null && secretKey == null)) {
1412+
throw new InvalidParameterValueException("Please provide an userApiKey/userSecretKey pair");
14301413
}
14311414

14321415
// If the account is an admin type, return an error. We do not allow this

0 commit comments

Comments
 (0)