Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// under the License.
package com.cloud.exception;

import java.util.Map;

import org.apache.cloudstack.context.ErrorMessageResolver;

import com.cloud.utils.exception.CloudRuntimeException;

public class InvalidParameterValueException extends CloudRuntimeException {
Expand All @@ -26,4 +30,8 @@ public InvalidParameterValueException(String message) {
super(message);
}

public InvalidParameterValueException(String key, Map<String, Object> metadata) {
super(ErrorMessageResolver.getMessage(key, metadata), key, metadata);
}

}
6 changes: 4 additions & 2 deletions api/src/main/java/com/cloud/user/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import java.util.List;
import java.util.Map;

import com.cloud.utils.Pair;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.command.admin.account.CreateAccountCmd;
import org.apache.cloudstack.api.command.admin.user.GetUserKeysCmd;
import org.apache.cloudstack.api.command.admin.user.RegisterUserKeyCmd;
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
import org.apache.cloudstack.auth.UserTwoFactorAuthenticator;

import com.cloud.dc.DataCenter;
import com.cloud.domain.Domain;
Expand All @@ -35,7 +35,7 @@
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import org.apache.cloudstack.auth.UserTwoFactorAuthenticator;
import com.cloud.utils.Pair;

public interface AccountService {

Expand Down Expand Up @@ -85,6 +85,8 @@ User createUser(String userName, String password, String firstName, String lastN

boolean isRootAdmin(Long accountId);

boolean isRootAdmin(Account account);

boolean isDomainAdmin(Long accountId);

boolean isResourceDomainAdmin(Long accountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ private Long getNetworkIdFomIpMap(HashMap<String, String> ips) {
try {
networkId = Long.parseLong(networkid);
} catch (NumberFormatException e) {
throw new InvalidParameterValueException("Unable to translate and find entity with networkId: " + networkid);
throw new InvalidParameterValueException("vm.deploy.network.not.found.ip.map",
Map.of("networkId", networkid));
}
}
return networkId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

import java.util.ArrayList;
import java.util.List;

import com.google.gson.annotations.SerializedName;
import java.util.Map;

import org.apache.cloudstack.api.BaseResponse;

import com.cloud.serializer.Param;
import com.cloud.utils.exception.ExceptionProxyObject;
import com.google.gson.annotations.SerializedName;

public class ExceptionResponse extends BaseResponse {

Expand All @@ -44,6 +44,14 @@ public class ExceptionResponse extends BaseResponse {
@Param(description = "the text associated with this error")
private String errorText = "Command failed due to Internal Server Error";

@SerializedName("errortextkey")
@Param(description = "the key for the text associated with this error")
private String errorTextKey = "";

@SerializedName("errormetadata")
@Param(description = "the metadata associated with this error")
private Map<String, String> errorMetadata;

public ExceptionResponse() {
idList = new ArrayList<ExceptionProxyObject>();
}
Expand All @@ -64,6 +72,22 @@ public void setErrorText(String errorText) {
this.errorText = errorText;
}

public String getErrorTextKey() {
return errorTextKey;
}

public void setErrorTextKey(String errorTextKey) {
this.errorTextKey = errorTextKey;
}

public Map<String, String> getErrorMetadata() {
return errorMetadata;
}

public void setErrorMetadata(Map<String, String> errorMetadata) {
this.errorMetadata = errorMetadata;
}

public void addProxyObject(ExceptionProxyObject id) {
idList.add(id);
return;
Expand Down
23 changes: 21 additions & 2 deletions api/src/main/java/org/apache/cloudstack/context/CallContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@

import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import com.cloud.exception.CloudAuthenticationException;
import com.cloud.projects.Project;
import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.user.User;
import com.cloud.utils.UuidUtils;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.logging.log4j.ThreadContext;

/**
* CallContext records information about the environment the call is made. This
Expand All @@ -53,6 +56,7 @@ protected Stack<CallContext> initialValue() {
private String contextId;
private Account account;
private long accountId;
private Boolean isAccountRootAdmin = null;
private long startEventId = 0;
private String eventDescription;
private String eventDetails;
Expand Down Expand Up @@ -134,6 +138,21 @@ public Account getCallingAccount() {
return account;
}

public boolean isCallingAccountRootAdmin() {
if (isAccountRootAdmin == null) {
AccountService accountService;
try {
accountService = ComponentContext.getDelegateComponentOfType(AccountService.class);
} catch (NoSuchBeanDefinitionException e) {
LOGGER.warn("Falling back to account type check for isRootAdmin for account ID: {} as no AccountService bean found: {}", accountId, e.getMessage());
Account caller = getCallingAccount();
return caller != null && caller.getType() == Account.Type.ADMIN;
}
isAccountRootAdmin = accountService.isRootAdmin(getCallingAccount());
}
return Boolean.TRUE.equals(isAccountRootAdmin);
}

public static CallContext current() {
CallContext context = s_currentContext.get();

Expand Down
Loading
Loading