diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b413e..b99f357 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# Release v1.15.1 (2023-08-16) +* Adds timeout in api client + # Release v1.15.0 (2023-08-01) * Adds OIDC support in integrations & login diff --git a/buddy/provider/provider.go b/buddy/provider/provider.go index b3d1208..38fbf03 100644 --- a/buddy/provider/provider.go +++ b/buddy/provider/provider.go @@ -11,8 +11,10 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" "os" + "strconv" buddyresource "terraform-provider-buddy/buddy/resource" buddysource "terraform-provider-buddy/buddy/source" + "time" ) var _ provider.Provider = &BuddyProvider{} @@ -25,6 +27,7 @@ type BuddyProviderModel struct { Token types.String `tfsdk:"token"` BaseUrl types.String `tfsdk:"base_url"` Insecure types.Bool `tfsdk:"insecure"` + Timeout types.Int64 `tfsdk:"timeout"` } func (p *BuddyProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) { @@ -48,6 +51,10 @@ func (p *BuddyProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp MarkdownDescription: "Disable SSL verification of API calls. You may need to set this to `true` if you are using Buddy On-Premises without signed certificate. Can be specified with the `BUDDY_INSECURE` environmental variable", Optional: true, }, + "timeout": schema.Int64Attribute{ + MarkdownDescription: "The Buddy API client timeout in seconds. Can be specified with the `BUDDY_TIMEOUT` environmental variable. Default: 30s", + Optional: true, + }, }, } } @@ -79,6 +86,13 @@ func (p *BuddyProvider) Configure(ctx context.Context, req provider.ConfigureReq "The provider cannot create the Buddy API client as there is unknown configuration value for the Buddy insecure attribute", ) } + if config.Timeout.IsUnknown() { + resp.Diagnostics.AddAttributeError( + path.Root("timeout"), + "Unknown Buddy timeout value for the API endpoint", + "The provider cannot create the Buddy API client as there is unknown configuration value for the Buddy timeout attribute", + ) + } if resp.Diagnostics.HasError() { return } @@ -95,8 +109,21 @@ func (p *BuddyProvider) Configure(ctx context.Context, req provider.ConfigureReq if !config.Insecure.IsNull() { insecure = config.Insecure.ValueBool() } + timeout := 30 + t := os.Getenv("BUDDY_TIMEOUT") + if t != "" { + var err error + timeout, err = strconv.Atoi(t) + if err != nil { + resp.Diagnostics.AddError("Wrong value in BUDDY_TIMEOUT env variable", "The provider cannot create the Buddy API client as there is wrong value for the BUDDY_TIMEOUT env variable") + return + } + } + if !config.Timeout.IsNull() { + timeout = int(config.Timeout.ValueInt64()) + } - client, err := buddy.NewClient(token, baseUrl, insecure) + client, err := buddy.NewClientWithTimeout(token, baseUrl, insecure, time.Duration(timeout)*time.Second) if err != nil { resp.Diagnostics.AddError("Failed to create Buddy Client from provider configuration", fmt.Sprintf("The provider failed to create a new Buddy Client from the giver configuration: %s", err.Error())) return diff --git a/buddy/source/test/member_test.go b/buddy/source/test/member_test.go index b68328a..d738686 100644 --- a/buddy/source/test/member_test.go +++ b/buddy/source/test/member_test.go @@ -13,7 +13,10 @@ import ( func TestAccSourceMember_upgrade(t *testing.T) { domain := util.UniqueString() config := testAccSourceMemberConfig(domain) - p, _, _ := acc.ApiClient.ProfileService.Get() + p, _, err := acc.ApiClient.ProfileService.Get() + if err != nil { + t.Fatal(err) + } resource.Test(t, resource.TestCase{ Steps: []resource.TestStep{ { diff --git a/docs/index.md b/docs/index.md index 5f8515a..98994f2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,4 +25,5 @@ provider "buddy" { - `base_url` (String) The Buddy API base url. You may need to set this to your Buddy On-Premises API endpoint. Can be specified with the `BUDDY_BASE_URL` environment variable. Default: `https://api.buddy.works` - `insecure` (Boolean) Disable SSL verification of API calls. You may need to set this to `true` if you are using Buddy On-Premises without signed certificate. Can be specified with the `BUDDY_INSECURE` environmental variable +- `timeout` (Number) The Buddy API client timeout in seconds. Can be specified with the `BUDDY_TIMEOUT` environmental variable. Default: 30s - `token` (String, Sensitive) The OAuth2 token or Personal Access Token. Can be specified with the `BUDDY_TOKEN` environment variable. \ No newline at end of file diff --git a/go.mod b/go.mod index 83cfaf9..2832fc7 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/bflad/tfproviderlint v0.29.0 - github.com/buddy/api-go-sdk v1.13.1 + github.com/buddy/api-go-sdk v1.13.4 github.com/golangci/golangci-lint v1.52.2 github.com/hashicorp/terraform-plugin-docs v0.14.1 github.com/hashicorp/terraform-plugin-framework v1.2.0 diff --git a/go.sum b/go.sum index 6a2654d..89db9d1 100644 --- a/go.sum +++ b/go.sum @@ -118,8 +118,8 @@ github.com/breml/bidichk v0.2.4 h1:i3yedFWWQ7YzjdZJHnPo9d/xURinSq3OM+gyM43K4/8= github.com/breml/bidichk v0.2.4/go.mod h1:7Zk0kRFt1LIZxtQdl9W9JwGAcLTTkOs+tN7wuEYGJ3s= github.com/breml/errchkjson v0.3.1 h1:hlIeXuspTyt8Y/UmP5qy1JocGNR00KQHgfaNtRAjoxQ= github.com/breml/errchkjson v0.3.1/go.mod h1:XroxrzKjdiutFyW3nWhw34VGg7kiMsDQox73yWCGI2U= -github.com/buddy/api-go-sdk v1.13.1 h1:bDHXha/MmoNfDWqYdygXoGq+AkASyZMX9XnjF2SJc9g= -github.com/buddy/api-go-sdk v1.13.1/go.mod h1:l3gE/GMTiq92cQGjQsBWwoTMaTPkLZqNZwLQOBAQiQw= +github.com/buddy/api-go-sdk v1.13.4 h1:Ht0A+cuGYHYEB3oYCS+6XkNdy2EBhS2WA69h6bqf8Ik= +github.com/buddy/api-go-sdk v1.13.4/go.mod h1:l3gE/GMTiq92cQGjQsBWwoTMaTPkLZqNZwLQOBAQiQw= github.com/butuzov/ireturn v0.1.1 h1:QvrO2QF2+/Cx1WA/vETCIYBKtRjc30vesdoPUNo1EbY= github.com/butuzov/ireturn v0.1.1/go.mod h1:Wh6Zl3IMtTpaIKbmwzqi6olnM9ptYQxxVacMsOEFPoc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=