Skip to content

Commit c82da2c

Browse files
Linting fixes (#81)
* Refactored Create and Update within dependencytrack_team_permissions, so as to use a common function to upatePermissions. * Added named constant for SEMVER_COMPONENT_COUNT for util.go, and wrapped the error exposed by FilterPaged. * Resolved several long line lints. * Resolved linters on main.go. * Promoted uuidRegex to const within http_client.go. Moved gochecknoglobals to be ignored just on provider_test.go, rather than whole package. * Resolved godot lints. * Resolved govet lints. * Resolved grouper linter, by grouping type definitions together into a singular block within each file. * Enabled revive lints across package, and disabled the individual revive lints which were failing, to provide greater granularity. * Resolved staticcheck lints. Mostly changing Id to ID, and Acl to ACL. * Resolved unused-resolver lint within reviver. * Resolved import-shadowing lint within revive lints. * Resolved declorder lint. * Updated expected responses within TestParseSemver. Fixed potential null ptr dereference within FilterPaged, due to not checking if err is nil. * Add missing colons before id within error messages in dependencytrack_oidc_group_mapping.
1 parent c979401 commit c82da2c

Some content is hidden

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

47 files changed

+1012
-954
lines changed

.golangci.yml

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,25 @@ linters:
294294
max-open-files: 32 # Default unlimited
295295
severity: "error" # Default warning
296296
enable-all-rules: true # Default false
297-
#directives: [] # TODO
297+
directives: []
298+
rules:
299+
# Marker for Revive
300+
- name: line-length-limit
301+
arguments: [170]
302+
- name: add-constant
303+
disabled: true
304+
- name: exported
305+
disabled: true
306+
- name: comment-spacings
307+
disabled: true
308+
- name: indent-error-flow
309+
disabled: true
310+
- name: cognitive-complexity
311+
disabled: true
312+
- name: function-length
313+
disabled: true
314+
- name: cyclomatic
315+
disabled: true
298316
rowserrcheck:
299317
packages: [] # Default []
300318
sloglint:
@@ -449,57 +467,36 @@ linters:
449467
- path: internal/provider/
450468
linters:
451469
- wsl
452-
- staticcheck
453-
- revive
454470
- nlreturn
455471
- unused
456472
- ireturn
457-
- grouper
458-
- govet
459-
- godot
460473
- gocritic
461474
- goconst
462475
- funlen
463-
- gochecknoglobals
464476
- exhaustruct
465477
- err113
466478
- dupl
467-
- decorder
468479
- path: main.go
469480
linters:
470-
- revive
471481
- exhaustruct
472482
- cyclop
473-
- godot
474-
- wsl
475483
- path: go.mod
476484
linters:
477485
- gomoddirectives
478-
- path: internal/provider/config_property_data_source_test.go
479-
linters:
480-
- lll
481-
- path: internal/provider/oidc_group_mapping_resource.go
482-
linters:
483-
- lll
484486
- path: internal/provider/provider.go
485487
linters:
486-
- lll
487488
- gocyclo
488489
- cyclop
489-
- path: internal/provider/config_properties_resource_test.go
490-
linters:
491-
- lll
492-
- path: internal/provider/config_property_resource_test.go
490+
- path: internal/provider/provider_test.go
493491
linters:
494-
- lll
492+
- gochecknoglobals
495493
- path: internal/provider/project_resource.go
496494
linters:
497495
- gocyclo
498496
- cyclop
499497
- gocognit
500498
- path: internal/provider/http_client.go
501499
linters:
502-
- gocognit
503500
- wrapcheck
504501
- path: internal/provider/config_properties_resource.go
505502
linters:
@@ -511,27 +508,19 @@ linters:
511508
- gosec
512509
- path: internal/provider/util.go
513510
linters:
514-
- wrapcheck
515-
- mnd
516511
- nonamedreturns
517512
- path: internal/provider/util_test.go
518513
linters:
519514
- cyclop
520515
- path: internal/provider/team_data_source_test.go
521516
linters:
522517
- godox
523-
- path: internal/provider/team_permissions_resource.go
524-
linters:
525-
- gocognit
526518
- path: internal/provider/policy_tag_resource.go
527519
linters:
528520
- godox
529521
- path: internal/provider/team_apikey_resource_test.go
530522
linters:
531523
- godox
532-
- path: internal/provider/ldap_team_mapping_resource.go
533-
linters:
534-
- lll
535524

536525
formatters:
537526
enable:

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ provider "dependencytrack" {
3636
### Required
3737

3838
- `host` (String) URI for DependencyTrack API.
39-
- `key` (String, Sensitive) API Key for authentication to DependencyTrack. Must have permissions for all attempted actions. Set to 'OS_ENV' to read from DEPENDENCYTRACK_API_KEY environment variable.
39+
- `key` (String, Sensitive) API Key for authentication to DependencyTrack. Must have permissions for all attempted actions. Set to 'OS_ENV' to read from 'DEPENDENCYTRACK_API_KEY' environment variable.
4040

4141
### Optional
4242

internal/provider/acl_mapping_resource.go

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@ var (
2121
_ resource.ResourceWithImportState = &aclMappingResource{}
2222
)
2323

24-
func NewAclMappingResource() resource.Resource {
25-
return &aclMappingResource{}
26-
}
24+
type (
25+
aclMappingResource struct {
26+
client *dtrack.Client
27+
semver *Semver
28+
}
2729

28-
type aclMappingResource struct {
29-
client *dtrack.Client
30-
semver *Semver
31-
}
30+
aclMappingResourceModel struct {
31+
ID types.String `tfsdk:"id"`
32+
Team types.String `tfsdk:"team"`
33+
Project types.String `tfsdk:"project"`
34+
}
35+
)
3236

33-
type aclMappingResourceModel struct {
34-
ID types.String `tfsdk:"id"`
35-
Team types.String `tfsdk:"team"`
36-
Project types.String `tfsdk:"project"`
37+
func NewACLMappingResource() resource.Resource {
38+
return &aclMappingResource{}
3739
}
3840

39-
func (r *aclMappingResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
41+
func (*aclMappingResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
4042
resp.TypeName = req.ProviderTypeName + "_acl_mapping"
4143
}
4244

43-
func (r *aclMappingResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
45+
func (*aclMappingResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
4446
resp.Schema = schema.Schema{
4547
Description: "Manages an ACL mapping to grant a Team access to a Project",
4648
Attributes: map[string]schema.Attribute{
@@ -124,19 +126,19 @@ func (r *aclMappingResource) Create(ctx context.Context, req resource.CreateRequ
124126
}
125127

126128
func (r *aclMappingResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
127-
// Fetch state
129+
// Fetch state.
128130
var state aclMappingResourceModel
129131
diags := req.State.Get(ctx, &state)
130132
resp.Diagnostics.Append(diags...)
131133
if resp.Diagnostics.HasError() {
132134
return
133135
}
134-
// Refresh
135-
team, diag := TryParseUUID(state.Team, LifecycleRead, path.Root("team"))
136+
// Refresh.
137+
teamID, diag := TryParseUUID(state.Team, LifecycleRead, path.Root("team"))
136138
if diag != nil {
137139
resp.Diagnostics.Append(diag)
138140
}
139-
projectId, diag := TryParseUUID(state.Project, LifecycleRead, path.Root("project"))
141+
projectID, diag := TryParseUUID(state.Project, LifecycleRead, path.Root("project"))
140142
if diag != nil {
141143
resp.Diagnostics.Append(diag)
142144
}
@@ -146,29 +148,29 @@ func (r *aclMappingResource) Read(ctx context.Context, req resource.ReadRequest,
146148

147149
tflog.Debug(ctx, "Reading Project ACL Mapping", map[string]any{
148150
"id": state.ID.ValueString(),
149-
"team": team.String(),
150-
"project": projectId.String(),
151+
"team": teamID.String(),
152+
"project": projectID.String(),
151153
})
152154
project, err := FindPaged(func(po dtrack.PageOptions) (dtrack.Page[dtrack.Project], error) {
153-
return r.client.ACL.GetAllProjects(ctx, team, po)
155+
return r.client.ACL.GetAllProjects(ctx, teamID, po)
154156
}, func(project dtrack.Project) bool {
155-
return project.UUID == projectId
157+
return project.UUID == projectID
156158
})
157159

158160
if err != nil {
159161
resp.Diagnostics.AddError(
160162
"Unable to get ACL mapping within Read",
161-
"Error with reading acl mapping for team: "+team.String()+", and project: "+projectId.String()+", in original error: "+err.Error(),
163+
"Error with reading acl mapping for team: "+teamID.String()+", and project: "+projectID.String()+", in original error: "+err.Error(),
162164
)
163165
return
164166
}
165167
state = aclMappingResourceModel{
166-
ID: types.StringValue(fmt.Sprintf("%s/%s", team.String(), project.UUID.String())),
167-
Team: types.StringValue(team.String()),
168+
ID: types.StringValue(fmt.Sprintf("%s/%s", teamID.String(), project.UUID.String())),
169+
Team: types.StringValue(teamID.String()),
168170
Project: types.StringValue(project.UUID.String()),
169171
}
170172

171-
// Update state
173+
// Update state.
172174
diags = resp.State.Set(ctx, &state)
173175
resp.Diagnostics.Append(diags...)
174176
if resp.Diagnostics.HasError() {
@@ -181,9 +183,9 @@ func (r *aclMappingResource) Read(ctx context.Context, req resource.ReadRequest,
181183
})
182184
}
183185

184-
func (r *aclMappingResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
185-
// Nothing to Update. This resource only has Create, Delete actions
186-
// Get State
186+
func (*aclMappingResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
187+
// Nothing to Update. This resource only has Create, Delete actions.
188+
// Get State.
187189
var plan aclMappingResourceModel
188190
diags := req.Plan.Get(ctx, &plan)
189191
resp.Diagnostics.Append(diags...)
@@ -209,7 +211,7 @@ func (r *aclMappingResource) Update(ctx context.Context, req resource.UpdateRequ
209211
Project: types.StringValue(project.String()),
210212
}
211213

212-
// Update State
214+
// Update State.
213215
diags = resp.State.Set(ctx, plan)
214216
resp.Diagnostics.Append(diags...)
215217
if resp.Diagnostics.HasError() {
@@ -223,15 +225,15 @@ func (r *aclMappingResource) Update(ctx context.Context, req resource.UpdateRequ
223225
}
224226

225227
func (r *aclMappingResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
226-
// Load state
228+
// Load state.
227229
var state aclMappingResourceModel
228230
diags := req.State.Get(ctx, &state)
229231
resp.Diagnostics.Append(diags...)
230232
if resp.Diagnostics.HasError() {
231233
return
232234
}
233235

234-
// Map TF to SDK
236+
// Map TF to SDK.
235237
team, diag := TryParseUUID(state.Team, LifecycleDelete, path.Root("team"))
236238
if diag != nil {
237239
resp.Diagnostics.Append(diag)
@@ -244,7 +246,7 @@ func (r *aclMappingResource) Delete(ctx context.Context, req resource.DeleteRequ
244246
return
245247
}
246248

247-
// Execute
249+
// Execute.
248250
tflog.Debug(ctx, "Deleting Project ACL Mapping", map[string]any{
249251
"id": state.ID.ValueString(),
250252
"team": team.String(),
@@ -265,7 +267,7 @@ func (r *aclMappingResource) Delete(ctx context.Context, req resource.DeleteRequ
265267
})
266268
}
267269

268-
func (r *aclMappingResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
270+
func (*aclMappingResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
269271
idParts := strings.Split(req.ID, "/")
270272
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
271273
resp.Diagnostics.AddError(
@@ -274,28 +276,28 @@ func (r *aclMappingResource) ImportState(ctx context.Context, req resource.Impor
274276
)
275277
return
276278
}
277-
teamIdString := idParts[0]
278-
projectIdString := idParts[1]
279+
teamIDString := idParts[0]
280+
projectIDString := idParts[1]
279281
tflog.Debug(ctx, "Importing Project ACL Mapping", map[string]any{
280-
"team": teamIdString,
281-
"project": projectIdString,
282+
"team": teamIDString,
283+
"project": projectIDString,
282284
})
283285

284-
teamId, diag := TryParseUUID(types.StringValue(teamIdString), LifecycleImport, path.Root("team"))
286+
teamID, diag := TryParseUUID(types.StringValue(teamIDString), LifecycleImport, path.Root("team"))
285287
if diag != nil {
286288
resp.Diagnostics.Append(diag)
287289
}
288-
projectId, diag := TryParseUUID(types.StringValue(projectIdString), LifecycleImport, path.Root("project"))
290+
projectID, diag := TryParseUUID(types.StringValue(projectIDString), LifecycleImport, path.Root("project"))
289291
if diag != nil {
290292
resp.Diagnostics.Append(diag)
291293
}
292294
if resp.Diagnostics.HasError() {
293295
return
294296
}
295297
aclMappingState := aclMappingResourceModel{
296-
ID: types.StringValue(fmt.Sprintf("%s/%s", teamId.String(), projectId.String())),
297-
Team: types.StringValue(teamId.String()),
298-
Project: types.StringValue(projectId.String()),
298+
ID: types.StringValue(fmt.Sprintf("%s/%s", teamID.String(), projectID.String())),
299+
Team: types.StringValue(teamID.String()),
300+
Project: types.StringValue(projectID.String()),
299301
}
300302
diags := resp.State.Set(ctx, aclMappingState)
301303
resp.Diagnostics.Append(diags...)
@@ -313,7 +315,7 @@ func (r *aclMappingResource) Configure(_ context.Context, req resource.Configure
313315
if req.ProviderData == nil {
314316
return
315317
}
316-
clientInfo, ok := req.ProviderData.(clientInfo)
318+
clientInfoData, ok := req.ProviderData.(clientInfo)
317319

318320
if !ok {
319321
resp.Diagnostics.AddError(
@@ -322,6 +324,6 @@ func (r *aclMappingResource) Configure(_ context.Context, req resource.Configure
322324
)
323325
return
324326
}
325-
r.client = clientInfo.client
326-
r.semver = clientInfo.semver
327+
r.client = clientInfoData.client
328+
r.semver = clientInfoData.semver
327329
}

internal/provider/acl_mapping_resource_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func TestAccAclMappingResource(t *testing.T) {
99
resource.Test(t, resource.TestCase{
1010
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
1111
Steps: []resource.TestStep{
12-
// Create and Read testing
12+
// Create and Read testing.
1313
{
1414
Config: providerConfig + `
1515
resource "dependencytrack_project" "test" {
@@ -35,13 +35,13 @@ resource "dependencytrack_acl_mapping" "test" {
3535
),
3636
),
3737
},
38-
// ImportState testing
38+
// ImportState testing.
3939
{
4040
ResourceName: "dependencytrack_acl_mapping.test",
4141
ImportState: true,
4242
ImportStateVerify: true,
4343
},
44-
// Update and Read testing
44+
// Update and Read testing.
4545
{
4646
Config: providerConfig + `
4747
resource "dependencytrack_project" "test" {

0 commit comments

Comments
 (0)