github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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 Region string 18 } 19 20 // Client contains scaleway api clients 21 type Client struct { 22 scaleway *api.ScalewayAPI 23 } 24 25 // Client configures and returns a fully initialized Scaleway client 26 func (c *Config) Client() (*Client, error) { 27 api, err := api.NewScalewayAPI( 28 c.Organization, 29 c.APIKey, 30 scwversion.UserAgent(), 31 c.Region, 32 func(s *api.ScalewayAPI) { 33 s.Logger = newTerraformLogger() 34 }, 35 ) 36 if err != nil { 37 return nil, err 38 } 39 return &Client{api}, nil 40 } 41 42 func newTerraformLogger() api.Logger { 43 return &terraformLogger{} 44 } 45 46 type terraformLogger struct { 47 } 48 49 func (l *terraformLogger) LogHTTP(r *http.Request) { 50 log.Printf("[DEBUG] %s %s\n", r.Method, r.URL.Path) 51 } 52 func (l *terraformLogger) Fatalf(format string, v ...interface{}) { 53 log.Printf("[FATAL] %s\n", fmt.Sprintf(format, v)) 54 os.Exit(1) 55 } 56 func (l *terraformLogger) Debugf(format string, v ...interface{}) { 57 log.Printf("[DEBUG] %s\n", fmt.Sprintf(format, v)) 58 } 59 func (l *terraformLogger) Infof(format string, v ...interface{}) { 60 log.Printf("[INFO ] %s\n", fmt.Sprintf(format, v)) 61 } 62 func (l *terraformLogger) Warnf(format string, v ...interface{}) { 63 log.Printf("[WARN ] %s\n", fmt.Sprintf(format, v)) 64 }