Skip to content

Commit

Permalink
refactor: fix lints
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson committed Jul 23, 2024
1 parent 6183d09 commit 0d83811
Show file tree
Hide file tree
Showing 71 changed files with 1,091 additions and 692 deletions.
27 changes: 7 additions & 20 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
# - https://golangci-lint.run/usage/linters/

run:
allow-parallel-runners: true
timeout: 10m

linters-settings:
govet:
enable-all: true
disable:
- fieldalignment # too strict
- shadow # too strict
issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
exclude-files:
- ".*_test\\.go"

linters:
disable-all: true
enable:
- errcheck
- exportloopref
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
Expand All @@ -32,16 +32,3 @@ linters:
- unparam
- unused
- revive

issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gosimple
- ineffassign
- staticcheck
- unused
- revive
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ vet: ## Run go vet against code
go vet ./...

lint: golangci-lint ## Run golangci-lint against code
$(GOLANGCI_LINT) run -v ./...
GOPATH= GOROOT= $(GOLANGCI_LINT) run -v ./...

pre-commit-install: pre-commit ## Install pre-commit hooks
@if [ "$(GITHUB_ACTIONS)" != "true" ]; then \
Expand All @@ -58,7 +58,7 @@ BIN_DIR ?= ./bin
bin-dir:
test -d $(BIN_DIR) || mkdir $(BIN_DIR)

GOLANGCI_VERSION ?= 1.59.1
GOLANGCI_VERSION ?= 1.54.2
.PHONY: golangci-lint
golangci-lint: bin-dir
if ! test -f $(BIN_DIR)/golangci-lint-linux-amd64; then \
Expand Down
6 changes: 4 additions & 2 deletions client/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package client
import (
"fmt"

clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
clientv1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
)

// ListCloudAccounts returns a list of all cloud account summaries.
func (h *V1Client) ListCloudAccounts() ([]*models.V1CloudAccountSummary, error) {
params := clientV1.NewV1CloudAccountsListSummaryParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsListSummaryParamsWithContext(h.ctx).
WithLimit(apiutil.Ptr(int64(0)))
resp, err := h.Client.V1CloudAccountsListSummary(params)
if apiutil.Is404(err) {
Expand All @@ -20,6 +21,7 @@ func (h *V1Client) ListCloudAccounts() ([]*models.V1CloudAccountSummary, error)
return resp.Payload.Items, nil
}

// GetCloudAccount retrieves an existing cloud account summary.
func (h *V1Client) GetCloudAccount(uid string) (*models.V1CloudAccountSummary, error) {
accounts, err := h.ListCloudAccounts()
if err != nil {
Expand Down
19 changes: 12 additions & 7 deletions client/account_aws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
clientv1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
)
Expand All @@ -17,11 +17,12 @@ func toV1AwsCloudAccount(account *models.V1AwsAccount) *models.V1AwsCloudAccount
}
}

// CreateCloudAccountAws creates a new AWS cloud account.
func (h *V1Client) CreateCloudAccountAws(account *models.V1AwsAccount) (string, error) {
if err := h.validateCloudAccountAws(account); err != nil {
return "", err
}
params := clientV1.NewV1CloudAccountsAwsCreateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAwsCreateParamsWithContext(h.ctx).
WithBody(account)

resp, err := h.Client.V1CloudAccountsAwsCreate(params)
Expand All @@ -38,33 +39,36 @@ func (h *V1Client) validateCloudAccountAws(account *models.V1AwsAccount) error {
}

// validate account
params := clientV1.NewV1AwsAccountValidateParamsWithContext(h.ctx).
params := clientv1.NewV1AwsAccountValidateParamsWithContext(h.ctx).
WithAwsCloudAccount(toV1AwsCloudAccount(account))

_, err := h.Client.V1AwsAccountValidate(params)
return err
}

// UpdateCloudAccountAws updates an existing AWS cloud account.
func (h *V1Client) UpdateCloudAccountAws(account *models.V1AwsAccount) error {
if err := h.validateCloudAccountAws(account); err != nil {
return err
}
params := clientV1.NewV1CloudAccountsAwsUpdateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAwsUpdateParamsWithContext(h.ctx).
WithUID(account.Metadata.UID).
WithBody(account)
_, err := h.Client.V1CloudAccountsAwsUpdate(params)
return err
}

// DeleteCloudAccountAws deletes an existing AWS cloud account.
func (h *V1Client) DeleteCloudAccountAws(uid string) error {
params := clientV1.NewV1CloudAccountsAwsDeleteParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAwsDeleteParamsWithContext(h.ctx).
WithUID(uid)
_, err := h.Client.V1CloudAccountsAwsDelete(params)
return err
}

