Skip to content

Commit 89d9a70

Browse files
authored
server: Allow template names upto 255 chars (#6768)
* Allow template names upto 255 chars * Update error message * externalise name length in constant Fixes: #6766
1 parent 432a03f commit 89d9a70

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

api/src/main/java/com/cloud/template/VirtualMachineTemplate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.cloud.utils.fsm.StateObject;
3131

3232
public interface VirtualMachineTemplate extends ControlledEntity, Identity, InternalIdentity, StateObject<VirtualMachineTemplate.State> {
33+
int MAXIMUM_TEMPLATE_NAME_LENGTH = 255;
34+
3335
enum State {
3436
Active,
3537
Inactive,

server/src/main/java/com/cloud/template/TemplateManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,9 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
17471747
_accountMgr.checkAccess(caller, null, true, templateOwner);
17481748

17491749
String name = cmd.getTemplateName();
1750-
if ((name == null) || (name.length() > 32)) {
1751-
throw new InvalidParameterValueException("Template name cannot be null and should be less than 32 characters");
1750+
if ((org.apache.commons.lang3.StringUtils.isBlank(name)
1751+
|| (name.length() > VirtualMachineTemplate.MAXIMUM_TEMPLATE_NAME_LENGTH))) {
1752+
throw new InvalidParameterValueException(String.format("Template name cannot be null and cannot be more %s characters", VirtualMachineTemplate.MAXIMUM_TEMPLATE_NAME_LENGTH));
17521753
}
17531754

17541755
if (cmd.getTemplateTag() != null) {

0 commit comments

Comments
 (0)