From 32d9a2dcbed4a5720e35eba0e051061d0ed66948 Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Wed, 21 Jun 2023 21:21:13 +0000 Subject: [PATCH] feat: validator `QemuWorldWideName` --- proxmox/config_qemu_disk.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/proxmox/config_qemu_disk.go b/proxmox/config_qemu_disk.go index 0176e719..8539e1c5 100644 --- a/proxmox/config_qemu_disk.go +++ b/proxmox/config_qemu_disk.go @@ -443,6 +443,9 @@ func (disk *qemuDisk) validate() (err error) { if err = disk.Serial.Validate(); err != nil { return } + if err = disk.WorldWideName.Validate(); err != nil { + return + } if disk.Disk { // disk if err = disk.Format.Validate(); err != nil { @@ -1016,6 +1019,17 @@ type qemuUpdateChanges struct { type QemuWorldWideName string +const Error_QemuWorldWideName_Invalid string = "world wide name should be prefixed with 0x followed by 8 hexadecimal values" + +var regexp_QemuWorldWideName = regexp.MustCompile(`^0x[0-9A-Fa-f]{16}$`) + +func (wwn QemuWorldWideName) Validate() error { + if wwn == "" || regexp_QemuWorldWideName.MatchString(string(wwn)) { + return nil + } + return errors.New(Error_QemuWorldWideName_Invalid) +} + func diskSubtypeSet(set bool) error { if set { return errors.New(Error_QemuDisk_MutuallyExclusive)