// GetCloudAccountAws retrieves an existing AWS cloud account.
func (h *V1Client) GetCloudAccountAws(uid string) (*models.V1AwsAccount, error) {
params := clientV1.NewV1CloudAccountsAwsGetParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAwsGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsAwsGet(params)
if apiutil.Is404(err) {
Expand All @@ -75,8 +79,9 @@ func (h *V1Client) GetCloudAccountAws(uid string) (*models.V1AwsAccount, error)
return resp.Payload, nil
}

// GetCloudAccountsAws retrieves all AWS cloud accounts.
func (h *V1Client) GetCloudAccountsAws() ([]*models.V1AwsAccount, error) {
params := clientV1.NewV1CloudAccountsAwsListParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAwsListParamsWithContext(h.ctx).
WithLimit(apiutil.Ptr(int64(0)))
resp, err := h.Client.V1CloudAccountsAwsList(params)
if err != nil {
Expand Down
19 changes: 12 additions & 7 deletions client/account_azure.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
clientv1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
)
Expand All @@ -17,13 +17,14 @@ func toV1AzureCloudAccount(account *models.V1AzureAccount) *models.V1AzureCloudA
}
}

// CreateCloudAccountAzure creates a new Azure cloud account.
func (h *V1Client) CreateCloudAccountAzure(account *models.V1AzureAccount) (string, error) {
// validate account
if err := h.validateCloudAccountAzure(account); err != nil {
return "", err
}

params := clientV1.NewV1CloudAccountsAzureCreateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAzureCreateParamsWithContext(h.ctx).
WithBody(account)
resp, err := h.Client.V1CloudAccountsAzureCreate(params)
if err != nil {
Expand All @@ -39,36 +40,39 @@ func (h *V1Client) validateCloudAccountAzure(account *models.V1AzureAccount) err
}

// validate account
params := clientV1.NewV1AzureAccountValidateParamsWithContext(h.ctx).
params := clientv1.NewV1AzureAccountValidateParamsWithContext(h.ctx).
WithAzureCloudAccount(toV1AzureCloudAccount(account))

_, err := h.Client.V1AzureAccountValidate(params)
return err
}

// UpdateCloudAccountAzure updates an existing Azure cloud account.
func (h *V1Client) UpdateCloudAccountAzure(account *models.V1AzureAccount) error {
// validate account
if err := h.validateCloudAccountAzure(account); err != nil {
return err
}

params := clientV1.NewV1CloudAccountsAzureUpdateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAzureUpdateParamsWithContext(h.ctx).
WithUID(account.Metadata.UID).
WithBody(account)

_, err := h.Client.V1CloudAccountsAzureUpdate(params)
return err
}

// DeleteCloudAccountAzure deletes an existing Azure cloud account.
func (h *V1Client) DeleteCloudAccountAzure(uid string) error {
params := clientV1.NewV1CloudAccountsAzureDeleteParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAzureDeleteParamsWithContext(h.ctx).
WithUID(uid)
_, err := h.Client.V1CloudAccountsAzureDelete(params)
return err
}

