From 86989767d241ac9cb5cd4dde068885f885be30ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 May 2025 07:26:30 +0000 Subject: [PATCH 1/8] Bump golangci/golangci-lint-action from 6.1.1 to 8.0.0 Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6.1.1 to 8.0.0. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/971e284b6050e8a5849b72094c50ab08da042db8...4afd733a84b1f43292c63897423277bb7f4313a9) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-version: 8.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e333873..62c5487 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: - run: go mod download - run: go build -v . - name: Run linters - uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: version: latest From 18edae3753f84061243f67933992eb71f39436c5 Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Mon, 26 May 2025 07:39:22 +0000 Subject: [PATCH 2/8] adding version to .golangci.yml --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 6301ca6..3795484 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,6 @@ # Visit https://golangci-lint.run/ for usage documentation # and information on other useful linters +version: "2" issues: max-per-linter: 0 max-same-issues: 0 From 40cbf29300bfd673b695b2dbc4ec81355dfd3c6b Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Mon, 26 May 2025 07:45:48 +0000 Subject: [PATCH 3/8] Removing outdated references --- .golangci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3795484..406dda4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,11 +2,9 @@ # and information on other useful linters version: "2" issues: - max-per-linter: 0 max-same-issues: 0 linters: - disable-all: true enable: - durationcheck - errcheck From 206acc9a5921dd0fcd974487e0f5485b9a2c15d8 Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Mon, 26 May 2025 09:11:32 +0000 Subject: [PATCH 4/8] Removing wrong linter reference --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 406dda4..2f360d4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,7 @@ linters: - copyloopvar - forcetypeassert - godot - - gofmt + - goimports - gosimple - ineffassign - makezero From 167f099192aaac082591d4dea88dab25457bc61d Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Mon, 26 May 2025 09:50:40 +0000 Subject: [PATCH 5/8] Removing goimports reference --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 2f360d4..8ad51c5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,6 @@ linters: - copyloopvar - forcetypeassert - godot - - goimports - gosimple - ineffassign - makezero From 92243a4de6805132e0a123e50f2c540ebd0879d4 Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Mon, 26 May 2025 09:57:21 +0000 Subject: [PATCH 6/8] Removing tenv and gosimple --- .golangci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8ad51c5..93ba58d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,14 +11,12 @@ linters: - copyloopvar - forcetypeassert - godot - - gosimple - ineffassign - makezero - misspell - nilerr - predeclared - staticcheck - - tenv - unconvert - unparam - unused From 813bceac045ae271c9119ba7521c896b3eb7a28f Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Mon, 26 May 2025 10:20:50 +0000 Subject: [PATCH 7/8] Lint fixes --- internal/provider/hypercore_vm_resource.go | 2 +- internal/utils/helper.go | 14 +++-- internal/utils/rest_client.go | 63 ++++++++++++++++++---- internal/utils/task_tag.go | 2 +- internal/utils/vm.go | 2 +- 5 files changed, 67 insertions(+), 16 deletions(-) diff --git a/internal/provider/hypercore_vm_resource.go b/internal/provider/hypercore_vm_resource.go index 6752229..e9d580f 100644 --- a/internal/provider/hypercore_vm_resource.go +++ b/internal/provider/hypercore_vm_resource.go @@ -640,7 +640,7 @@ func ShutdownVM(ctx context.Context, vmUUID string, restClient *utils.RestClient return err } } - var maxWaitTime int = 300 + var maxWaitTime = 300 envMaxWaitTime := os.Getenv("HC_VM_SHUTDOWN_TIMEOUT") if envMaxWaitTime != "" { val, err := strconv.Atoi(envMaxWaitTime) diff --git a/internal/utils/helper.go b/internal/utils/helper.go index 25057b1..3beea19 100644 --- a/internal/utils/helper.go +++ b/internal/utils/helper.go @@ -238,7 +238,11 @@ func ReadLocalFileBinary(filePath string) ([]byte, error) { if err != nil { return nil, fmt.Errorf("error opening file '%s': %s", filePath, err) } - defer file.Close() + defer func() { + if cerr := file.Close(); cerr != nil && err == nil { + err = fmt.Errorf("error closing file '%s': %w", filePath, cerr) + } + }() reader := bufio.NewReader(file) buffer := make([]byte, 4096) // 4KiB buffer @@ -262,7 +266,11 @@ func FetchFileBinaryFromURL(url string) ([]byte, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + err = fmt.Errorf("there was an issue closing response body with: %w", cerr) + } + }() var binaryData []byte buffer := make([]byte, 4096) // 4 KiB buffer @@ -334,7 +342,7 @@ func ValidateHTTP(httpUri string, path string) diag.Diagnostic { func RecoverDiagnostics(ctx context.Context, diags *diag.Diagnostics) { if r := recover(); r != nil { - err := fmt.Errorf("Terraform provider got an unexpected error during execution: %v", r) + err := fmt.Errorf("terraform provider got an unexpected error during execution: %v", r) *diags = append(*diags, diag.NewErrorDiagnostic("Unexpected error", err.Error())) } } diff --git a/internal/utils/rest_client.go b/internal/utils/rest_client.go index 7049d57..1395037 100644 --- a/internal/utils/rest_client.go +++ b/internal/utils/rest_client.go @@ -201,7 +201,11 @@ func (rc *RestClient) Login() { if err != nil { panic(fmt.Errorf("couldn't authenticate: %s", err.Error())) } - defer resp.Body.Close() + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() if resp.StatusCode != http.StatusOK { respBytes, _ := io.ReadAll(resp.Body) @@ -237,9 +241,13 @@ func (rc *RestClient) ListRecords(endpoint string, query map[string]any, timeout if err != nil { panic(fmt.Errorf("error making a request: %s", err.Error())) } - defer resp.Body.Close() + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() - if !(resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNoContent) { + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent { panic(fmt.Errorf("unexpected response: %d - %v", resp.StatusCode, rc.ToString(resp))) } @@ -289,7 +297,12 @@ func (rc *RestClient) CreateRecord(endpoint string, payload map[string]any, time if err != nil { return nil, resp.StatusCode, err } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() respJson := rc.ToJson(resp) if resp.StatusCode == 400 { @@ -336,7 +349,12 @@ func (rc *RestClient) CreateRecordWithList(endpoint string, payload []map[string if err != nil { return nil, resp.StatusCode, err } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() respJson := rc.ToJson(resp) if resp.StatusCode == 400 { @@ -374,7 +392,12 @@ func (rc *RestClient) UpdateRecord(endpoint string, payload map[string]any, time if err != nil { panic(fmt.Errorf("error making a request: %s", err.Error())) } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() respJson := rc.ToJson(resp) if resp.StatusCode == 400 { @@ -412,7 +435,12 @@ func (rc *RestClient) PutRecord(endpoint string, payload map[string]any, timeout if err != nil { panic(fmt.Errorf("error making a request: %s", err.Error())) } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() respJson := rc.ToJson(resp) if resp.StatusCode == 400 { @@ -451,7 +479,12 @@ func (rc *RestClient) PutBinaryRecord(endpoint string, binaryData []byte, conten if err != nil { panic(fmt.Errorf("error making a request: %s", err.Error())) } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() respJson := rc.ToJson(resp) if resp.StatusCode == 400 { @@ -490,7 +523,12 @@ func (rc *RestClient) PutBinaryRecordWithoutTaskTag(endpoint string, binaryData if err != nil { panic(fmt.Errorf("error making a request: %s", err.Error())) } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() if resp.StatusCode != 200 { panic(fmt.Errorf("error making a request: got response status code %v", resp.StatusCode)) @@ -518,7 +556,12 @@ func (rc *RestClient) DeleteRecord(endpoint string, timeout float64, ctx context if err != nil { panic(fmt.Errorf("error making a request: %s", err.Error())) } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + panic(fmt.Errorf("couldn't close response body: %s", cerr.Error())) + } + }() respJson := rc.ToJson(resp) diff --git a/internal/utils/task_tag.go b/internal/utils/task_tag.go index bd7ac22..ebfef2c 100644 --- a/internal/utils/task_tag.go +++ b/internal/utils/task_tag.go @@ -60,7 +60,7 @@ func (tt *TaskTag) WaitTask(restClient RestClient, ctx context.Context) { panic(fmt.Sprintf("Error executing task: %s, %s", state, taskStatus)) } - if !(state == "RUNNING" || state == "QUEUED") { // TaskTag has finished + if state != "RUNNING" && state != "QUEUED" { // TaskTag has finished return } } diff --git a/internal/utils/vm.go b/internal/utils/vm.go index 292cb5f..6715a87 100644 --- a/internal/utils/vm.go +++ b/internal/utils/vm.go @@ -626,7 +626,7 @@ func GetOneVM(uuid string, restClient RestClient) map[string]any { } if len(records) > 1 { // uuid == "" - panic(fmt.Errorf("Multiple VMs found: uuid=%v", uuid)) + panic(fmt.Errorf("multiple VMs found: uuid=%v", uuid)) } return records[0] From 6fac5cad1f7e885df5b1635f4d0674fa474d7f8c Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Mon, 26 May 2025 10:23:42 +0000 Subject: [PATCH 8/8] lint fixes --- .../tests/acceptance/setup/acceptance_test_env_prepare.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go b/internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go index 482a082..7861273 100644 --- a/internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go +++ b/internal/provider/tests/acceptance/setup/acceptance_test_env_prepare.go @@ -80,7 +80,12 @@ func SendHTTPRequest(client *http.Client, method string, url string, data []byte if err != nil { log.Fatalf("Sending request failed with %v", err) } - defer resp.Body.Close() + + defer func() { + if cerr := resp.Body.Close(); cerr != nil { + err = fmt.Errorf("there was an issue closing response body with: %w", cerr) + } + }() // Read and print the response body, err := io.ReadAll(resp.Body)