Skip to content

Commit

Permalink
Extracted constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Jan 24, 2021
1 parent f519645 commit 089cb08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import (
"gopkg.in/ini.v1"
)

// Default settings
const (
DefaultRateLimit = 1200
DebugTruncateBytes = 96
DefaultTimeoutSeconds = 60
)

// DatabricksClient is the client struct that contains clients for all the services available on Databricks
type DatabricksClient struct {
Host string
Expand All @@ -45,7 +52,7 @@ func (c *DatabricksClient) Configure() error {
c.configureHTTPCLient()
c.AzureAuth.databricksClient = c
if c.DebugTruncateBytes == 0 {
c.DebugTruncateBytes = 96
c.DebugTruncateBytes = DebugTruncateBytes
}
return nil
}
Expand Down Expand Up @@ -179,10 +186,10 @@ func (c *DatabricksClient) encodeBasicAuth(username, password string) string {

func (c *DatabricksClient) configureHTTPCLient() {
if c.TimeoutSeconds == 0 {
c.TimeoutSeconds = 60
c.TimeoutSeconds = DefaultTimeoutSeconds
}
if c.RateLimit == 0 {
c.RateLimit = 1200
c.RateLimit = DefaultRateLimit
}
c.rateLimiter = rate.NewLimiter(rate.Every(1*time.Minute), c.RateLimit)
// Set up a retryable HTTP Client to handle cases where the service returns
Expand Down
4 changes: 2 additions & 2 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func DatabricksProvider() *schema.Provider {
Optional: true,
Type: schema.TypeInt,
Description: "Truncate JSON fields in JSON above this limit. Default is 96. Visible only when TF_LOG=DEBUG is set",
DefaultFunc: schema.EnvDefaultFunc("DATABRICKS_DEBUG_TRUNCATE_BYTES", 96),
DefaultFunc: schema.EnvDefaultFunc("DATABRICKS_DEBUG_TRUNCATE_BYTES", common.DebugTruncateBytes),
},
"debug_headers": {
Optional: true,
Expand All @@ -216,7 +216,7 @@ func DatabricksProvider() *schema.Provider {
Optional: true,
Type: schema.TypeInt,
Description: "Maximum number of requests per minute made to Databricks REST API by Terraform.",
DefaultFunc: schema.EnvDefaultFunc("DATABRICKS_RATE_LIMIT", 1200),
DefaultFunc: schema.EnvDefaultFunc("DATABRICKS_RATE_LIMIT", common.DefaultRateLimit),
},
},
ConfigureContextFunc: func(c context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
Expand Down

0 comments on commit 089cb08

Please sign in to comment.