// GetCloudAccountAzure retrieves an existing Azure cloud account.
func (h *V1Client) GetCloudAccountAzure(uid string) (*models.V1AzureAccount, error) {
params := clientV1.NewV1CloudAccountsAzureGetParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAzureGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsAzureGet(params)
if apiutil.Is404(err) {
Expand All @@ -79,8 +83,9 @@ func (h *V1Client) GetCloudAccountAzure(uid string) (*models.V1AzureAccount, err
return resp.Payload, nil
}

// GetCloudAccountsAzure retrieves all Azure cloud accounts.
func (h *V1Client) GetCloudAccountsAzure() ([]*models.V1AzureAccount, error) {
params := clientV1.NewV1CloudAccountsAzureListParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsAzureListParamsWithContext(h.ctx).
WithLimit(apiutil.Ptr(int64(0)))
resp, err := h.Client.V1CloudAccountsAzureList(params)
if err != nil {
Expand Down
29 changes: 17 additions & 12 deletions client/account_custom_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package client
import (
"fmt"

clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
clientv1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
)

// CreateAccountCustomCloud creates a custom cloud account.
func (h *V1Client) CreateAccountCustomCloud(account *models.V1CustomAccountEntity, cloudType string) (string, error) {
pcgId := account.Metadata.Annotations[OverlordUID]
if err := h.CheckPCG(pcgId); err != nil {
pcgID := account.Metadata.Annotations[OverlordUID]
if err := h.CheckPCG(pcgID); err != nil {
return "", err
}
params := clientV1.NewV1CloudAccountsCustomCreateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsCustomCreateParamsWithContext(h.ctx).
WithBody(account).
WithCloudType(cloudType)
resp, err := h.Client.V1CloudAccountsCustomCreate(params)
Expand All @@ -23,8 +24,9 @@ func (h *V1Client) CreateAccountCustomCloud(account *models.V1CustomAccountEntit
return *resp.Payload.UID, nil
}

// GetCustomCloudAccount retrieves an existing custom cloud account.
func (h *V1Client) GetCustomCloudAccount(uid, cloudType string) (*models.V1CustomAccount, error) {
params := clientV1.NewV1CloudAccountsCustomGetParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsCustomGetParamsWithContext(h.ctx).
WithCloudType(cloudType).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsCustomGet(params)
Expand All @@ -34,25 +36,28 @@ func (h *V1Client) GetCustomCloudAccount(uid, cloudType string) (*models.V1Custo
return resp.Payload, nil
}

// UpdateAccountCustomCloud updates an existing custom cloud account.
func (h *V1Client) UpdateAccountCustomCloud(uid string, account *models.V1CustomAccountEntity, cloudType string) error {
params := clientV1.NewV1CloudAccountsCustomUpdateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsCustomUpdateParamsWithContext(h.ctx).
WithBody(account).
WithCloudType(cloudType).
WithUID(uid)
_, err := h.Client.V1CloudAccountsCustomUpdate(params)
return err
}

// DeleteCloudAccountCustomCloud deletes an existing custom cloud account.
func (h *V1Client) DeleteCloudAccountCustomCloud(uid, cloudType string) error {
params := clientV1.NewV1CloudAccountsCustomDeleteParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsCustomDeleteParamsWithContext(h.ctx).
WithCloudType(cloudType).
WithUID(uid)
_, err := h.Client.V1CloudAccountsCustomDelete(params)
return err
}

// ValidateCustomCloudType validates a custom cloud type.
func (h *V1Client) ValidateCustomCloudType(cloudType string) error {
params := clientV1.NewV1CustomCloudTypesGetParamsWithContext(h.ctx)
params := clientv1.NewV1CustomCloudTypesGetParamsWithContext(h.ctx)
resp, err := h.Client.V1CustomCloudTypesGet(params)
if err != nil {
return err
Expand All @@ -61,16 +66,16 @@ func (h *V1Client) ValidateCustomCloudType(cloudType string) error {
if c.Name == cloudType {
if c.IsCustom {
return nil
} else {
return fmt.Errorf("cloud - `%s` is not a valid custom cloud", cloudType)
}
return fmt.Errorf("cloud '%s' is not a valid custom cloud", cloudType)
}
}
return fmt.Errorf("cloud - `%s` is not a valid cloud", cloudType)
return fmt.Errorf("cloud '%s' is not a valid cloud", cloudType)
}

// GetCustomCloudAccountList retrieves all custom cloud accounts.
func (h *V1Client) GetCustomCloudAccountList(cloudType string) ([]*models.V1CustomAccount, error) {
params := clientV1.NewV1CloudAccountsCustomListParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsCustomListParamsWithContext(h.ctx).
WithLimit(apiutil.Ptr(int64(0))).
WithCloudType(cloudType)
resp, err := h.Client.V1CloudAccountsCustomList(params)
Expand Down
17 changes: 11 additions & 6 deletions client/account_gcp.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package client

import (
clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
clientv1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
)

// CreateCloudAccountGcp creates a new GCP cloud account.
func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity) (string, error) {
params := clientV1.NewV1CloudAccountsGcpCreateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsGcpCreateParamsWithContext(h.ctx).
WithBody(account)
resp, err := h.Client.V1CloudAccountsGcpCreate(params)
if err != nil {
Expand All @@ -16,23 +17,26 @@ func (h *V1Client) CreateCloudAccountGcp(account *models.V1GcpAccountEntity) (st
return *resp.Payload.UID, nil
}

// UpdateCloudAccountGcp updates an existing GCP cloud account.
func (h *V1Client) UpdateCloudAccountGcp(account *models.V1GcpAccountEntity) error {
params := clientV1.NewV1CloudAccountsGcpUpdateParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsGcpUpdateParamsWithContext(h.ctx).
WithUID(account.Metadata.UID).
WithBody(account)
_, err := h.Client.V1CloudAccountsGcpUpdate(params)
return err
}

// DeleteCloudAccountGcp deletes an existing GCP cloud account.
func (h *V1Client) DeleteCloudAccountGcp(uid string) error {
params := clientV1.NewV1CloudAccountsGcpDeleteParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsGcpDeleteParamsWithContext(h.ctx).
WithUID(uid)
_, err := h.Client.V1CloudAccountsGcpDelete(params)
return err
}

// GetCloudAccountGcp retrieves an existing GCP cloud account.
func (h *V1Client) GetCloudAccountGcp(uid string) (*models.V1GcpAccount, error) {
params := clientV1.NewV1CloudAccountsGcpGetParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsGcpGetParamsWithContext(h.ctx).
WithUID(uid)
resp, err := h.Client.V1CloudAccountsGcpGet(params)
if apiutil.Is404(err) {
Expand All @@ -43,8 +47,9 @@ func (h *V1Client) GetCloudAccountGcp(uid string) (*models.V1GcpAccount, error)
return resp.Payload, nil
}

// GetCloudAccountsGcp retrieves all GCP cloud accounts.
func (h *V1Client) GetCloudAccountsGcp() ([]*models.V1GcpAccount, error) {
params := clientV1.NewV1CloudAccountsGcpListParamsWithContext(h.ctx).
params := clientv1.NewV1CloudAccountsGcpListParamsWithContext(h.ctx).
WithLimit(apiutil.Ptr(int64(0)))
resp, err := h.Client.V1CloudAccountsGcpList(params)
if err != nil {
Expand Down
Loading

0 comments on commit 0d83811

Please sign in to comment.