0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-02 03:22:59 +00:00

chore(code): fix code problems reported by Qodana (#1934)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2025-04-27 21:07:01 -04:00 committed by GitHub
parent 794e959cf2
commit ebd5399e14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 30 deletions

View File

@ -382,9 +382,7 @@ func (d *CustomStorageDevice) UnmarshalJSON(b []byte) error {
// //
// It will return true if any attribute of the current CustomStorageDevice was changed. // It will return true if any attribute of the current CustomStorageDevice was changed.
func (d *CustomStorageDevice) MergeWith(m CustomStorageDevice) bool { func (d *CustomStorageDevice) MergeWith(m CustomStorageDevice) bool {
updated := false updated := ptr.UpdateIfChanged(&d.AIO, m.AIO)
updated = ptr.UpdateIfChanged(&d.AIO, m.AIO) || updated
updated = ptr.UpdateIfChanged(&d.Backup, m.Backup) || updated updated = ptr.UpdateIfChanged(&d.Backup, m.Backup) || updated
updated = ptr.UpdateIfChanged(&d.BurstableReadSpeedMbps, m.BurstableReadSpeedMbps) || updated updated = ptr.UpdateIfChanged(&d.BurstableReadSpeedMbps, m.BurstableReadSpeedMbps) || updated
updated = ptr.UpdateIfChanged(&d.BurstableWriteSpeedMbps, m.BurstableWriteSpeedMbps) || updated updated = ptr.UpdateIfChanged(&d.BurstableWriteSpeedMbps, m.BurstableWriteSpeedMbps) || updated

View File

@ -73,7 +73,7 @@ func (r *CustomVirtiofsShare) EncodeValues(key string, v *url.Values) error {
} }
// EncodeValues converts a CustomVirtiofsShares dict to multiple URL values. // EncodeValues converts a CustomVirtiofsShares dict to multiple URL values.
func (r CustomVirtiofsShares) EncodeValues(key string, v *url.Values) error { func (r CustomVirtiofsShares) EncodeValues(_ string, v *url.Values) error {
for s, d := range r { for s, d := range r {
if err := d.EncodeValues(s, v); err != nil { if err := d.EncodeValues(s, v); err != nil {
return fmt.Errorf("failed to encode virtiofs share %s: %w", s, err) return fmt.Errorf("failed to encode virtiofs share %s: %w", s, err)

View File

@ -85,7 +85,6 @@ const (
dvInitializationIPConfigIPv6Address = "" dvInitializationIPConfigIPv6Address = ""
dvInitializationIPConfigIPv6Gateway = "" dvInitializationIPConfigIPv6Gateway = ""
dvInitializationUserAccountPassword = "" dvInitializationUserAccountPassword = ""
dvInitializationType = ""
dvKeyboardLayout = "en-us" dvKeyboardLayout = "en-us"
dvKVMArguments = "" dvKVMArguments = ""
dvMachineType = "" dvMachineType = ""
@ -290,9 +289,9 @@ const (
mkVirtiofs = "virtiofs" mkVirtiofs = "virtiofs"
mkVirtiofsMapping = "mapping" mkVirtiofsMapping = "mapping"
mkVirtiofsCache = "cache" mkVirtiofsCache = "cache"
mkVirtiofsDirectIo = "direct_io" mkVirtiofsDirectIO = "direct_io"
mkVirtiofsExposeAcl = "expose_acl" mkVirtiofsExposeACL = "expose_acl"
mkVirtiofsExposeXattr = "expose_xattr" mkVirtiofsExposeXAttr = "expose_xattr"
mkWatchdog = "watchdog" mkWatchdog = "watchdog"
// a workaround for the lack of proper support of default and undefined values in SDK. // a workaround for the lack of proper support of default and undefined values in SDK.
mkWatchdogEnabled = "enabled" mkWatchdogEnabled = "enabled"
@ -1495,19 +1494,19 @@ func VM() *schema.Resource {
Default: dvVirtiofsCache, Default: dvVirtiofsCache,
ValidateDiagFunc: VirtiofsCacheValidator(), ValidateDiagFunc: VirtiofsCacheValidator(),
}, },
mkVirtiofsDirectIo: { mkVirtiofsDirectIO: {
Type: schema.TypeBool, Type: schema.TypeBool,
Description: "Whether to allow direct io", Description: "Whether to allow direct io",
Optional: true, Optional: true,
Default: dvVirtiofsDirectIo, Default: dvVirtiofsDirectIo,
}, },
mkVirtiofsExposeAcl: { mkVirtiofsExposeACL: {
Type: schema.TypeBool, Type: schema.TypeBool,
Description: "Enable POSIX ACLs, implies xattr support", Description: "Enable POSIX ACLs, implies xattr support",
Optional: true, Optional: true,
Default: dvVirtiofsExposeAcl, Default: dvVirtiofsExposeAcl,
}, },
mkVirtiofsExposeXattr: { mkVirtiofsExposeXAttr: {
Type: schema.TypeBool, Type: schema.TypeBool,
Description: "Enable support for extended attributes", Description: "Enable support for extended attributes",
Optional: true, Optional: true,
@ -3411,15 +3410,15 @@ func vmGetVirtiofsShares(d *schema.ResourceData) vms.CustomVirtiofsShares {
mapping, _ := block[mkVirtiofsMapping].(string) mapping, _ := block[mkVirtiofsMapping].(string)
cache, _ := block[mkVirtiofsCache].(string) cache, _ := block[mkVirtiofsCache].(string)
direct_io := types.CustomBool(block[mkVirtiofsDirectIo].(bool)) directIO := types.CustomBool(block[mkVirtiofsDirectIO].(bool))
expose_acl := types.CustomBool(block[mkVirtiofsExposeAcl].(bool)) exposeACL := types.CustomBool(block[mkVirtiofsExposeACL].(bool))
expose_xattr := types.CustomBool(block[mkVirtiofsExposeXattr].(bool)) exposeXAttr := types.CustomBool(block[mkVirtiofsExposeXAttr].(bool))
share := vms.CustomVirtiofsShare{ share := vms.CustomVirtiofsShare{
DirId: mapping, DirId: mapping,
DirectIo: &direct_io, DirectIo: &directIO,
ExposeAcl: &expose_acl, ExposeAcl: &exposeACL,
ExposeXattr: &expose_xattr, ExposeXattr: &exposeXAttr,
} }
if cache != "" { if cache != "" {
@ -4064,25 +4063,25 @@ func vmReadCustom(
} }
if pp.DirectIo != nil { if pp.DirectIo != nil {
share[mkVirtiofsDirectIo] = *pp.DirectIo share[mkVirtiofsDirectIO] = *pp.DirectIo
} else { } else {
share[mkVirtiofsDirectIo] = dvVirtiofsDirectIo share[mkVirtiofsDirectIO] = dvVirtiofsDirectIo
} }
if pp.ExposeAcl != nil { if pp.ExposeAcl != nil {
share[mkVirtiofsExposeAcl] = *pp.ExposeAcl share[mkVirtiofsExposeACL] = *pp.ExposeAcl
} else { } else {
share[mkVirtiofsExposeAcl] = dvVirtiofsExposeAcl share[mkVirtiofsExposeACL] = dvVirtiofsExposeAcl
} }
switch { switch {
case pp.ExposeXattr != nil: case pp.ExposeXattr != nil:
share[mkVirtiofsExposeXattr] = *pp.ExposeXattr share[mkVirtiofsExposeXAttr] = *pp.ExposeXattr
case pp.ExposeAcl != nil && bool(*pp.ExposeAcl): case pp.ExposeAcl != nil && bool(*pp.ExposeAcl):
// expose-xattr implies expose-acl // expose-xattr implies expose-acl
share[mkVirtiofsExposeXattr] = true share[mkVirtiofsExposeXAttr] = true
default: default:
share[mkVirtiofsExposeXattr] = dvVirtiofsExposeXattr share[mkVirtiofsExposeXAttr] = dvVirtiofsExposeXattr
} }
virtiofsMap[pi] = share virtiofsMap[pi] = share

View File

@ -388,17 +388,17 @@ func TestVMSchema(t *testing.T) {
test.AssertOptionalArguments(t, virtiofsSchema, []string{ test.AssertOptionalArguments(t, virtiofsSchema, []string{
mkVirtiofsCache, mkVirtiofsCache,
mkVirtiofsDirectIo, mkVirtiofsDirectIO,
mkVirtiofsExposeAcl, mkVirtiofsExposeACL,
mkVirtiofsExposeXattr, mkVirtiofsExposeXAttr,
}) })
test.AssertValueTypes(t, virtiofsSchema, map[string]schema.ValueType{ test.AssertValueTypes(t, virtiofsSchema, map[string]schema.ValueType{
mkVirtiofsMapping: schema.TypeString, mkVirtiofsMapping: schema.TypeString,
mkVirtiofsCache: schema.TypeString, mkVirtiofsCache: schema.TypeString,
mkVirtiofsDirectIo: schema.TypeBool, mkVirtiofsDirectIO: schema.TypeBool,
mkVirtiofsExposeAcl: schema.TypeBool, mkVirtiofsExposeACL: schema.TypeBool,
mkVirtiofsExposeXattr: schema.TypeBool, mkVirtiofsExposeXAttr: schema.TypeBool,
}) })
vgaSchema := test.AssertNestedSchemaExistence(t, s, mkVGA) vgaSchema := test.AssertNestedSchemaExistence(t, s, mkVGA)