Skip to content

chore: Update golang to 1.24, add tools usage, update libraries to recent versions, remove deprecated libraries and fix linting #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
3 changes: 1 addition & 2 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
- name: Generate Docs
run: |
export PATH=$PATH:/home/runner/go/bin
make docs-prepare
tfplugindocs generate
make docs
- name: Validate No Changes
run: |
git diff --exit-code
Expand Down
19 changes: 4 additions & 15 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ PKG_NAME=codefresh
NAMESPACE=app
BINARY=terraform-provider-${PKG_NAME}
OS_ARCH=darwin_amd64
TFPLUGINDOCS_VERSION=v0.14.1

default: build

tools:
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
GO111MODULE=on go install github.com/bflad/tfproviderlint/cmd/tfproviderlint

build: fmtcheck
go install
go build -o ${BINARY}
Expand All @@ -31,7 +25,7 @@ fmtcheck:

lint:
@echo "==> Checking source code against linters..."
golangci-lint run ./...
go tool golangci-lint run ./...

test: fmtcheck
go test -i $(TEST) || exit 1
Expand All @@ -58,13 +52,8 @@ vet:
exit 1; \
fi

docs-prepare:
@echo "==> Setting up tfplugindocs..."
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@${TFPLUGINDOCS_VERSION}

docs: docs-prepare
docs:
@echo "==> Generating Provider Documentation..."
tfplugindocs generate

.PHONY: build test testacc vet fmt fmtcheck lint tools test-compile docs docs-prepare
go tool tfplugindocs generate

.PHONY: build test testacc vet fmt fmtcheck lint test-compile docs docs-prepare
6 changes: 3 additions & 3 deletions codefresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ steps:
go_fmt:
title: "Formatting"
stage: test
image: goreleaser/goreleaser:v1.17.0
image: golang:1.24.3-alpine3.21
commands:
- go fmt

go_test:
title: "Run tests"
stage: test
image: golang:1.18.10-alpine3.17
image: golang:1.24.3-alpine3.21
environment:
- TF_ACC="test"
- CGO_ENABLED=0
Expand All @@ -39,7 +39,7 @@ steps:
# The following will resolve to their latest patch version
environment:
- TF_VERSION=1.3.0
- TF_VERSION=1.7.0
- TF_VERSION=1.11.4
when:
condition:
all:
Expand Down
2 changes: 1 addition & 1 deletion codefresh/cfclient/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/imdario/mergo"
"dario.cat/mergo"
)

type DockerRegistry struct {
Expand Down
6 changes: 3 additions & 3 deletions codefresh/cfclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
)
Expand Down Expand Up @@ -71,7 +71,7 @@ func (client *Client) RequestAPI(opt *RequestOptions) ([]byte, error) {
}
defer resp.Body.Close()

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

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Failed to read body %v %v", resp.StatusCode, resp.Status)
}
Expand Down
3 changes: 1 addition & 2 deletions codefresh/cfclient/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"fmt"
"log"
"net/url"

"golang.org/x/exp/slices"
"slices"
)

var encryptedContextTypes = []string{
Expand Down
2 changes: 1 addition & 1 deletion codefresh/cfclient/current_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/stretchr/objx"
"golang.org/x/exp/slices"
"slices"
)

// CurrentAccountUser spec
Expand Down
4 changes: 2 additions & 2 deletions codefresh/cfclient/gql_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -38,7 +38,7 @@ func (client *Client) SendGqlRequest(request GraphQLRequest) ([]byte, error) {
return nil, err
}
if resp.StatusCode >= 400 {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyBytes, _ := io.ReadAll(resp.Body)
return nil, errors.New(resp.Status + " " + string(bodyBytes))
}
defer resp.Body.Close()
Expand Down
7 changes: 3 additions & 4 deletions codefresh/cfclient/idp.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cfclient

import (
"errors"
"fmt"
"log"
"net/url"
Expand Down Expand Up @@ -237,7 +236,7 @@ func (client *Client) GetIdpByName(idpName string) (*IDP, error) {
}
}

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

func (client *Client) GetIdpByID(idpID string) (*IDP, error) {
Expand All @@ -253,7 +252,7 @@ func (client *Client) GetIdpByID(idpID string) (*IDP, error) {
}
}

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

// get account idps
Expand Down Expand Up @@ -293,7 +292,7 @@ func (client *Client) GetAccountIdpByID(idpID string) (*IDP, error) {
}
}

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

// add account to idp
Expand Down
2 changes: 1 addition & 1 deletion codefresh/cfclient/service_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cfclient

