Skip to content

Commit 2e3fd14

Browse files
chore: Update golang to 1.24, add tools usage, update libraries to recent versions, remove deprecated libraries and fix linting (#163)
## What ## Why ## Notes <!-- Add any notes here --> ## Checklist * [ ] _I have read [CONTRIBUTING.md](https://github.com/codefresh-io/terraform-provider-codefresh/blob/master/CONTRIBUTING.md)._ * [ ] _I have [allowed changes to my fork to be made](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)._ * [ ] _I have added tests, assuming new tests are warranted_. * [ ] _I understand that the `/test` comment will be ignored by the CI trigger [unless it is made by a repo admin or collaborator](https://codefresh.io/docs/docs/pipelines/triggers/git-triggers/#support-for-building-pull-requests-from-forks)._
1 parent 2945191 commit 2e3fd14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1502
-1392
lines changed

.github/workflows/pull_request.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ jobs:
1313
- name: Generate Docs
1414
run: |
1515
export PATH=$PATH:/home/runner/go/bin
16-
make docs-prepare
17-
tfplugindocs generate
16+
make docs
1817
- name: Validate No Changes
1918
run: |
2019
git diff --exit-code

GNUmakefile

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ PKG_NAME=codefresh
66
NAMESPACE=app
77
BINARY=terraform-provider-${PKG_NAME}
88
OS_ARCH=darwin_amd64
9-
TFPLUGINDOCS_VERSION=v0.14.1
109

1110
default: build
1211

13-
tools:
14-
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
15-
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
16-
GO111MODULE=on go install github.com/bflad/tfproviderlint/cmd/tfproviderlint
17-
1812
build: fmtcheck
1913
go install
2014
go build -o ${BINARY}
@@ -31,7 +25,7 @@ fmtcheck:
3125

3226
lint:
3327
@echo "==> Checking source code against linters..."
34-
golangci-lint run ./...
28+
go tool golangci-lint run ./...
3529

3630
test: fmtcheck
3731
go test -i $(TEST) || exit 1
@@ -58,13 +52,8 @@ vet:
5852
exit 1; \
5953
fi
6054

61-
docs-prepare:
62-
@echo "==> Setting up tfplugindocs..."
63-
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@${TFPLUGINDOCS_VERSION}
64-
65-
docs: docs-prepare
55+
docs:
6656
@echo "==> Generating Provider Documentation..."
67-
tfplugindocs generate
68-
69-
.PHONY: build test testacc vet fmt fmtcheck lint tools test-compile docs docs-prepare
57+
go tool tfplugindocs generate
7058

59+
.PHONY: build test testacc vet fmt fmtcheck lint test-compile docs docs-prepare

codefresh.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ steps:
1515
go_fmt:
1616
title: "Formatting"
1717
stage: test
18-
image: goreleaser/goreleaser:v1.17.0
18+
image: golang:1.24.3-alpine3.21
1919
commands:
2020
- go fmt
2121

2222
go_test:
2323
title: "Run tests"
2424
stage: test
25-
image: golang:1.18.10-alpine3.17
25+
image: golang:1.24.3-alpine3.21
2626
environment:
2727
- TF_ACC="test"
2828
- CGO_ENABLED=0
@@ -39,7 +39,7 @@ steps:
3939
# The following will resolve to their latest patch version
4040
environment:
4141
- TF_VERSION=1.3.0
42-
- TF_VERSION=1.7.0
42+
- TF_VERSION=1.11.4
4343
when:
4444
condition:
4545
all:

codefresh/cfclient/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7-
"github.com/imdario/mergo"
7+
"dario.cat/mergo"
88
)
99

1010
type DockerRegistry struct {

codefresh/cfclient/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"strings"
1010
)
@@ -71,7 +71,7 @@ func (client *Client) RequestAPI(opt *RequestOptions) ([]byte, error) {
7171
}
7272
defer resp.Body.Close()
7373

74-
body, err := ioutil.ReadAll(resp.Body)
74+
body, err := io.ReadAll(resp.Body)
7575
if err != nil {
7676
return nil, fmt.Errorf("Failed to read body %v %v", resp.StatusCode, resp.Status)
7777
}
@@ -103,7 +103,7 @@ func (client *Client) RequestApiXAccessToken(opt *RequestOptions) ([]byte, error
103103
}
104104
defer resp.Body.Close()
105105

