Skip to content

Commit 938e8e4

Browse files
deanhuynhmarcelopv
andauthored
Check empty id (#31)
Co-authored-by: Marcelo Vargas <[email protected]>
1 parent 58c5774 commit 938e8e4

11 files changed

+85
-7
lines changed

internal/provider/source_data_source.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ func (d *sourceDataSource) Read(ctx context.Context, req datasource.ReadRequest,
198198
return
199199
}
200200

201-
out, body, err := d.client.SourcesApi.GetSource(d.authContext, config.ID.ValueString()).Execute()
201+
id := config.ID.ValueString()
202+
if id == "" {
203+
resp.Diagnostics.AddError("Unable to read Source", "ID is empty")
204+
return
205+
}
206+
207+
out, body, err := d.client.SourcesApi.GetSource(d.authContext, id).Execute()
202208
if err != nil {
203209
resp.Diagnostics.AddError(
204210
"Unable to Read Source",

internal/provider/source_metadata_data_source.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ func (d *sourceMetadataDataSource) Read(ctx context.Context, req datasource.Read
4747
return
4848
}
4949

50-
response, body, err := d.client.CatalogApi.GetSourceMetadata(d.authContext, state.ID.ValueString()).Execute()
50+
id := state.ID.ValueString()
51+
if id == "" {
52+
resp.Diagnostics.AddError("Unable to read Source Metadata", "ID is empty")
53+
return
54+
}
55+
56+
response, body, err := d.client.CatalogApi.GetSourceMetadata(d.authContext, id).Execute()
5157
if err != nil {
5258
resp.Diagnostics.AddError(
5359
"Unable to Read Source metadata",
@@ -60,7 +66,7 @@ func (d *sourceMetadataDataSource) Read(ctx context.Context, req datasource.Read
6066
err = state.Fill(sourceMetadata)
6167
if err != nil {
6268
resp.Diagnostics.AddError(
63-
"Unable to Read Source metadata",
69+
"Unable to read Source Metadata",
6470
err.Error(),
6571
)
6672
return

internal/provider/source_resource.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,13 @@ func (r *sourceResource) Read(ctx context.Context, req resource.ReadRequest, res
317317
return
318318
}
319319

320-
out, body, err := r.client.SourcesApi.GetSource(r.authContext, config.ID.ValueString()).Execute()
320+
id := config.ID.ValueString()
321+
if id == "" {
322+
resp.Diagnostics.AddError("Unable to read Source", "ID is empty")
323+
return
324+
}
325+
326+
out, body, err := r.client.SourcesApi.GetSource(r.authContext, id).Execute()
321327
if err != nil {
322328
resp.Diagnostics.AddError(
323329
"Unable to read Source",

internal/provider/source_warehouse_connection_resource.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func (r *sourceWarehouseConnectionResource) Create(ctx context.Context, req reso
6666
return
6767
}
6868

69+
if plan.WarehouseID.String() == "" || plan.SourceID.String() == "" {
70+
resp.Diagnostics.AddError("Unable to create connection between Source and Warehouse", "At least one ID is empty")
71+
return
72+
}
73+
6974
_, body, err := r.client.WarehousesApi.AddConnectionFromSourceToWarehouse(r.authContext, plan.WarehouseID.ValueString(), plan.SourceID.ValueString()).Execute()
7075
if err != nil {
7176
resp.Diagnostics.AddError(
@@ -101,6 +106,10 @@ func (d *sourceWarehouseConnectionResource) Read(ctx context.Context, req resour
101106
paginationNext := "MA=="
102107

103108
for paginationNext != "" {
109+
if state.SourceID.String() == "" {
110+
resp.Diagnostics.AddError("Unable to read Source-Warehouse connection", "At least one ID is empty")
111+
return
112+
}
104113
response, body, err := d.client.SourcesApi.ListConnectedWarehousesFromSource(d.authContext, state.SourceID.ValueString()).Pagination(api.PaginationInput{
105114
Cursor: &paginationNext,
106115
Count: 200,
@@ -154,6 +163,11 @@ func (r *sourceWarehouseConnectionResource) Delete(ctx context.Context, req reso
154163
return
155164
}
156165

166+
if config.WarehouseID.String() == "" || config.SourceID.String() == "" {
167+
resp.Diagnostics.AddError("Unable to remove Source-Warehouse connection", "At least one ID is empty")
168+
return
169+
}
170+
157171
_, body, err := r.client.WarehousesApi.RemoveSourceConnectionFromWarehouse(r.authContext, config.WarehouseID.ValueString(), config.SourceID.ValueString()).Execute()
158172
if err != nil {
159173
resp.Diagnostics.AddError(

internal/provider/tracking_plan_data_source.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ func (d *trackingPlanDataSource) Read(ctx context.Context, req datasource.ReadRe
9191
return
9292
}
9393

94-
out, body, err := d.client.TrackingPlansApi.GetTrackingPlan(d.authContext, config.ID.ValueString()).Execute()
94+
id := config.ID.ValueString()
95+
if id == "" {
96+
resp.Diagnostics.AddError("Unable to read Tracking Plan", "ID is empty")
97+
return
98+
}
99+
100+
out, body, err := d.client.TrackingPlansApi.GetTrackingPlan(d.authContext, id).Execute()
95101
if err != nil {
96102
resp.Diagnostics.AddError(
97103
"Unable to read Tracking Plan",

internal/provider/tracking_plan_resource.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ func (r *trackingPlanResource) Read(ctx context.Context, req resource.ReadReques
126126
return
127127
}
128128

129-
out, body, err := r.client.TrackingPlansApi.GetTrackingPlan(r.authContext, config.ID.ValueString()).Execute()
129+
id := config.ID.ValueString()
130+
if id == "" {
131+
resp.Diagnostics.AddError("Unable to read Tracking Plan", "ID is empty")
132+
return
133+
}
134+
135+
out, body, err := r.client.TrackingPlansApi.GetTrackingPlan(r.authContext, id).Execute()
130136
if err != nil {
131137
resp.Diagnostics.AddError(
132138
"Unable to read Tracking Plan",

internal/provider/tracking_plan_rules_data_source.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ func (d *trackingPlanRulesDataSource) Read(ctx context.Context, req datasource.R
105105
return
106106
}
107107

108+
if config.TrackingPlanID.ValueString() == "" {
109+
resp.Diagnostics.AddError("Unable to read Tracking Plan rules", "ID is empty")
110+
return
111+
}
112+
108113
out, body, err := d.client.TrackingPlansApi.ListRulesFromTrackingPlan(d.authContext, config.TrackingPlanID.ValueString()).Pagination(*api.NewPaginationInput(200)).Execute()
109114
if err != nil {
110115
resp.Diagnostics.AddError(
@@ -118,7 +123,7 @@ func (d *trackingPlanRulesDataSource) Read(ctx context.Context, req datasource.R
118123
err = state.Fill(out.Data.GetRules(), config.TrackingPlanID.ValueString())
119124
if err != nil {
120125
resp.Diagnostics.AddError(
121-
"Unable to get Tracking Plan rules",
126+
"Unable to read Tracking Plan rules",
122127
err.Error(),
123128
)
124129
return

internal/provider/tracking_plan_rules_resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func (r *trackingPlanRulesResource) Create(ctx context.Context, req resource.Cre
108108
replaceRules = append(replaceRules, apiRule)
109109
}
110110

111+
if plan.TrackingPlanID.ValueString() == "" {
112+
resp.Diagnostics.AddError("Unable to create Tracking Plan rules", "ID is empty")
113+
return
114+
}
115+
111116
_, body, err := r.client.TrackingPlansApi.ReplaceRulesInTrackingPlan(r.authContext, plan.TrackingPlanID.ValueString()).ReplaceRulesInTrackingPlanV1Input(api.ReplaceRulesInTrackingPlanV1Input{
112117
Rules: replaceRules,
113118
}).Execute()
@@ -148,6 +153,12 @@ func (r *trackingPlanRulesResource) Read(ctx context.Context, req resource.ReadR
148153
config.Rules.ElementsAs(ctx, &rules, false)
149154
state.Rules = rules
150155
} else {
156+
157+
if config.TrackingPlanID.ValueString() == "" {
158+
resp.Diagnostics.AddError("Unable to read Tracking Plan rules", "ID is empty")
159+
return
160+
}
161+
151162
out, body, err := r.client.TrackingPlansApi.ListRulesFromTrackingPlan(r.authContext, config.TrackingPlanID.ValueString()).Pagination(*api.NewPaginationInput(200)).Execute()
152163
if err != nil {
153164
resp.Diagnostics.AddError(

internal/provider/warehouse_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ func (d *warehouseDataSource) Read(ctx context.Context, req datasource.ReadReque
7575
return
7676
}
7777

78+
id := state.ID.ValueString()
79+
if id == "" {
80+
resp.Diagnostics.AddError("Unable to read Warehouse", "ID is empty")
81+
return
82+
}
83+
7884
response, body, err := d.client.WarehousesApi.GetWarehouse(d.authContext, state.ID.ValueString()).Execute()
7985
if err != nil {
8086
resp.Diagnostics.AddError(

internal/provider/warehouse_metadata_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ func (d *warehouseMetadataDataSource) Read(ctx context.Context, req datasource.R
118118
return
119119
}
120120

121+
id := state.ID.ValueString()
122+
if id == "" {
123+
resp.Diagnostics.AddError("Unable to read Warehouse metadata", "ID is empty")
124+
return
125+
}
126+
121127
response, body, err := d.client.CatalogApi.GetWarehouseMetadata(d.authContext, state.ID.ValueString()).Execute()
122128
if err != nil {
123129
resp.Diagnostics.AddError(

0 commit comments

Comments
 (0)