server: Allow template names upto 255 chars (#6768)

* Allow template names upto 255 chars

* Update error message

* externalise name length in constant

Fixes: #6766
This commit is contained in:
dahn 2022-09-30 07:16:50 +02:00 committed by GitHub
parent 432a03fb02
commit 89d9a70dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -30,6 +30,8 @@ import com.cloud.utils.fsm.StateMachine2;
import com.cloud.utils.fsm.StateObject;
public interface VirtualMachineTemplate extends ControlledEntity, Identity, InternalIdentity, StateObject<VirtualMachineTemplate.State> {
int MAXIMUM_TEMPLATE_NAME_LENGTH = 255;
enum State {
Active,
Inactive,

View File

@ -1747,8 +1747,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
_accountMgr.checkAccess(caller, null, true, templateOwner);
String name = cmd.getTemplateName();
if ((name == null) || (name.length() > 32)) {
throw new InvalidParameterValueException("Template name cannot be null and should be less than 32 characters");
if ((org.apache.commons.lang3.StringUtils.isBlank(name)
|| (name.length() > VirtualMachineTemplate.MAXIMUM_TEMPLATE_NAME_LENGTH))) {
throw new InvalidParameterValueException(String.format("Template name cannot be null and cannot be more %s characters", VirtualMachineTemplate.MAXIMUM_TEMPLATE_NAME_LENGTH));
}
if (cmd.getTemplateTag() != null) {