106-
body, err := ioutil.ReadAll(resp.Body)
106+
body, err := io.ReadAll(resp.Body)
107107
if err != nil {
108108
return nil, fmt.Errorf("Failed to read body %v %v", resp.StatusCode, resp.Status)
109109
}

codefresh/cfclient/context.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import (
44
"fmt"
55
"log"
66
"net/url"
7-
8-
"golang.org/x/exp/slices"
7+
"slices"
98
)
109

1110
var encryptedContextTypes = []string{

codefresh/cfclient/current_account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66

77
"github.com/stretchr/objx"
8-
"golang.org/x/exp/slices"
8+
"slices"
99
)
1010

1111
// CurrentAccountUser spec

codefresh/cfclient/gql_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"errors"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
)
1010

@@ -38,7 +38,7 @@ func (client *Client) SendGqlRequest(request GraphQLRequest) ([]byte, error) {
3838
return nil, err
3939
}
4040
if resp.StatusCode >= 400 {
41-
bodyBytes, _ := ioutil.ReadAll(resp.Body)
41+
bodyBytes, _ := io.ReadAll(resp.Body)
4242
return nil, errors.New(resp.Status + " " + string(bodyBytes))
4343
}
4444
defer resp.Body.Close()

codefresh/cfclient/idp.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cfclient
22

33
import (
4-
"errors"
54
"fmt"
65
"log"
76
"net/url"
@@ -237,7 +236,7 @@ func (client *Client) GetIdpByName(idpName string) (*IDP, error) {
237236
}
238237
}
239238

240-
return nil, errors.New(fmt.Sprintf("[ERROR] IDP with name %s isn't found.", idpName))
239+
return nil, fmt.Errorf("[ERROR] IDP with name %s isn't found.", idpName)
241240
}
242241

243242
func (client *Client) GetIdpByID(idpID string) (*IDP, error) {
@@ -253,7 +252,7 @@ func (client *Client) GetIdpByID(idpID string) (*IDP, error) {
253252
}
254253
}
255254

256-
return nil, errors.New(fmt.Sprintf("[ERROR] IDP with ID %s isn't found.", idpID))
255+
return nil, fmt.Errorf("[ERROR] IDP with ID %s isn't found.", idpID)
257256
}
258257

259258
// get account idps
@@ -293,7 +292,7 @@ func (client *Client) GetAccountIdpByID(idpID string) (*IDP, error) {
293292
}
294293
}
295294

296-
return nil, errors.New(fmt.Sprintf("[ERROR] IDP with ID %s isn't found.", idpID))
295+
return nil, fmt.Errorf("[ERROR] IDP with ID %s isn't found.", idpID)
297296
}
298297

299298
// add account to idp

codefresh/cfclient/service_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package cfclient
22

33
import (
44
"fmt"
5-
"golang.org/x/exp/slices"
5+
"slices"
66
)
77

88
type ServiceUserTeam struct {

codefresh/cfclient/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type Variable struct {
1010
Key string `json:"key"`
1111
Value string `json:"value"`
12-
Encrypted bool `json:"encrypted",omitempty`
12+
Encrypted bool `json:"encrypted,omitempty"`
1313
}
1414

1515
// CodefreshObject codefresh interface

codefresh/data_account.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,23 @@ func mapDataAccountToResource(account *cfclient.Account, d *schema.ResourceData)
6262
}
6363
d.SetId(account.ID)
6464

65-
d.Set("_id", account.ID)
66-
d.Set("name", account.Name)
67-
d.Set("admins", account.Admins)
65+
err := d.Set("_id", account.ID)
66+
67+
if err != nil {
68+
return err
69+
}
70+
71+
err = d.Set("name", account.Name)
72+
73+
if err != nil {
74+
return err
75+
}
76+
77+
err = d.Set("admins", account.Admins)
78+
79+
if err != nil {
80+
return err
81+
}
6882

6983
return nil
7084
}

