-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_different_region_test.go
64 lines (56 loc) · 1.37 KB
/
example_different_region_test.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
54
55
56
57
58
59
60
61
62
63
64
package brightbox_test
import (
"context"
"fmt"
"log"
brightbox "github.com/brightbox/gobrightbox/v2"
"github.com/brightbox/gobrightbox/v2/clientcredentials"
"github.com/brightbox/gobrightbox/v2/endpoint"
)
// Authenticate using an API Client identifier and secret, and get a list of
// configMaps, but in a different region
func ExampleConnect_different_region() {
// Brightbox client details issued on a specific account
clientID := "cli-xxxxx"
clientSecret := "somesecret"
region := "https://api.gb1s.brightbox.com"
// Setup Config
conf := &clientcredentials.Config{
ID: clientID,
Secret: clientSecret,
Config: endpoint.Config{
BaseURL: region,
},
}
// Underlying network connection context.
ctx := context.Background()
// Setup connection to API
client, err := brightbox.Connect(ctx, conf)
if err != nil {
log.Fatal(err)
}
// Get a list of configMaps
configMaps, err := client.ConfigMaps(ctx)
if err != nil {
log.Fatal(err)
}
for _, configMap := range configMaps {
fmt.Printf("id:%s name:%s\n", configMap.ID, configMap.Name)
}
// Create a new configMap
name := "new_map"
data := map[string]interface{}{
"attribute": 42,
}
configMap, err := client.CreateConfigMap(
ctx,
brightbox.ConfigMapOptions{
Name: &name,
Data: &data,
},
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("id:%s name:%s\n", configMap.ID, configMap.Name)
}