forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
62 lines (54 loc) · 1.38 KB
/
config.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
package scaleway
import (
"fmt"
"log"
"net/http"
"os"
"github.com/scaleway/scaleway-cli/pkg/api"
"github.com/scaleway/scaleway-cli/pkg/scwversion"
)
// Config contains scaleway configuration values
type Config struct {
Organization string
APIKey string
}
// Client contains scaleway api clients
type Client struct {
scaleway *api.ScalewayAPI
}
// Client configures and returns a fully initialized Scaleway client
func (c *Config) Client() (*Client, error) {
api, err := api.NewScalewayAPI(
c.Organization,
c.APIKey,
scwversion.UserAgent(),
func(s *api.ScalewayAPI) {
s.Logger = newTerraformLogger()
},
)
if err != nil {
return nil, err
}
return &Client{api}, nil
}
func newTerraformLogger() api.Logger {
return &terraformLogger{}
}
type terraformLogger struct {
}
func (l *terraformLogger) LogHTTP(r *http.Request) {
log.Printf("[DEBUG] %s %s\n", r.Method, r.URL.Path)
}
func (l *terraformLogger) Fatalf(format string, v ...interface{}) {
log.Printf("[FATAL] %s\n", fmt.Sprintf(format, v))
os.Exit(1)
}
func (l *terraformLogger) Debugf(format string, v ...interface{}) {
log.Printf("[DEBUG] %s\n", fmt.Sprintf(format, v))
}
func (l *terraformLogger) Infof(format string, v ...interface{}) {
log.Printf("[INFO ] %s\n", fmt.Sprintf(format, v))
}
func (l *terraformLogger) Warnf(format string, v ...interface{}) {
log.Printf("[WARN ] %s\n", fmt.Sprintf(format, v))
}