Skip to content

Commit

Permalink
add error when client is not configured in provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanburgess committed Sep 13, 2024
1 parent c26772f commit 60a2bbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions internal/resources/cloudprovider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ func withClientForResource(req resource.ConfigureRequest, resp *resource.Configu
return nil, fmt.Errorf("unexpected Resource Configure Type: %T, expected *common.Client", req.ProviderData)
}

if client.CloudProviderAPI == nil {
resp.Diagnostics.AddError(
"The Grafana Provider is missing a configuration for the Cloud Provider API.",
"Please ensure that cloud_provider_url and cloud_provider_access_token are set in the provider configuration.",
)

return nil, fmt.Errorf("CloudProviderAPI is nil")
}

return client.CloudProviderAPI, nil
}

Expand All @@ -47,5 +56,14 @@ func withClientForDataSource(req datasource.ConfigureRequest, resp *datasource.C
return nil, fmt.Errorf("unexpected DataSource Configure Type: %T, expected *common.Client", req.ProviderData)
}

if client.CloudProviderAPI == nil {
resp.Diagnostics.AddError(
"The Grafana Provider is missing a configuration for the Cloud Provider API.",
"Please ensure that cloud_provider_url and cloud_provider_access_token are set in the provider configuration.",
)

return nil, fmt.Errorf("CloudProviderAPI is nil")
}

return client.CloudProviderAPI, nil
}
2 changes: 1 addition & 1 deletion pkg/provider/configure_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CreateClients(providerConfig ProviderConfig) (*common.Client, error) {
onCallClient.UserAgent = providerConfig.UserAgent.ValueString()
c.OnCallClient = onCallClient
}
if !providerConfig.CloudProviderURL.IsNull() && !providerConfig.CloudProviderAccessToken.IsNull() {
if !providerConfig.CloudProviderAccessToken.IsNull() {
if err := createCloudProviderClient(c, providerConfig); err != nil {
return nil, err
}
Expand Down

0 comments on commit 60a2bbb

Please sign in to comment.