github.com/richardbowden/terraform@v0.6.12-0.20160901200758-30ea22c25211/builtin/providers/scaleway/config.go (about) 1 package scaleway 2 3 import ( 4 "fmt" 5 "log" 6 "net/http" 7 "os" 8 9 "github.com/scaleway/scaleway-cli/pkg/api" 10 "github.com/scaleway/scaleway-cli/pkg/scwversion" 11 ) 12 13 // Config contains scaleway configuration values 14 type Config struct { 15 Organization string 16 APIKey string 17 } 18 19 // Client contains scaleway api clients 20 type Client struct { 21 scaleway *api.ScalewayAPI 22 } 23 24 // Client configures and returns a fully initialized Scaleway client 25 func (c *Config) Client() (*Client, error) { 26 api, err := api.NewScalewayAPI( 27 c.Organization, 28 c.APIKey, 29 scwversion.UserAgent(), 30 func(s *api.ScalewayAPI) { 31 s.Logger = newTerraformLogger() 32 }, 33 ) 34 if err != nil { 35 return nil, err 36 } 37 return &Client{api}, nil 38 } 39 40 func newTerraformLogger() api.Logger { 41 return &terraformLogger{} 42 } 43 44 type terraformLogger struct { 45 } 46 47 func (l *terraformLogger) LogHTTP(r *http.Request) { 48 log.Printf("[DEBUG] %s %s\n", r.Method, r.URL.Path) 49 } 50 func (l *terraformLogger) Fatalf(format string, v ...interface{}) { 51 log.Printf("[FATAL] %s\n", fmt.Sprintf(format, v)) 52 os.Exit(1) 53 } 54 func (l *terraformLogger) Debugf(format string, v ...interface{}) { 55 log.Printf("[DEBUG] %s\n", fmt.Sprintf(format, v)) 56 } 57 func (l *terraformLogger) Infof(format string, v ...interface{}) { 58 log.Printf("[INFO ] %s\n", fmt.Sprintf(format, v)) 59 } 60 func (l *terraformLogger) Warnf(format string, v ...interface{}) { 61 log.Printf("[WARN ] %s\n", fmt.Sprintf(format, v)) 62 }