codefresh/data_account_gitops_settings.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,36 @@ func mapDataAccountGitopsSettingsToResource(account *cfclient.GitopsActiveAccoun
6868
return fmt.Errorf("cannot get gitops settings as account wasn't properly retrived")
6969
}
7070
d.SetId(account.ID)
71-
d.Set("name", account.AccountName)
72-
d.Set("admins", account.Admins)
73-
d.Set("git_provider", account.GitProvider)
74-
d.Set("git_provider_api_url", account.GitApiUrl)
75-
d.Set("shared_config_repository", account.SharedConfigRepo)
71+
72+
err := d.Set("name", account.AccountName)
73+
74+
if err != nil {
75+
return err
76+
}
77+
78+
err = d.Set("admins", account.Admins)
79+
80+
if err != nil {
81+
return err
82+
}
83+
84+
err = d.Set("git_provider", account.GitProvider)
85+
86+
if err != nil {
87+
return err
88+
}
89+
90+
err = d.Set("git_provider_api_url", account.GitApiUrl)
91+
92+
if err != nil {
93+
return err
94+
}
95+
96+
err = d.Set("shared_config_repository", account.SharedConfigRepo)
97+
98+
if err != nil {
99+
return err
100+
}
76101

77102
return nil
78103
}

codefresh/data_account_idp.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,41 @@ func dataSourceAccountIdpRead(d *schema.ResourceData, meta interface{}) error {
9090
func mapDataAccountIdpToResource(cfClientIDP cfclient.IDP, d *schema.ResourceData) error {
9191

9292
d.SetId(cfClientIDP.ID)
93-
d.Set("client_name", cfClientIDP.ClientName)
94-
d.Set("client_type", cfClientIDP.ClientType)
95-
d.Set("display_name", cfClientIDP.DisplayName)
96-
d.Set("redirect_url", cfClientIDP.RedirectUrl)
97-
d.Set("redirect_ui_url", cfClientIDP.RedirectUiUrl)
98-
d.Set("login_url", cfClientIDP.LoginUrl)
93+
err := d.Set("client_name", cfClientIDP.ClientName)
94+
95+
if err != nil {
96+
return err
97+
}
98+
99+
err = d.Set("client_type", cfClientIDP.ClientType)
100+
101+
if err != nil {
102+
return err
103+
}
104+
105+
err = d.Set("display_name", cfClientIDP.DisplayName)
106+
107+
if err != nil {
108+
return err
109+
}
110+
111+
err = d.Set("redirect_url", cfClientIDP.RedirectUrl)
112+
113+
if err != nil {
114+
return err
115+
}
116+
117+
err = d.Set("redirect_ui_url", cfClientIDP.RedirectUiUrl)
118+
119+
if err != nil {
120+
return err
121+
}
122+
123+
err = d.Set("login_url", cfClientIDP.LoginUrl)
124+
125+
if err != nil {
126+
return err
127+
}
99128

100129
return nil
101130
}

codefresh/data_context.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,28 @@ func mapDataContextToResource(context *cfclient.Context, d *schema.ResourceData)
5858
}
5959
d.SetId(context.Metadata.Name)
6060

61-
d.Set("name", context.Metadata.Name)
62-
d.Set("type", context.Spec.Type)
61+
err := d.Set("name", context.Metadata.Name)
62+
63+
if err != nil {
64+
return err
65+
}
66+
67+
err = d.Set("type", context.Spec.Type)
68+
69+
if err != nil {
70+
return err
71+
}
72+
6373
data, err := yaml.Marshal(context.Spec.Data)
6474
if err != nil {
6575
return err
6676
}
67-
d.Set("data", string(data))
77+
78+
err = d.Set("data", string(data))
79+
80+
if err != nil {
81+
return err
82+
}
6883

6984
return nil
7085
}

codefresh/data_current_account.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,17 @@ func mapDataCurrentAccountToResource(currentAccount *cfclient.CurrentAccount, d
6969
}
7070
d.SetId(currentAccount.ID)
7171

72-
d.Set("_id", currentAccount.ID)
73-
d.Set("name", currentAccount.Name)
72+
err := d.Set("_id", currentAccount.ID)
73+
74+
if err != nil {
75+
return err
76+
}
77+
78+
err = d.Set("name", currentAccount.Name)
79+
80+
if err != nil {
81+
return err
82+
}
7483

7584
// users := make(map[string](map[string]interface{}))
7685
// for n, user := range currentAccount.Users {
@@ -89,6 +98,11 @@ func mapDataCurrentAccountToResource(currentAccount *cfclient.CurrentAccount, d
8998
users[n]["id"] = user.ID
9099
}
91100

92-
d.Set("users", users)
101+
err = d.Set("users", users)
102+
103+
if err != nil {
104+
return err
105+
}
106+
93107
return nil
94108
}

0 commit comments

Comments
 (0)