mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 18:42:58 +00:00
fix: linter issues (#158)
* fix: remove io/ioutil * fix: lost diagnostic context * fix: various linter errors * fix: json manifests
This commit is contained in:
parent
552af4d3df
commit
0fad160ed6
@ -116,7 +116,7 @@ func (r *CustomLineBreakSeparatedList) UnmarshalJSON(b []byte) error {
|
||||
|
||||
// MarshalJSON converts a boolean to a JSON value.
|
||||
func (r *CustomPrivileges) MarshalJSON() ([]byte, error) {
|
||||
var privileges map[string]CustomBool
|
||||
privileges := map[string]CustomBool{}
|
||||
|
||||
for _, v := range *r {
|
||||
privileges[v] = true
|
||||
@ -135,10 +135,8 @@ func (r *CustomPrivileges) UnmarshalJSON(b []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
switch privileges.(type) {
|
||||
switch s := privileges.(type) {
|
||||
case string:
|
||||
s := privileges.(string)
|
||||
|
||||
if s != "" {
|
||||
*r = strings.Split(s, ",")
|
||||
} else {
|
||||
@ -159,9 +157,7 @@ func (r *CustomPrivileges) UnmarshalJSON(b []byte) error {
|
||||
|
||||
// MarshalJSON converts a boolean to a JSON value.
|
||||
func (r CustomTimestamp) MarshalJSON() ([]byte, error) {
|
||||
var timestamp time.Time
|
||||
|
||||
timestamp = time.Time(r)
|
||||
timestamp := time.Time(r)
|
||||
buffer := bytes.NewBufferString(strconv.FormatInt(timestamp.Unix(), 10))
|
||||
|
||||
return buffer.Bytes(), nil
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@ -190,7 +189,7 @@ func (c *VirtualEnvironmentClient) DoRequest(ctx context.Context, method, path s
|
||||
return fErr
|
||||
}
|
||||
} else {
|
||||
data, _ := ioutil.ReadAll(res.Body)
|
||||
data, _ := io.ReadAll(res.Body)
|
||||
tflog.Warn(ctx, "unhandled HTTP response body", map[string]interface{}{
|
||||
"data": string(data),
|
||||
})
|
||||
|
@ -24,7 +24,7 @@ func (c *VirtualEnvironmentClient) AddCIDRToIPSet(ctx context.Context, id string
|
||||
|
||||
// UpdateIPSet updates an IPSet.
|
||||
func (c *VirtualEnvironmentClient) UpdateIPSet(ctx context.Context, d *VirtualEnvironmentClusterIPSetUpdateRequestBody) error {
|
||||
return c.DoRequest(ctx, hmPOST, fmt.Sprint("cluster/firewall/ipset/"), d, nil)
|
||||
return c.DoRequest(ctx, hmPOST, "cluster/firewall/ipset/", d, nil)
|
||||
}
|
||||
|
||||
// DeleteIPSet delete an IPSet
|
||||
|
@ -111,7 +111,7 @@ func (c *VirtualEnvironmentClient) WaitForContainerState(ctx context.Context, no
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
timeElapsed = time.Now().Sub(timeStart)
|
||||
timeElapsed = time.Since(timeStart)
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
@ -145,7 +145,7 @@ func (c *VirtualEnvironmentClient) WaitForContainerLock(ctx context.Context, nod
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
timeElapsed = time.Now().Sub(timeStart)
|
||||
timeElapsed = time.Since(timeStart)
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
|
@ -210,7 +210,7 @@ type VirtualEnvironmentContainerRebootRequestBody struct {
|
||||
|
||||
// VirtualEnvironmentContainerShutdownRequestBody contains the body for a container shutdown request.
|
||||
type VirtualEnvironmentContainerShutdownRequestBody struct {
|
||||
ForceStop *CustomBool `json:"forceStop,omitempty,int" url:"forceStop,omitempty,int"`
|
||||
ForceStop *CustomBool `json:"forceStop,omitempty" url:"forceStop,omitempty,int"`
|
||||
Timeout *int `json:"timeout,omitempty" url:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -84,7 +84,13 @@ func (c *VirtualEnvironmentClient) UploadFileToDatastore(ctx context.Context, d
|
||||
defer w.Close()
|
||||
defer m.Close()
|
||||
|
||||
m.WriteField("content", d.ContentType)
|
||||
err := m.WriteField("content", d.ContentType)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, "failed to write 'content' field", map[string]interface{}{
|
||||
"error": err,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
part, err := m.CreateFormFile("filename", d.FileName)
|
||||
|
||||
@ -101,7 +107,7 @@ func (c *VirtualEnvironmentClient) UploadFileToDatastore(ctx context.Context, d
|
||||
|
||||
// We need to store the multipart content in a temporary file to avoid using high amounts of memory.
|
||||
// This is necessary due to Proxmox VE not supporting chunked transfers in v6.1 and earlier versions.
|
||||
tempMultipartFile, err := ioutil.TempFile("", "multipart")
|
||||
tempMultipartFile, err := os.CreateTemp("", "multipart")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -109,7 +115,10 @@ func (c *VirtualEnvironmentClient) UploadFileToDatastore(ctx context.Context, d
|
||||
|
||||
tempMultipartFileName := tempMultipartFile.Name()
|
||||
|
||||
io.Copy(tempMultipartFile, r)
|
||||
_, err = io.Copy(tempMultipartFile, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = tempMultipartFile.Close()
|
||||
|
||||
|
@ -218,7 +218,7 @@ func (c *VirtualEnvironmentClient) WaitForNodeTask(ctx context.Context, nodeName
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
timeElapsed = time.Now().Sub(timeStart)
|
||||
timeElapsed = time.Since(timeStart)
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
|
@ -432,7 +432,7 @@ func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(ctx conte
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
timeElapsed = time.Now().Sub(timeStart)
|
||||
timeElapsed = time.Since(timeStart)
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
@ -462,7 +462,7 @@ func (c *VirtualEnvironmentClient) WaitForNoNetworkInterfacesFromVMAgent(ctx con
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
timeElapsed = time.Now().Sub(timeStart)
|
||||
timeElapsed = time.Since(timeStart)
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
@ -496,7 +496,7 @@ func (c *VirtualEnvironmentClient) WaitForVMConfigUnlock(ctx context.Context, no
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
timeElapsed = time.Now().Sub(timeStart)
|
||||
timeElapsed = time.Since(timeStart)
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
@ -531,7 +531,7 @@ func (c *VirtualEnvironmentClient) WaitForVMState(ctx context.Context, nodeName
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
timeElapsed = time.Now().Sub(timeStart)
|
||||
timeElapsed = time.Since(timeStart)
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
|
@ -504,7 +504,7 @@ type VirtualEnvironmentVMListResponseData struct {
|
||||
// VirtualEnvironmentVMMoveDiskRequestBody contains the body for a VM move disk request.
|
||||
type VirtualEnvironmentVMMoveDiskRequestBody struct {
|
||||
BandwidthLimit *int `json:"bwlimit,omitempty" url:"bwlimit,omitempty"`
|
||||
DeleteOriginalDisk *CustomBool `json:"delete,omitempty,int" url:"delete,omitempty,int"`
|
||||
DeleteOriginalDisk *CustomBool `json:"delete,omitempty" url:"delete,omitempty,int"`
|
||||
Digest *string `json:"digest,omitempty" url:"digest,omitempty"`
|
||||
Disk string `json:"disk" url:"disk"`
|
||||
TargetStorage string `json:"storage" url:"storage"`
|
||||
@ -531,14 +531,14 @@ type VirtualEnvironmentVMResizeDiskRequestBody struct {
|
||||
Digest *string `json:"digest,omitempty" url:"digest,omitempty"`
|
||||
Disk string `json:"disk" url:"disk"`
|
||||
Size string `json:"size" url:"size"`
|
||||
SkipLock *CustomBool `json:"skiplock,omitempty,int" url:"skiplock,omitempty,int"`
|
||||
SkipLock *CustomBool `json:"skiplock,omitempty" url:"skiplock,omitempty,int"`
|
||||
}
|
||||
|
||||
// VirtualEnvironmentVMShutdownRequestBody contains the body for a VM shutdown request.
|
||||
type VirtualEnvironmentVMShutdownRequestBody struct {
|
||||
ForceStop *CustomBool `json:"forceStop,omitempty,int" url:"forceStop,omitempty,int"`
|
||||
KeepActive *CustomBool `json:"keepActive,omitempty,int" url:"keepActive,omitempty,int"`
|
||||
SkipLock *CustomBool `json:"skipLock,omitempty,int" url:"skipLock,omitempty,int"`
|
||||
ForceStop *CustomBool `json:"forceStop,omitempty" url:"forceStop,omitempty,int"`
|
||||
KeepActive *CustomBool `json:"keepActive,omitempty" url:"keepActive,omitempty,int"`
|
||||
SkipLock *CustomBool `json:"skipLock,omitempty" url:"skipLock,omitempty,int"`
|
||||
Timeout *int `json:"timeout,omitempty" url:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
@ -980,9 +980,9 @@ func (r CustomSpiceEnhancements) EncodeValues(key string, v *url.Values) error {
|
||||
|
||||
if r.FolderSharing != nil {
|
||||
if *r.FolderSharing {
|
||||
values = append(values, fmt.Sprintf("foldersharing=1"))
|
||||
values = append(values, "foldersharing=1")
|
||||
} else {
|
||||
values = append(values, fmt.Sprintf("foldersharing=0"))
|
||||
values = append(values, "foldersharing=0")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ func dataSourceVirtualEnvironmentNodes() *schema.Resource {
|
||||
Type: schema.TypeList,
|
||||
Description: "The uptime in seconds for each node",
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
Elem: &schema.Schema{Type: schema.TypeInt},
|
||||
},
|
||||
},
|
||||
ReadContext: dataSourceVirtualEnvironmentNodesRead,
|
||||
@ -183,5 +183,5 @@ func dataSourceVirtualEnvironmentNodesRead(ctx context.Context, d *schema.Resour
|
||||
err = d.Set(mkDataSourceVirtualEnvironmentNodesUptime, uptime)
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
|
||||
return nil
|
||||
return diags
|
||||
}
|
||||
|
@ -859,6 +859,7 @@ func resourceVirtualEnvironmentContainerCreateClone(ctx context.Context, d *sche
|
||||
|
||||
template := proxmox.CustomBool(d.Get(mkResourceVirtualEnvironmentContainerTemplate).(bool))
|
||||
|
||||
//nolint:gosimple
|
||||
if template != dvResourceVirtualEnvironmentContainerTemplate {
|
||||
updateBody.Template = &template
|
||||
}
|
||||
@ -1642,6 +1643,7 @@ func resourceVirtualEnvironmentContainerRead(ctx context.Context, d *schema.Reso
|
||||
|
||||
currentTemplate := d.Get(mkResourceVirtualEnvironmentContainerTemplate).(bool)
|
||||
|
||||
//nolint:gosimple
|
||||
if len(clone) == 0 || currentTemplate != dvResourceVirtualEnvironmentContainerTemplate {
|
||||
if containerConfig.Template != nil {
|
||||
err = d.Set(mkResourceVirtualEnvironmentContainerTemplate, bool(*containerConfig.Template))
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -261,7 +260,7 @@ func resourceVirtualEnvironmentFileCreate(ctx context.Context, d *schema.Resourc
|
||||
}
|
||||
}(res.Body)
|
||||
|
||||
tempDownloadedFile, err := ioutil.TempFile("", "download")
|
||||
tempDownloadedFile, err := os.CreateTemp("", "download")
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@ -330,7 +329,7 @@ func resourceVirtualEnvironmentFileCreate(ctx context.Context, d *schema.Resourc
|
||||
}
|
||||
}
|
||||
|
||||
tempRawFile, err := ioutil.TempFile("", "raw")
|
||||
tempRawFile, err := os.CreateTemp("", "raw")
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ func resourceVirtualEnvironmentPoolRead(ctx context.Context, d *schema.ResourceD
|
||||
err = d.Set(mkResourceVirtualEnvironmentPoolMembers, members)
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
|
||||
return diag.FromErr(err)
|
||||
return diags
|
||||
}
|
||||
|
||||
func resourceVirtualEnvironmentPoolUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
|
@ -97,7 +97,7 @@ func resourceVirtualEnvironmentTimeRead(ctx context.Context, d *schema.ResourceD
|
||||
err = d.Set(mkDataSourceVirtualEnvironmentTimeUTCTime, time.Time(nodeTime.UTCTime).Format(time.RFC3339))
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
|
||||
return nil
|
||||
return diags
|
||||
}
|
||||
|
||||
func resourceVirtualEnvironmentTimeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
|
@ -1194,6 +1194,7 @@ func resourceVirtualEnvironmentVMCreateClone(ctx context.Context, d *schema.Reso
|
||||
|
||||
var del []string
|
||||
|
||||
//nolint:gosimple
|
||||
if acpi != dvResourceVirtualEnvironmentVMACPI {
|
||||
updateBody.ACPI = &acpi
|
||||
}
|
||||
@ -1378,10 +1379,12 @@ func resourceVirtualEnvironmentVMCreateClone(ctx context.Context, d *schema.Reso
|
||||
|
||||
updateBody.StartOnBoot = &onBoot
|
||||
|
||||
//nolint:gosimple
|
||||
if tabletDevice != dvResourceVirtualEnvironmentVMTabletDevice {
|
||||
updateBody.TabletDeviceEnabled = &tabletDevice
|
||||
}
|
||||
|
||||
//nolint:gosimple
|
||||
if template != dvResourceVirtualEnvironmentVMTemplate {
|
||||
updateBody.Template = &template
|
||||
}
|
||||
@ -3157,6 +3160,7 @@ func resourceVirtualEnvironmentVMReadPrimitiveValues(d *schema.ResourceData, vmC
|
||||
clone := d.Get(mkResourceVirtualEnvironmentVMClone).([]interface{})
|
||||
currentACPI := d.Get(mkResourceVirtualEnvironmentVMACPI).(bool)
|
||||
|
||||
//nolint:gosimple
|
||||
if len(clone) == 0 || currentACPI != dvResourceVirtualEnvironmentVMACPI {
|
||||
if vmConfig.ACPI != nil {
|
||||
err = d.Set(mkResourceVirtualEnvironmentVMACPI, bool(*vmConfig.ACPI))
|
||||
@ -3215,13 +3219,14 @@ func resourceVirtualEnvironmentVMReadPrimitiveValues(d *schema.ResourceData, vmC
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
}
|
||||
|
||||
if d.Get(mkResourceVirtualEnvironmentVMTemplate).(bool) != true {
|
||||
if !d.Get(mkResourceVirtualEnvironmentVMTemplate).(bool) {
|
||||
err = d.Set(mkResourceVirtualEnvironmentVMStarted, vmStatus.Status == "running")
|
||||
diags = append(diags, diag.FromErr(err)...)
|
||||
}
|
||||
|
||||
currentTabletDevice := d.Get(mkResourceVirtualEnvironmentVMTabletDevice).(bool)
|
||||
|
||||
//nolint:gosimple
|
||||
if len(clone) == 0 || currentTabletDevice != dvResourceVirtualEnvironmentVMTabletDevice {
|
||||
if vmConfig.TabletDeviceEnabled != nil {
|
||||
err = d.Set(mkResourceVirtualEnvironmentVMTabletDevice, bool(*vmConfig.TabletDeviceEnabled))
|
||||
@ -3234,6 +3239,7 @@ func resourceVirtualEnvironmentVMReadPrimitiveValues(d *schema.ResourceData, vmC
|
||||
|
||||
currentTemplate := d.Get(mkResourceVirtualEnvironmentVMTemplate).(bool)
|
||||
|
||||
//nolint:gosimple
|
||||
if len(clone) == 0 || currentTemplate != dvResourceVirtualEnvironmentVMTemplate {
|
||||
if vmConfig.Template != nil {
|
||||
err = d.Set(mkResourceVirtualEnvironmentVMTemplate, bool(*vmConfig.Template))
|
||||
@ -3383,7 +3389,7 @@ func resourceVirtualEnvironmentVMUpdate(ctx context.Context, d *schema.ResourceD
|
||||
cdromEnabled := cdromBlock[mkResourceVirtualEnvironmentVMCDROMEnabled].(bool)
|
||||
cdromFileID := cdromBlock[mkResourceVirtualEnvironmentVMCDROMFileID].(string)
|
||||
|
||||
if cdromEnabled == false && cdromFileID == "" {
|
||||
if !cdromEnabled && cdromFileID == "" {
|
||||
del = append(del, "ide3")
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ func getContentTypeValidator() schema.SchemaValidateDiagFunc {
|
||||
}, false))
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getCPUFlagsValidator() schema.SchemaValidateDiagFunc {
|
||||
return validation.ToDiagFunc(func(i interface{}, k string) (ws []string, es []error) {
|
||||
list, ok := i.([]interface{})
|
||||
@ -332,6 +333,7 @@ func getVGATypeValidator() schema.SchemaValidateDiagFunc {
|
||||
}, false))
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getVLANIDsValidator() schema.SchemaValidateDiagFunc {
|
||||
return validation.ToDiagFunc(func(i interface{}, k string) (ws []string, es []error) {
|
||||
min := 1
|
||||
@ -507,7 +509,7 @@ func testComputedAttributes(t *testing.T, s *schema.Resource, keys []string) {
|
||||
t.Fatalf("Error in Schema: Missing definition for \"%s\"", v)
|
||||
}
|
||||
|
||||
if s.Schema[v].Computed != true {
|
||||
if !s.Schema[v].Computed {
|
||||
t.Fatalf("Error in Schema: Attribute \"%s\" is not computed", v)
|
||||
}
|
||||
}
|
||||
@ -531,7 +533,7 @@ func testOptionalArguments(t *testing.T, s *schema.Resource, keys []string) {
|
||||
t.Fatalf("Error in Schema: Missing definition for \"%s\"", v)
|
||||
}
|
||||
|
||||
if s.Schema[v].Optional != true {
|
||||
if !s.Schema[v].Optional {
|
||||
t.Fatalf("Error in Schema: Argument \"%s\" is not optional", v)
|
||||
}
|
||||
}
|
||||
@ -543,7 +545,7 @@ func testRequiredArguments(t *testing.T, s *schema.Resource, keys []string) {
|
||||
t.Fatalf("Error in Schema: Missing definition for \"%s\"", v)
|
||||
}
|
||||
|
||||
if s.Schema[v].Required != true {
|
||||
if !s.Schema[v].Required {
|
||||
t.Fatalf("Error in Schema: Argument \"%s\" is not required", v)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user