Skip to content

fix(lint): solve linting issues #649

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 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
args: --timeout 30m --build-tags unit,tf_acc_sysdig_monitor,tf_acc_sysdig_secure,tf_acc_ibm_monitor,tf_acc_ibm_secure
args: --timeout 30m

test:
name: Unit Tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store
.envrc
.env
.direnv/
example.tf
terraform.tfplan
terraform.tfstate
Expand Down
7 changes: 3 additions & 4 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
SWEEP?=us-east-1,us-west-2
TEST?=./...
TEST_SUITE?=tf_acc_sysdig_monitor,tf_acc_sysdig_secure
PKG_NAME=sysdig
WEBSITE_REPO=github.com/hashicorp/terraform-website
VERSION=$(shell [ ! -z `git tag -l --contains HEAD` ] && git tag -l --contains HEAD || git rev-parse --short HEAD)
Expand Down Expand Up @@ -35,14 +34,14 @@ sweep:
go test $(TEST) -v -sweep=$(SWEEP) $(SWEEPARGS)

test: fmtcheck
go test $(TEST) -tags=unit -timeout=30s -parallel=4
go test $(TEST) -timeout=30s -parallel=4

testacc: fmtcheck
CGO_ENABLED=1 TF_ACC=1 go test $(TEST) -v $(TESTARGS) -tags=$(TEST_SUITE) -timeout 120m -race -parallel=1
CGO_ENABLED=1 TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -race -parallel=1

junit-report: fmtcheck
@go install github.com/jstemmer/go-junit-report/v2@latest
CGO_ENABLED=1 TF_ACC=1 TF_LOG=DEBUG go test $(TEST) -v $(TESTARGS) -tags=$(TEST_SUITE) -timeout 120m -race -parallel=1 2>&1 | tee output.txt
CGO_ENABLED=1 TF_ACC=1 TF_LOG=DEBUG go test $(TEST) -v $(TESTARGS) -timeout 120m -race -parallel=1 2>&1 | tee output.txt
! grep -q "\[build failed\]" output.txt
go-junit-report -in output.txt -out junit-report.xml

Expand Down
2 changes: 0 additions & 2 deletions buildinfo/ibm_monitor.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_ibm_monitor

package buildinfo

