forked from bloominlabs/vault-plugin-secrets-cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.go
More file actions
36 lines (31 loc) · 845 Bytes
/
Copy pathclient.go
File metadata and controls
36 lines (31 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package cloudflare
import (
"context"
"net/http"
"time"
"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/vault/sdk/logical"
)
const (
cloudflareClientTimeout = 60 * time.Second
cloudflareMaxRetries = 5
cloudflareMinRetryDelaySeconds = 1
cloudflareMaxRetryDelaySeconds = 60
)
func createClient(token string) (*cloudflare.API, error) {
client := &http.Client{
Timeout: cloudflareClientTimeout,
}
return cloudflare.NewWithAPIToken(
token,
cloudflare.HTTPClient(client),
cloudflare.UsingRetryPolicy(cloudflareMaxRetries, cloudflareMinRetryDelaySeconds, cloudflareMaxRetryDelaySeconds),
)
}
func (b *backend) client(ctx context.Context, s logical.Storage) (*cloudflare.API, error) {
conf, err := b.readConfigToken(ctx, s)
if err != nil {
return nil, err
}
return createClient(conf.Token)
}