github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/fn/common/api.go (about) 1 package common 2 3 import ( 4 "crypto/tls" 5 "fmt" 6 "net/http" 7 8 httptransport "github.com/go-openapi/runtime/client" 9 "github.com/go-openapi/strfmt" 10 f_common "github.com/iron-io/functions/common" 11 fnclient "github.com/iron-io/functions_go/client" 12 ) 13 14 func ApiClient() *fnclient.Functions { 15 tr := &http.Transport{ 16 TLSClientConfig: &tls.Config{InsecureSkipVerify: SSL_SKIP_VERIFY}, 17 } 18 cl := &http.Client{Transport: tr} 19 20 transport := httptransport.NewWithClient(HOST, API_VERSION, []string{SCHEME}, cl) 21 22 if JWT_AUTH_KEY != "" { 23 jwtToken, err := f_common.GetJwt(JWT_AUTH_KEY, 60*60) 24 if err != nil { 25 fmt.Println(fmt.Errorf("unexpected error: %s", err)) 26 } else { 27 transport.DefaultAuthentication = httptransport.BearerToken(jwtToken) 28 } 29 } 30 31 // create the API client, with the transport 32 client := fnclient.New(transport, strfmt.Default) 33 34 return client 35 }