Skip to content

Commit 26b0377

Browse files
committed
fix(lint): solve linting issues
1 parent 43e7747 commit 26b0377

File tree

212 files changed

+3227
-2830
lines changed

Some content is hidden

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

212 files changed

+3227
-2830
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.DS_Store
44
.envrc
55
.env
6+
.direnv/
67
example.tf
78
terraform.tfplan
89
terraform.tfstate

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/hashicorp/terraform-plugin-log v0.8.0
1313
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
1414
github.com/jmespath/go-jmespath v0.4.0
15-
github.com/pkg/errors v0.9.1
1615
github.com/rs/zerolog v1.29.1
1716
github.com/spf13/cast v1.5.1
1817
github.com/stretchr/testify v1.8.4
@@ -63,6 +62,7 @@ require (
6362
github.com/oklog/run v1.0.0 // indirect
6463
github.com/opencontainers/go-digest v1.0.0 // indirect
6564
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
65+
github.com/pkg/errors v0.9.1 // indirect
6666
github.com/pmezard/go-difflib v1.0.0 // indirect
6767
github.com/sirupsen/logrus v1.9.3 // indirect
6868
github.com/sysdiglabs/agent-kilt/pkg v0.0.0-20240201123620-2272de6dee9f // indirect

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package main
22

33
import (
4+
"log/slog"
5+
46
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
57

68
"github.com/draios/terraform-provider-sysdig/sysdig"
79
)
810

911
func main() {
1012
sysdigClient := sysdig.NewSysdigClients()
11-
defer sysdigClient.Close()
13+
defer func() {
14+
err := sysdigClient.Close()
15+
if err != nil {
16+
slog.Default().Error("error closing the provider", "error", err)
17+
}
18+
}()
1219

1320
provider := &sysdig.SysdigProvider{SysdigClient: sysdigClient}
1421
plugin.Serve(&plugin.ServeOpts{ProviderFunc: provider.Provider})

scripts/oanc/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ func main() {
9898
if err != nil {
9999
log.Fatal(err)
100100
}
101-
defer response.Body.Close()
101+
defer func() {
102+
err := response.Body.Close()
103+
if err != nil {
104+
log.Fatalf("error closing response body: %s", err)
105+
}
106+
}()
102107

103108
if response.StatusCode != http.StatusOK {
104109
log.Fatal(errors.New(response.Status))

sysdig/cfn_preprocess_template.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/*
2-
This file contains definition for the following functions.
3-
4-
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.
5-
6-
GetValueFromTemplate is used to obtain key, value information from JSON object
7-
*/
8-
91
package sysdig
102

113
import (
@@ -39,7 +31,7 @@ func capitalize(key string) string {
3931
return string(r)
4032
}
4133

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

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

10698
err = container.Delete("name")
@@ -115,22 +107,22 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
115107
name, _ := env.S("name").Data().(string)
116108
err = env.Delete("name")
117109
if err != nil {
118-
return nil, fmt.Errorf("Could not delete \"name\" key in Environment: %v", err)
110+
return nil, fmt.Errorf("could not delete \"name\" key in Environment: %v", err)
119111
}
120112
_, err = env.Set(name, "Name")
121113
if err != nil {
122-
return nil, fmt.Errorf("Could not assign \"Name\" key in Environment: %v", err)
114+
return nil, fmt.Errorf("could not assign \"Name\" key in Environment: %v", err)
123115
}
124116
}
125117
if env.Exists("value") {
126118
value, _ := env.S("value").Data().(string)
127119
err = env.Delete("value")
128120
if err != nil {
129-
return nil, fmt.Errorf("Could not delete \"value\" key in Environment: %v", err)
121+
return nil, fmt.Errorf("could not delete \"value\" key in Environment: %v", err)
130122
}
131123
_, err = env.Set(value, "Value")
132124
if err != nil {
133-
return nil, fmt.Errorf("Could not assign \"Value\" key in Environment: %v", err)
125+
return nil, fmt.Errorf("could not assign \"Value\" key in Environment: %v", err)
134126
}
135127
}
136128
}
@@ -139,7 +131,7 @@ func terraformPreModifications(ctx context.Context, patchedStack []byte) ([]byte
139131
parsedPassthrough, _ := gabs.ParseJSON([]byte(passthrough))
140132
_, err = container.Set(parsedPassthrough, "Environment")
141133
if err != nil {
142-
return nil, fmt.Errorf("Could not update Environment field: %v", err)
134+
return nil, fmt.Errorf("could not update Environment field: %v", err)
143135
}
144136

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

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

173165
err = container.Delete("command")

sysdig/common.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555
SchemaRoleKey = "role"
5656
SchemaSystemRoleKey = "system_role"
5757
SchemaRulesKey = "rules"
58-
SchemaApiKeyKey = "api_key"
58+
SchemaAPIKeyKey = "api_key"
5959
SchemaPermissionsKey = "permissions"
6060
SchemaMonitorPermKey = "monitor_permissions"
6161
SchemaSecurePermKey = "secure_permissions"
@@ -79,10 +79,10 @@ const (
7979
SchemaEnabled = "enabled"
8080
SchemaComponents = "components"
8181
SchemaComponent = "component"
82-
SchemaCloudProviderId = "provider_id"
82+
SchemaCloudProviderID = "provider_id"
8383
SchemaCloudProviderType = "provider_type"
8484
SchemaFeature = "feature"
85-
SchemaManagementAccountId = "management_account_id"
85+
SchemaManagementAccountID = "management_account_id"
8686
SchemaOrganizationIDKey = "organization_id"
8787
SchemaOrganizationalUnitIds = "organizational_unit_ids"
8888
SchemaIncludedOrganizationalGroups = "included_organizational_groups"
@@ -91,9 +91,9 @@ const (
9191
SchemaExcludedCloudAccounts = "excluded_cloud_accounts"
9292
SchemaOrganizationRootID = "organization_root_id"
9393
SchemaAutomaticOnboarding = "automatic_onboarding"
94-
SchemaCloudProviderTenantId = "provider_tenant_id"
94+
SchemaCloudProviderTenantID = "provider_tenant_id"
9595
SchemaCloudProviderAlias = "provider_alias"
96-
SchemaAccountId = "account_id"
96+
SchemaAccountID = "account_id"
9797
SchemaFeatureFlags = "flags"
9898
SchemaProviderPartition = "provider_partition"
9999
)

sysdig/data_source_agent_access_keys.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ func dataSourceSysdigAgentAccessKey() *schema.Resource {
6161
}
6262

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

70-
agentKeyId := d.Get("id").(int)
71-
agentAccessKey, err := client.GetAgentAccessKeyByID(ctx, strconv.Itoa(agentKeyId))
70+
agentKeyID := d.Get("id").(int)
71+
agentAccessKey, err := client.GetAgentAccessKeyByID(ctx, strconv.Itoa(agentKeyID))
7272
if err != nil {
7373
return diag.FromErr(err)
7474
}

sysdig/data_source_sysdig_current_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func dataSourceSysdigCurrentUser() *schema.Resource {
4141
}
4242

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

sysdig/data_source_sysdig_custom_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func dataSourceSysdigCustomRole() *schema.Resource {
4646
}
4747
}
4848

49-
func dataSourceSysdigCustomRoleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
49+
func dataSourceSysdigCustomRoleRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
5050
client, err := m.(SysdigClients).sysdigCommonClientV2()
5151
if err != nil {
5252
return diag.FromErr(err)

sysdig/data_source_sysdig_custom_role_permissions_common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ func dataSourceSysdigCustomRoleSchema() map[string]*schema.Schema {
3131
}
3232

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

4141
rps := readPermissions(rp)
4242
dependencies, err := client.GetPermissionsDependencies(ctx, product, rps)
@@ -57,7 +57,7 @@ func getDataSourceSysdigCustomRoleMonitorPermissionsRead(product v2.Product) sch
5757
}
5858
}
5959

60-
func readPermissions(rp []interface{}) []string {
60+
func readPermissions(rp []any) []string {
6161
permissions := make([]string, len(rp))
6262
for i, permission := range rp {
6363
permissions[i] = permission.(string)

0 commit comments

Comments
 (0)