Skip to content

Commit e1ddc71

Browse files
committed
(fix) fix potential nil pointer when using namespace data source
1 parent b5d55c8 commit e1ddc71

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

internal/provider/namespace_data_source.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/hashicorp/terraform-plugin-framework/datasource"
78
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@@ -45,7 +46,20 @@ func (d *NamespaceDataSource) Schema(_ context.Context, _ datasource.SchemaReque
4546
}
4647

4748
func (d *NamespaceDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
48-
d.client = ConfigureClient(req, resp)
49+
if req.ProviderData == nil {
50+
return
51+
}
52+
53+
client, ok := req.ProviderData.(*client.Client)
54+
if !ok {
55+
resp.Diagnostics.AddError(
56+
"Unexpected Data Source Configure Type",
57+
fmt.Sprintf("Expected *client.Client, got: %T.", req.ProviderData),
58+
)
59+
return
60+
}
61+
62+
d.client = client
4963
}
5064

5165
func (d *NamespaceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
@@ -56,6 +70,14 @@ func (d *NamespaceDataSource) Read(ctx context.Context, req datasource.ReadReque
5670
return
5771
}
5872

73+
if d.client == nil {
74+
resp.Diagnostics.AddError(
75+
"Client not configured",
76+
"The provider client is not properly configured. Please report this issue to the provider developers.",
77+
)
78+
return
79+
}
80+
5981
namespaceResp, err := d.client.NamespaceService.GetNamespace(ctx, &pb.GetNamespaceRequest{
6082
Id: data.ID.ValueString(),
6183
})

0 commit comments

Comments
 (0)