From 0dd3fc9c8c1b138c81bc7d38502f89a96b6f8699 Mon Sep 17 00:00:00 2001 From: ioito Date: Mon, 9 Jan 2023 11:15:15 +0800 Subject: [PATCH] fix(region): hostname validate --- pkg/compute/models/hostnameresource.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/compute/models/hostnameresource.go b/pkg/compute/models/hostnameresource.go index 95d2303cfb..3966301110 100644 --- a/pkg/compute/models/hostnameresource.go +++ b/pkg/compute/models/hostnameresource.go @@ -33,7 +33,9 @@ type SHostnameResourceBaseManager struct { } func (manager *SHostnameResourceBaseManager) ValidateHostname(name string, osType string, input api.HostnameInput) (api.HostnameInput, error) { + inputHostname := true if len(input.Hostname) == 0 { + inputHostname = false if len(name) == 0 { return input, httperrors.NewMissingParameterError("name") } @@ -65,8 +67,10 @@ func (manager *SHostnameResourceBaseManager) ValidateHostname(name string, osTyp } input.Hostname = strings.ReplaceAll(input.Hostname, ".", "") if len(input.Hostname) > api.MAX_WINDOWS_COMPUTER_NAME_LENGTH { - return input, httperrors.NewInputParameterError("Windows hostname cannot be longer than %d characters", api.MAX_WINDOWS_COMPUTER_NAME_LENGTH) - // input.Hostname = input.Hostname[:15] + if inputHostname { + return input, httperrors.NewInputParameterError("Windows hostname cannot be longer than %d characters", api.MAX_WINDOWS_COMPUTER_NAME_LENGTH) + } + input.Hostname = input.Hostname[:15] } } if len(input.Hostname) < 2 {