github.com/webdestroya/awsmocker@v0.2.6/awsconfig.go (about) 1 package awsmocker 2 3 import ( 4 "bytes" 5 "context" 6 "net/http" 7 "net/url" 8 "time" 9 10 "github.com/aws/aws-sdk-go-v2/aws" 11 awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" 12 "github.com/aws/aws-sdk-go-v2/config" 13 "github.com/aws/aws-sdk-go-v2/credentials" 14 ) 15 16 // If your application is setup to where you can provide an aws.Config object for your clients, 17 // then using the one provided by this method will make testing much easier. 18 func (m *mocker) buildAwsConfig() aws.Config { 19 20 httpClient := awshttp.NewBuildableClient().WithTimeout(10 * time.Second).WithTransportOptions(func(t *http.Transport) { 21 proxyUrl, _ := url.Parse(m.httpServer.URL) 22 t.Proxy = http.ProxyURL(proxyUrl) 23 24 // remove the need for CA bundle? 25 // t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} 26 }) 27 28 cfg, err := config.LoadDefaultConfig(context.TODO(), 29 config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("XXfakekey", "XXfakesecret", "xxtoken")), 30 config.WithDefaultRegion(DefaultRegion), 31 config.WithHTTPClient(httpClient), 32 config.WithCustomCABundle(bytes.NewReader(caCert)), 33 config.WithRetryer(func() aws.Retryer { 34 return aws.NopRetryer{} 35 }), 36 ) 37 if err != nil { 38 panic(err) 39 } 40 41 return cfg 42 }