import (
"fmt"
"golang.org/x/exp/slices"
"slices"
)

type ServiceUserTeam struct {
Expand Down
2 changes: 1 addition & 1 deletion codefresh/cfclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Variable struct {
Key string `json:"key"`
Value string `json:"value"`
Encrypted bool `json:"encrypted",omitempty`
Encrypted bool `json:"encrypted,omitempty"`
}

// CodefreshObject codefresh interface
Expand Down
20 changes: 17 additions & 3 deletions codefresh/data_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,23 @@ func mapDataAccountToResource(account *cfclient.Account, d *schema.ResourceData)
}
d.SetId(account.ID)

d.Set("_id", account.ID)
d.Set("name", account.Name)
d.Set("admins", account.Admins)
err := d.Set("_id", account.ID)

if err != nil {
return err
}

err = d.Set("name", account.Name)

if err != nil {
return err
}

err = d.Set("admins", account.Admins)

if err != nil {
return err
}

return nil
}
35 changes: 30 additions & 5 deletions codefresh/data_account_gitops_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,36 @@ func mapDataAccountGitopsSettingsToResource(account *cfclient.GitopsActiveAccoun
return fmt.Errorf("cannot get gitops settings as account wasn't properly retrived")
}
d.SetId(account.ID)
d.Set("name", account.AccountName)
d.Set("admins", account.Admins)
d.Set("git_provider", account.GitProvider)
d.Set("git_provider_api_url", account.GitApiUrl)
d.Set("shared_config_repository", account.SharedConfigRepo)

err := d.Set("name", account.AccountName)

if err != nil {
return err
}

err = d.Set("admins", account.Admins)

if err != nil {
return err
}

err = d.Set("git_provider", account.GitProvider)

if err != nil {
return err
}

err = d.Set("git_provider_api_url", account.GitApiUrl)

if err != nil {
return err
}

err = d.Set("shared_config_repository", account.SharedConfigRepo)

if err != nil {
return err
}

return nil
}
41 changes: 35 additions & 6 deletions codefresh/data_account_idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,41 @@ func dataSourceAccountIdpRead(d *schema.ResourceData, meta interface{}) error {
func mapDataAccountIdpToResource(cfClientIDP cfclient.IDP, d *schema.ResourceData) error {

d.SetId(cfClientIDP.ID)
d.Set("client_name", cfClientIDP.ClientName)
d.Set("client_type", cfClientIDP.ClientType)
d.Set("display_name", cfClientIDP.DisplayName)
d.Set("redirect_url", cfClientIDP.RedirectUrl)
d.Set("redirect_ui_url", cfClientIDP.RedirectUiUrl)
d.Set("login_url", cfClientIDP.LoginUrl)
err := d.Set("client_name", cfClientIDP.ClientName)

if err != nil {
return err
}

err = d.Set("client_type", cfClientIDP.ClientType)

if err != nil {
return err
}

err = d.Set("display_name", cfClientIDP.DisplayName)

if err != nil {
return err
}

err = d.Set("redirect_url", cfClientIDP.RedirectUrl)

if err != nil {
return err
}

err = d.Set("redirect_ui_url", cfClientIDP.RedirectUiUrl)

if err != nil {
return err
}

err = d.Set("login_url", cfClientIDP.LoginUrl)

if err != nil {
return err
}

return nil
}
21 changes: 18 additions & 3 deletions codefresh/data_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,28 @@ func mapDataContextToResource(context *cfclient.Context, d *schema.ResourceData)
}
d.SetId(context.Metadata.Name)

d.Set("name", context.Metadata.Name)
d.Set("type", context.Spec.Type)
err := d.Set("name", context.Metadata.Name)

if err != nil {
return err
}

err = d.Set("type", context.Spec.Type)

if err != nil {
return err
}

data, err := yaml.Marshal(context.Spec.Data)
if err != nil {
return err
}
d.Set("data", string(data))

err = d.Set("data", string(data))

if err != nil {
return err
}

return nil
}
20 changes: 17 additions & 3 deletions codefresh/data_current_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ func mapDataCurrentAccountToResource(currentAccount *cfclient.CurrentAccount, d
}
d.SetId(currentAccount.ID)

d.Set("_id", currentAccount.ID)
d.Set("name", currentAccount.Name)
err := d.Set("_id", currentAccount.ID)

if err != nil {
return err
}

err = d.Set("name", currentAccount.Name)

if err != nil {
return err
}

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

d.Set("users", users)
err = d.Set("users", users)

if err != nil {
return err
}

return nil
}
Loading
Loading