Skip to content

Commit 3fb519f

Browse files
UUID Parsing Errors / Release 1.12.1 (#78)
* Standardised log error reporting. Identified a couple issues and fixed. Updated CHANGELOG. * Added check within TryParseUUID for a value being null. Added further fix to CHANGELOG. * Removed Built provider binary, and added to .gitignore.
1 parent 07e8248 commit 3fb519f

19 files changed

+308
-535
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ website/vendor
3333

3434
# Keep windows files with windows line endings
3535
*.winfile eol=crlf
36+
37+
terraform-provider-dependencytrack

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 1.12.1
2+
3+
#### FIXES
4+
- Within Update `comment` on `dependencytrack_team_apikey` was not being written back to state using return value from DependencyTrack.
5+
- Within Create, Update, the permission list was assigned from a `dtrack.Team`, which may have been `nil`.
6+
- Within Import, `dependencytrack_acl_mapping` would still write to state if unable regardless of whether UUIDs parsed successfully.
7+
8+
#### MISC
9+
- Standardised log error reporting when failing to parse a `UUID`.
10+
111
## 1.12.0
212

313
#### FEATURES
@@ -11,6 +21,9 @@
1121
#### FEATURES
1222
- Add `dependencytrack_acl_mapping` resource to manage Portfolio Access Control for Projects.
1323

24+
#### ISSUES
25+
- [Fixed in `1.12.1`] Import of `dependencytrack_acl_mapping` would import regardless of whether UUIDs parsed successfully.
26+
1427
#### DEPENDENCIES
1528
- `github.com/DependencyTrack/client-go` `0.16.0` -> `main`
1629

@@ -63,6 +76,9 @@
6376
#### FEATURES
6477
- Add `dependencytrack_team_permissions` resource to canonically manage the permissions assigned to a Team.
6578

79+
#### ISSUES
80+
- [Fixed in `1.12.1`] Permission list is assigned from a potentially `nil` `dtrack.Team`.
81+
6682
#### MISC
6783
- Remove deprecated field from within `golangci` config file for `goconst`.
6884

internal/provider/acl_mapping_resource.go

Lines changed: 35 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"strings"
77

8-
"github.com/google/uuid"
9-
108
dtrack "github.com/DependencyTrack/client-go"
119
"github.com/hashicorp/terraform-plugin-framework/path"
1210
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -78,21 +76,13 @@ func (r *aclMappingResource) Create(ctx context.Context, req resource.CreateRequ
7876
if resp.Diagnostics.HasError() {
7977
return
8078
}
81-
team, err := uuid.Parse(plan.Team.ValueString())
82-
if err != nil {
83-
resp.Diagnostics.AddAttributeError(
84-
path.Root("team"),
85-
"Within Create, unable to parse team into UUID",
86-
"Error from: "+err.Error(),
87-
)
79+
team, diag := TryParseUUID(plan.Team, LifecycleCreate, path.Root("team"))
80+
if diag != nil {
81+
resp.Diagnostics.Append(diag)
8882
}
89-
project, err := uuid.Parse(plan.Project.ValueString())
90-
if err != nil {
91-
resp.Diagnostics.AddAttributeError(
92-
path.Root("project"),
93-
"Within Create, unable to parse project into UUID",
94-
"Error from: "+err.Error(),
95-
)
83+
project, diag := TryParseUUID(plan.Project, LifecycleCreate, path.Root("project"))
84+
if diag != nil {
85+
resp.Diagnostics.Append(diag)
9686
}
9787
if resp.Diagnostics.HasError() {
9888
return
@@ -103,7 +93,7 @@ func (r *aclMappingResource) Create(ctx context.Context, req resource.CreateRequ
10393
Project: project,
10494
}
10595
tflog.Debug(ctx, "Granting ACL for project "+mappingReq.Project.String()+" to team "+mappingReq.Team.String())
106-
err = r.client.ACL.AddProjectMapping(ctx, mappingReq)
96+
err := r.client.ACL.AddProjectMapping(ctx, mappingReq)
10797

10898
if err != nil {
10999
resp.Diagnostics.AddError(
@@ -137,21 +127,13 @@ func (r *aclMappingResource) Read(ctx context.Context, req resource.ReadRequest,
137127
tflog.Debug(ctx, "Refreshing acl mapping for team: "+state.Team.ValueString()+", and project: "+state.Project.ValueString())
138128

139129
// Refresh
140-
team, err := uuid.Parse(state.Team.ValueString())
141-
if err != nil {
142-
resp.Diagnostics.AddAttributeError(
143-
path.Root("team"),
144-
"Within Read, unable to parse team into UUID",
145-
"Error from: "+err.Error(),
146-
)
130+
team, diag := TryParseUUID(state.Team, LifecycleRead, path.Root("team"))
131+
if diag != nil {
132+
resp.Diagnostics.Append(diag)
147133
}
148-
projectId, err := uuid.Parse(state.Project.ValueString())
149-
if err != nil {
150-
resp.Diagnostics.AddAttributeError(
151-
path.Root("project"),
152-
"Within Read, unable to parse project into UUID",
153-
"Error from: "+err.Error(),
154-
)
134+
projectId, diag := TryParseUUID(state.Project, LifecycleRead, path.Root("project"))
135+
if diag != nil {
136+
resp.Diagnostics.Append(diag)
155137
}
156138
if resp.Diagnostics.HasError() {
157139
return
@@ -194,21 +176,13 @@ func (r *aclMappingResource) Update(ctx context.Context, req resource.UpdateRequ
194176
return
195177
}
196178

197-
team, err := uuid.Parse(plan.Team.ValueString())
198-
if err != nil {
199-
resp.Diagnostics.AddAttributeError(
200-
path.Root("team"),
201-
"Within Update, unable to parse team into UUID",
202-
"Error from: "+err.Error(),
203-
)
179+
team, diag := TryParseUUID(plan.Team, LifecycleUpdate, path.Root("team"))
180+
if diag != nil {
181+
resp.Diagnostics.Append(diag)
204182
}
205-
project, err := uuid.Parse(plan.Project.ValueString())
206-
if err != nil {
207-
resp.Diagnostics.AddAttributeError(
208-
path.Root("project"),
209-
"Within Update, unable to parse project into UUID",
210-
"Error from: "+err.Error(),
211-
)
183+
project, diag := TryParseUUID(plan.Project, LifecycleUpdate, path.Root("project"))
184+
if diag != nil {
185+
resp.Diagnostics.Append(diag)
212186
}
213187
if resp.Diagnostics.HasError() {
214188
return
@@ -239,29 +213,21 @@ func (r *aclMappingResource) Delete(ctx context.Context, req resource.DeleteRequ
239213
}
240214

241215
// Map TF to SDK
242-
team, err := uuid.Parse(state.Team.ValueString())
243-
if err != nil {
244-
resp.Diagnostics.AddAttributeError(
245-
path.Root("team"),
246-
"Within Delete, unable to parse team into UUID",
247-
"Error from: "+err.Error(),
248-
)
216+
team, diag := TryParseUUID(state.Team, LifecycleDelete, path.Root("team"))
217+
if diag != nil {
218+
resp.Diagnostics.Append(diag)
249219
}
250-
project, err := uuid.Parse(state.Project.ValueString())
251-
if err != nil {
252-
resp.Diagnostics.AddAttributeError(
253-
path.Root("project"),
254-
"Within Delete, unable to parse project into UUID",
255-
"Error from: "+err.Error(),
256-
)
220+
project, diag := TryParseUUID(state.Project, LifecycleDelete, path.Root("project"))
221+
if diag != nil {
222+
resp.Diagnostics.Append(diag)
257223
}
258224
if resp.Diagnostics.HasError() {
259225
return
260226
}
261227

262228
// Execute
263229
tflog.Debug(ctx, "Deleting acl mapping for project with id: "+state.Project.ValueString()+", and team with id: "+state.Team.ValueString())
264-
err = r.client.ACL.RemoveProjectMapping(ctx, team, project)
230+
err := r.client.ACL.RemoveProjectMapping(ctx, team, project)
265231
if err != nil {
266232
resp.Diagnostics.AddError(
267233
"Unable to delete acl mapping",
@@ -284,19 +250,16 @@ func (r *aclMappingResource) ImportState(ctx context.Context, req resource.Impor
284250
teamIdString := idParts[0]
285251
projectIdString := idParts[1]
286252

287-
teamId, err := uuid.Parse(teamIdString)
288-
if err != nil {
289-
resp.Diagnostics.AddError(
290-
"Within Import, unable to parse team into UUID",
291-
"Error from: "+err.Error(),
292-
)
253+
teamId, diag := TryParseUUID(types.StringValue(teamIdString), LifecycleImport, path.Root("team"))
254+
if diag != nil {
255+
resp.Diagnostics.Append(diag)
293256
}
294-
projectId, err := uuid.Parse(projectIdString)
295-
if err != nil {
296-
resp.Diagnostics.AddError(
297-
"Within Import, unable to parse project into UUID",
298-
"Error from: "+err.Error(),
299-
)
257+
projectId, diag := TryParseUUID(types.StringValue(projectIdString), LifecycleImport, path.Root("project"))
258+
if diag != nil {
259+
resp.Diagnostics.Append(diag)
260+
}
261+
if resp.Diagnostics.HasError() {
262+
return
300263
}
301264
aclMappingState := aclMappingResourceModel{
302265
ID: types.StringValue(fmt.Sprintf("%s/%s", teamId.String(), projectId.String())),

internal/provider/ldap_team_mapping_resource.go

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package provider
33
import (
44
"context"
55
"fmt"
6-
"github.com/google/uuid"
76

87
dtrack "github.com/DependencyTrack/client-go"
98
"github.com/hashicorp/terraform-plugin-framework/path"
@@ -75,13 +74,9 @@ func (r *ldapTeamMappingResource) Create(ctx context.Context, req resource.Creat
7574
if resp.Diagnostics.HasError() {
7675
return
7776
}
78-
team, err := uuid.Parse(plan.Team.ValueString())
79-
if err != nil {
80-
resp.Diagnostics.AddAttributeError(
81-
path.Root("team"),
82-
"Within Create, unable to parse team into UUID",
83-
"Error from: "+err.Error(),
84-
)
77+
team, diag := TryParseUUID(plan.Team, LifecycleCreate, path.Root("team"))
78+
if diag != nil {
79+
resp.Diagnostics.Append(diag)
8580
return
8681
}
8782
distinguishedName := plan.DistinguishedName.ValueString()
@@ -127,21 +122,13 @@ func (r *ldapTeamMappingResource) Read(ctx context.Context, req resource.ReadReq
127122
tflog.Debug(ctx, "Refreshing ldap mapping with id: "+state.ID.ValueString()+", for team: "+state.Team.ValueString()+", and distinguished name: "+state.DistinguishedName.ValueString())
128123

129124
// Refresh
130-
id, err := uuid.Parse(state.ID.ValueString())
131-
if err != nil {
132-
resp.Diagnostics.AddAttributeError(
133-
path.Root("id"),
134-
"Within Read, unable to parse id into UUID",
135-
"Error from: "+err.Error(),
136-
)
125+
id, diag := TryParseUUID(state.ID, LifecycleRead, path.Root("id"))
126+
if diag != nil {
127+
resp.Diagnostics.Append(diag)
137128
}
138-
team, err := uuid.Parse(state.Team.ValueString())
139-
if err != nil {
140-
resp.Diagnostics.AddAttributeError(
141-
path.Root("team"),
142-
"Within Read, unable to parse team into UUID",
143-
"Error from: "+err.Error(),
144-
)
129+
team, diag := TryParseUUID(state.Team, LifecycleRead, path.Root("team"))
130+
if diag != nil {
131+
resp.Diagnostics.Append(diag)
145132
}
146133
distinguishedName := state.DistinguishedName.ValueString()
147134
if resp.Diagnostics.HasError() {
@@ -192,21 +179,13 @@ func (r *ldapTeamMappingResource) Update(ctx context.Context, req resource.Updat
192179
return
193180
}
194181

195-
id, err := uuid.Parse(plan.ID.ValueString())
196-
if err != nil {
197-
resp.Diagnostics.AddAttributeError(
198-
path.Root("id"),
199-
"Within Update, unable to parse id into UUID",
200-
"Error from: "+err.Error(),
201-
)
182+
id, diag := TryParseUUID(plan.ID, LifecycleUpdate, path.Root("id"))
183+
if diag != nil {
184+
resp.Diagnostics.Append(diag)
202185
}
203-
team, err := uuid.Parse(plan.Team.ValueString())
204-
if err != nil {
205-
resp.Diagnostics.AddAttributeError(
206-
path.Root("team"),
207-
"Within Update, unable to parse team into UUID",
208-
"Error from: "+err.Error(),
209-
)
186+
team, diag := TryParseUUID(plan.Team, LifecycleUpdate, path.Root("team"))
187+
if diag != nil {
188+
resp.Diagnostics.Append(diag)
210189
}
211190
distingushedName := plan.DistinguishedName.ValueString()
212191
if resp.Diagnostics.HasError() {
@@ -238,19 +217,15 @@ func (r *ldapTeamMappingResource) Delete(ctx context.Context, req resource.Delet
238217
}
239218

240219
// Map TF to SDK
241-
id, err := uuid.Parse(state.ID.ValueString())
242-
if err != nil {
243-
resp.Diagnostics.AddAttributeError(
244-
path.Root("id"),
245-
"Within Delete, unable to parse id into UUID",
246-
"Error parsing UUID from: "+state.ID.ValueString()+", error: "+err.Error(),
247-
)
220+
id, diag := TryParseUUID(state.ID, LifecycleDelete, path.Root("id"))
221+
if diag != nil {
222+
resp.Diagnostics.Append(diag)
248223
return
249224
}
250225

251226
// Execute
252227
tflog.Debug(ctx, "Deleting ldap mapping with id: "+id.String()+", for team with id: "+state.Team.ValueString()+", and distinguished name: "+state.DistinguishedName.ValueString())
253-
err = r.client.LDAP.RemoveMapping(ctx, id)
228+
err := r.client.LDAP.RemoveMapping(ctx, id)
254229
if err != nil {
255230
resp.Diagnostics.AddError(
256231
"Unable to delete ldap mapping",

0 commit comments

Comments
 (0)