-
Notifications
You must be signed in to change notification settings - Fork 258
/
sweep.go
53 lines (42 loc) · 1.32 KB
/
sweep.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package sweep
import (
"fmt"
"log"
"os"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/config"
)
const TestNamePrefix = "tf-acc-test-"
func SharedConfigForRegion(region string) (interface{}, error) {
if os.Getenv("DIGITALOCEAN_TOKEN") == "" {
return nil, fmt.Errorf("empty DIGITALOCEAN_TOKEN")
}
apiEndpoint := os.Getenv("DIGITALOCEAN_API_URL")
if apiEndpoint == "" {
apiEndpoint = "https://api.digitalocean.com"
}
spacesEndpoint := os.Getenv("SPACES_ENDPOINT_URL")
if spacesEndpoint == "" {
spacesEndpoint = "https://{{.Region}}.digitaloceanspaces.com"
}
spacesAccessKeyID := os.Getenv("SPACES_ACCESS_KEY_ID")
if spacesAccessKeyID == "" {
log.Println("[DEBUG] SPACES_ACCESS_KEY_ID not set")
}
spacesSecretAccessKey := os.Getenv("SPACES_SECRET_ACCESS_KEY")
if spacesSecretAccessKey == "" {
log.Println("[DEBUG] SPACES_SECRET_ACCESS_KEY not set")
}
conf := config.Config{
Token: os.Getenv("DIGITALOCEAN_TOKEN"),
APIEndpoint: apiEndpoint,
SpacesAPIEndpoint: spacesEndpoint,
AccessID: spacesAccessKeyID,
SecretKey: spacesSecretAccessKey,
}
// configures a default client for the region, using the above env vars
client, err := conf.Client()
if err != nil {
return nil, fmt.Errorf("error getting DigitalOcean client")
}
return client, nil
}