func init() {
Expand Down
2 changes: 0 additions & 2 deletions buildinfo/ibm_secure.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_ibm_secure

package buildinfo

func init() {
Expand Down
2 changes: 0 additions & 2 deletions buildinfo/onprem_monitor.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_onprem_monitor

package buildinfo

func init() {
Expand Down
2 changes: 0 additions & 2 deletions buildinfo/onprem_secure.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_onprem_secure

package buildinfo

func init() {
Expand Down
2 changes: 0 additions & 2 deletions buildinfo/sysdig_monitor.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_sysdig_monitor

package buildinfo

func init() {
Expand Down
2 changes: 0 additions & 2 deletions buildinfo/sysdig_secure.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_sysdig_secure

package buildinfo

func init() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/hashicorp/terraform-plugin-log v0.8.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/jmespath/go-jmespath v0.4.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.29.1
github.com/spf13/cast v1.5.1
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -63,6 +62,7 @@ require (
github.com/oklog/run v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sysdiglabs/agent-kilt/pkg v0.0.0-20240201123620-2272de6dee9f // indirect
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package main

import (
"log/slog"

"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"

"github.com/draios/terraform-provider-sysdig/sysdig"
)

func main() {
sysdigClient := sysdig.NewSysdigClients()
defer sysdigClient.Close()
defer func() {
err := sysdigClient.Close()
if err != nil {
slog.Default().Error("error closing the provider", "error", err)
}
}()

provider := &sysdig.SysdigProvider{SysdigClient: sysdigClient}
plugin.Serve(&plugin.ServeOpts{ProviderFunc: provider.Provider})
Expand Down
7 changes: 6 additions & 1 deletion scripts/oanc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ func main() {
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
defer func() {
err := response.Body.Close()
if err != nil {
log.Fatalf("error closing response body: %s", err)
}
}()

if response.StatusCode != http.StatusOK {
log.Fatal(errors.New(response.Status))
Expand Down
28 changes: 10 additions & 18 deletions sysdig/cfn_preprocess_template.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*
This file contains definition for the following functions.

terraformPreModifications is used to modify the container definitions passed to the cfn patcher such that it modifies casing issues in any ECS json content so that it can be processed by the kilt patcher.

GetValueFromTemplate is used to obtain key, value information from JSON object
*/

package sysdig

import (
Expand Down Expand Up @@ -39,7 +31,7 @@ func capitalize(key string) string {
return string(r)
}

// updateKey recursively capitalizes the first letter of each key in the input object
// updateKeys recursively capitalizes the first letter of each key in the input object
func updateKeys(inputMap gabs.Container) error {
// in this case, the object is probably an array, so update each child
if len(inputMap.ChildrenMap()) == 0 {
Expand Down Expand Up @@ -87,7 +79,7 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
passthrough, _ := GetValueFromTemplate(container.S("image"))
_, err = container.Set(passthrough, "Image")
if err != nil {
return nil, fmt.Errorf("Could not update Image field: %v", err)
return nil, fmt.Errorf("could not update Image field: %v", err)
}

err = container.Delete("image")
Expand All @@ -100,7 +92,7 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
passthrough, _ := GetValueFromTemplate(container.S("name"))
_, err = container.Set(passthrough, "Name")
if err != nil {
return nil, fmt.Errorf("Could not update Name field: %v", err)
return nil, fmt.Errorf("could not update Name field: %v", err)
}

err = container.Delete("name")
Expand All @@ -115,22 +107,22 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
name, _ := env.S("name").Data().(string)
err = env.Delete("name")
if err != nil {
return nil, fmt.Errorf("Could not delete \"name\" key in Environment: %v", err)
return nil, fmt.Errorf("could not delete \"name\" key in Environment: %v", err)
}
_, err = env.Set(name, "Name")
if err != nil {
return nil, fmt.Errorf("Could not assign \"Name\" key in Environment: %v", err)
return nil, fmt.Errorf("could not assign \"Name\" key in Environment: %v", err)
}
}
if env.Exists("value") {
value, _ := env.S("value").Data().(string)
err = env.Delete("value")
if err != nil {
return nil, fmt.Errorf("Could not delete \"value\" key in Environment: %v", err)
return nil, fmt.Errorf("could not delete \"value\" key in Environment: %v", err)
}
_, err = env.Set(value, "Value")
if err != nil {
return nil, fmt.Errorf("Could not assign \"Value\" key in Environment: %v", err)
return nil, fmt.Errorf("could not assign \"Value\" key in Environment: %v", err)
}
}
}
Expand All @@ -139,7 +131,7 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
parsedPassthrough, _ := gabs.ParseJSON([]byte(passthrough))
_, err = container.Set(parsedPassthrough, "Environment")
if err != nil {
return nil, fmt.Errorf("Could not update Environment field: %v", err)
return nil, fmt.Errorf("could not update Environment field: %v", err)
}

err = container.Delete("environment")
Expand All @@ -153,7 +145,7 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
parsedPassthrough, _ := gabs.ParseJSON([]byte(passthrough))
_, err = container.Set(parsedPassthrough, "EntryPoint")
if err != nil {
return nil, fmt.Errorf("Could not update EntryPoint field: %v", err)
return nil, fmt.Errorf("could not update EntryPoint field: %v", err)
}

err = container.Delete("entryPoint")
Expand All @@ -167,7 +159,7 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
parsedPassthrough, _ := gabs.ParseJSON([]byte(passthrough))
_, err = container.Set(parsedPassthrough, "Command")
if err != nil {
return nil, fmt.Errorf("Could not update Command field: %v", err)
return nil, fmt.Errorf("could not update Command field: %v", err)
}

err = container.Delete("command")
Expand Down
10 changes: 5 additions & 5 deletions sysdig/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (
SchemaRoleKey = "role"
SchemaSystemRoleKey = "system_role"
SchemaRulesKey = "rules"
SchemaApiKeyKey = "api_key"
SchemaAPIKeyKey = "api_key"
SchemaPermissionsKey = "permissions"
SchemaMonitorPermKey = "monitor_permissions"
SchemaSecurePermKey = "secure_permissions"
Expand All @@ -79,10 +79,10 @@ const (
SchemaEnabled = "enabled"
SchemaComponents = "components"
SchemaComponent = "component"
SchemaCloudProviderId = "provider_id"
SchemaCloudProviderID = "provider_id"
SchemaCloudProviderType = "provider_type"
SchemaFeature = "feature"
SchemaManagementAccountId = "management_account_id"
SchemaManagementAccountID = "management_account_id"
SchemaOrganizationIDKey = "organization_id"
SchemaOrganizationalUnitIds = "organizational_unit_ids"
SchemaIncludedOrganizationalGroups = "included_organizational_groups"
Expand All @@ -91,9 +91,9 @@ const (
SchemaExcludedCloudAccounts = "excluded_cloud_accounts"
SchemaOrganizationRootID = "organization_root_id"
SchemaAutomaticOnboarding = "automatic_onboarding"
SchemaCloudProviderTenantId = "provider_tenant_id"
SchemaCloudProviderTenantID = "provider_tenant_id"
SchemaCloudProviderAlias = "provider_alias"
SchemaAccountId = "account_id"
SchemaAccountID = "account_id"
SchemaFeatureFlags = "flags"
SchemaProviderPartition = "provider_partition"
)
6 changes: 3 additions & 3 deletions sysdig/data_source_agent_access_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ func dataSourceSysdigAgentAccessKey() *schema.Resource {
}

// Retrieves the information of a resource form the file and loads it in Terraform
func dataSourceSysdigAgentAccessKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func dataSourceSysdigAgentAccessKeyRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
client, err := meta.(SysdigClients).commonClientV2()
if err != nil {
return diag.FromErr(err)
}

agentKeyId := d.Get("id").(int)
agentAccessKey, err := client.GetAgentAccessKeyByID(ctx, strconv.Itoa(agentKeyId))
agentKeyID := d.Get("id").(int)
agentAccessKey, err := client.GetAgentAccessKeyByID(ctx, strconv.Itoa(agentKeyID))
if err != nil {
return diag.FromErr(err)
}
Expand Down
2 changes: 0 additions & 2 deletions sysdig/data_source_agent_access_keys_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_secure

package sysdig_test

import (
Expand Down
2 changes: 1 addition & 1 deletion sysdig/data_source_sysdig_current_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func dataSourceSysdigCurrentUser() *schema.Resource {
}

// Retrieves the information of a resource form the file and loads it in Terraform
func dataSourceSysdigCurrentUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func dataSourceSysdigCurrentUserRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
client, err := meta.(SysdigClients).commonClientV2()
if err != nil {
return diag.FromErr(err)
Expand Down
2 changes: 0 additions & 2 deletions sysdig/data_source_sysdig_current_user_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_secure || tf_acc_ibm_monitor || tf_acc_onprem_monitor || tf_acc_onprem_secure

package sysdig_test

import (
Expand Down
2 changes: 1 addition & 1 deletion sysdig/data_source_sysdig_custom_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func dataSourceSysdigCustomRole() *schema.Resource {
}
}

func dataSourceSysdigCustomRoleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func dataSourceSysdigCustomRoleRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
client, err := m.(SysdigClients).sysdigCommonClientV2()
if err != nil {
return diag.FromErr(err)
Expand Down
6 changes: 3 additions & 3 deletions sysdig/data_source_sysdig_custom_role_permissions_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func dataSourceSysdigCustomRoleSchema() map[string]*schema.Schema {
}

func getDataSourceSysdigCustomRoleMonitorPermissionsRead(product v2.Product) schema.ReadContextFunc {
return func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
return func(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
client, err := m.(SysdigClients).sysdigCommonClientV2()
if err != nil {
return diag.FromErr(err)
}
rp := d.Get(SchemaRequestedPermKey).([]interface{})
rp := d.Get(SchemaRequestedPermKey).([]any)

rps := readPermissions(rp)
dependencies, err := client.GetPermissionsDependencies(ctx, product, rps)
Expand All @@ -57,7 +57,7 @@ func getDataSourceSysdigCustomRoleMonitorPermissionsRead(product v2.Product) sch
}
}

func readPermissions(rp []interface{}) []string {
func readPermissions(rp []any) []string {
permissions := make([]string, len(rp))
for i, permission := range rp {
permissions[i] = permission.(string)
Expand Down
2 changes: 0 additions & 2 deletions sysdig/data_source_sysdig_custom_role_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_secure || tf_acc_onprem_monitor || tf_acc_onprem_secure

package sysdig_test

import (
Expand Down
Loading
Loading