Skip to content

Commit f90dd96

Browse files
Copilotmawasilemattdot
authored
Fix unsafe type assertions in provider data handling (#847)
* Initial plan for issue * Fix unsafe type assertions in provider data handling Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com> Co-authored-by: Matt Dotson <mattdot@users.noreply.github.com>
1 parent 9b1bc31 commit f90dd96

File tree

8 files changed

+35
-41
lines changed

8 files changed

+35
-41
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: fixed
2+
body: Fixed unsafe type assertions in provider data handling that could cause panics and misleading error messages
3+
time: 2025-06-05T15:12:06.705294178Z
4+
custom:
5+
Issue: "841"

internal/services/data_record/datasource_data_record.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,16 @@ func (d *DataRecordDataSource) Configure(ctx context.Context, req datasource.Con
190190
return
191191
}
192192

193-
client := req.ProviderData.(*api.ProviderClient).Api
194-
195-
if client == nil {
193+
providerClient, ok := req.ProviderData.(*api.ProviderClient)
194+
if !ok {
196195
resp.Diagnostics.AddError(
197-
"Unexpected Resource Configure Type",
198-
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
196+
"Unexpected DataSource Configure Type",
197+
fmt.Sprintf("Expected *api.ProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
199198
)
200-
201199
return
202200
}
203201

204-
d.DataRecordClient = newDataRecordClient(client)
202+
d.DataRecordClient = newDataRecordClient(providerClient.Api)
205203
}
206204

207205
func (d *DataRecordDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {

internal/services/data_record/resource_data_record.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,15 @@ func (r *DataRecordResource) Configure(ctx context.Context, req resource.Configu
112112
return
113113
}
114114

115-
clientApi := req.ProviderData.(*api.ProviderClient).Api
116-
if clientApi == nil {
115+
providerClient, ok := req.ProviderData.(*api.ProviderClient)
116+
if !ok {
117117
resp.Diagnostics.AddError(
118118
"Unexpected Resource Configure Type",
119-
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
119+
fmt.Sprintf("Expected *api.ProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
120120
)
121-
122121
return
123122
}
124-
r.DataRecordClient = newDataRecordClient(clientApi)
123+
r.DataRecordClient = newDataRecordClient(providerClient.Api)
125124
}
126125

127126
func (r *DataRecordResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {

internal/services/environment_group_rule_set/resource_environment_group_rule_set.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ func (r *environmentGroupRuleSetResource) Configure(ctx context.Context, req res
270270
return
271271
}
272272

273-
client := req.ProviderData.(*api.ProviderClient).Api
274-
if client == nil {
273+
providerClient, ok := req.ProviderData.(*api.ProviderClient)
274+
if !ok {
275275
resp.Diagnostics.AddError(
276276
"Unexpected Resource Configure Type",
277-
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
277+
fmt.Sprintf("Expected *api.ProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
278278
)
279279
return
280280
}
281-
r.EnvironmentGroupRuleSetClient = NewEnvironmentGroupRuleSetClient(client, tenant.NewTenantClient(client))
281+
r.EnvironmentGroupRuleSetClient = NewEnvironmentGroupRuleSetClient(providerClient.Api, tenant.NewTenantClient(providerClient.Api))
282282
}
283283

284284
func (r *environmentGroupRuleSetResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {

internal/services/environment_settings/resources_environment_settings.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,16 @@ func (r *EnvironmentSettingsResource) Configure(ctx context.Context, req resourc
298298
return
299299
}
300300

301-
client := req.ProviderData.(*api.ProviderClient).Api
302-
303-
if client == nil {
301+
providerClient, ok := req.ProviderData.(*api.ProviderClient)
302+
if !ok {
304303
resp.Diagnostics.AddError(
305304
"Unexpected Resource Configure Type",
306-
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
305+
fmt.Sprintf("Expected *api.ProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
307306
)
308-
309307
return
310308
}
311309

312-
r.EnvironmentSettingClient = newEnvironmentSettingsClient(client)
310+
r.EnvironmentSettingClient = newEnvironmentSettingsClient(providerClient.Api)
313311
}
314312

315313
func (r *EnvironmentSettingsResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {

internal/services/languages/datasource_languages.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,15 @@ func (d *DataSource) Configure(ctx context.Context, req datasource.ConfigureRequ
9898
// ProviderData will be null when Configure is called from ValidateConfig. It's ok.
9999
return
100100
}
101-
clientApi := req.ProviderData.(*api.ProviderClient).Api
102-
if clientApi == nil {
101+
providerClient, ok := req.ProviderData.(*api.ProviderClient)
102+
if !ok {
103103
resp.Diagnostics.AddError(
104-
"Unexpected Resource Configure Type",
105-
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
104+
"Unexpected DataSource Configure Type",
105+
fmt.Sprintf("Expected *api.ProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
106106
)
107-
108107
return
109108
}
110-
d.LanguagesClient = newLanguagesClient(clientApi)
109+
d.LanguagesClient = newLanguagesClient(providerClient.Api)
111110
}
112111

113112
func (d *DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {

internal/services/managed_environment/resource_managed_environment.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,14 @@ func (r *ManagedEnvironmentResource) Configure(ctx context.Context, req resource
6868
)
6969
return
7070
}
71-
clientApi := client.Api
72-
73-
if clientApi == nil {
71+
if client.Api == nil {
7472
resp.Diagnostics.AddError(
75-
"Unexpected Resource Configure Type",
76-
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
73+
"Nil Api client",
74+
"ProviderData contained a *api.ProviderClient but with nil Api. Please check provider initialization and credentials.",
7775
)
78-
7976
return
8077
}
81-
r.ManagedEnvironmentClient = newManagedEnvironmentClient(clientApi)
78+
r.ManagedEnvironmentClient = newManagedEnvironmentClient(client.Api)
8279
}
8380

8481
func (r *ManagedEnvironmentResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {

internal/services/tenant_settings/resource_tenant_settings.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,16 @@ func (r *TenantSettingsResource) Configure(ctx context.Context, req resource.Con
344344
return
345345
}
346346

347-
client := req.ProviderData.(*api.ProviderClient).Api
348-
349-
if client == nil {
347+
providerClient, ok := req.ProviderData.(*api.ProviderClient)
348+
if !ok {
350349
resp.Diagnostics.AddError(
351350
"Unexpected Resource Configure Type",
352-
fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
351+
fmt.Sprintf("Expected *api.ProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
353352
)
354-
355353
return
356354
}
357355

358-
r.TenantSettingClient = newTenantSettingsClient(client)
356+
r.TenantSettingClient = newTenantSettingsClient(providerClient.Api)
359357
}
360358

361359
func (r *TenantSettingsResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {

0 commit comments

Comments
 (0)