Configuration
With the module initialised, the StatusCake provider can be configured.
Authentication
The StatusCake Terraform provider requires that an API bearer token be included in the provider configuration block. You can view and manage your API tokens from the StatusCake account panel.
API tokens must be kept private. In the event that one is exposed a new one should be generated.
- Go
- JavaScript (alpha)
- Python (alpha)
- Ruby (alpha)
package main
import (
"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)
func main() {
bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(statuscake.WithRequestCredentials(bearer))
}
import 'isomorphic-fetch';
import {
Configuration,
} from '@statuscake/statuscake-js';
const config = new Configuration({
headers: {
'Authorization': `Bearer ${apiToken}`,
},
});
from statuscake import ApiClient
client = ApiClient(
header_name='Authorization',
header_value='Bearer %s' % api_token,
)
require 'statuscake'
client = StatusCake::ApiClient.new
# Constructing these options is a temporary fix until a client wide
# authentication mechanism has been realised.
opts = { header_params: { 'Authorization' => "Bearer #{api_token}" } }
Request Retries
When a request results in a transient error - an error that will resolve itself, i.e. connection error, or rate limit being hit - it may be desirable to retry the request in the future. For this the SDKs allow for each request to be retired up to some maximum number of times to give thea greater chance for success.
- Go
package main
import (
"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)
func main() {
bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(
statuscake.WithRequestCredentials(bearer),
statuscake.WithMaxRetries(3),
)
}
Backoff
By default request retry attempts are made using a constant backoff strategy with a backoff period of 1 second. This may be configured to support alternate backoff periods.
- Go
package main
import (
"time"
"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/backoff"
"github.com/StatusCakeDev/statuscake-go/credentials"
)
func main() {
bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(
statuscake.WithRequestCredentials(bearer),
statuscake.WithBackoff(backoff.Constant{
BaseDelay: time.Duration(5) * time.Second,
}),
)
}
The SDKs support other backoff strategies. These are detailed further in the backoff strategies guide.
Disable Retries
Request retries can be disabled entirely for applications that do not require it.
- Go
package main
import (
"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)
func main() {
bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(
statuscake.WithRequestCredentials(bearer),
statuscake.WithDisableRetry(),
)
}
Next Steps
Next learn about the different request retry backoff strategies the SDKs support.