Skip to content

Commit

Permalink
fix: make server_url an optional field with default fallback value
Browse files Browse the repository at this point in the history
  • Loading branch information
Angie Song committed Mar 22, 2024
1 parent e79e924 commit fe336d9
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (p *Provider) Schema(ctx context.Context, req provider.SchemaRequest, resp
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"server_url": schema.StringAttribute{
Required: true,
Optional: true,
Required: false,
Sensitive: false,
Description: "The API host.",
},
Expand All @@ -61,13 +62,9 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
return
}

if dataModel.ServerUrl.IsUnknown() {
resp.Diagnostics.AddAttributeError(
path.Root("server_url"),
"Unknown ServerUrl",
"Cannot create API client without server_url.",
)
return
serverUrl := dataModel.ServerUrl.ValueString()
if serverUrl == "" {
serverUrl = "https://api.abbey.io/v1"
}

if dataModel.BearerAuth.IsUnknown() {
Expand All @@ -80,7 +77,7 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
}

config := clientconfig.NewConfig()
config.SetBaseUrl(dataModel.ServerUrl.ValueString())
config.SetBaseUrl(serverUrl)
config.SetAccessToken(dataModel.BearerAuth.ValueString())
apiClient := client.NewClient(config)

Expand Down

0 comments on commit fe336d9

Please sign in to comment.