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
|
package integrationtest
import (
"context"
"crypto/rand"
"fmt"
"github.com/aws/smithy-go/middleware"
"io"
"log"
"os"
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
)
// LoadConfigWithDefaultRegion loads the default configuration for the SDK, and
// falls back to a default region if one is not specified.
func LoadConfigWithDefaultRegion(defaultRegion string) (cfg aws.Config, err error) {
var lm aws.ClientLogMode
if strings.EqualFold(os.Getenv("AWS_DEBUG_REQUEST"), "true") {
lm |= aws.LogRequest
} else if strings.EqualFold(os.Getenv("AWS_DEBUG_REQUEST_BODY"), "true") {
lm |= aws.LogRequestWithBody
}
cfg, err = config.LoadDefaultConfig(context.Background(),
config.WithClientLogMode(lm),
config.WithAPIOptions([]func(*middleware.Stack) error{
RemoveOperationInputValidationMiddleware,
}),
config.WithDefaultRegion(defaultRegion),
)
if err != nil {
return cfg, err
}
return cfg, nil
}
type logger struct{}
func (logger) Logf(format string, args ...interface{}) {
log.Printf(format, args...)
}
// UniqueID returns a unique UUID-like identifier for use in generating
// resources for integration tests.
func UniqueID() string {
uuid := make([]byte, 16)
io.ReadFull(rand.Reader, uuid)
return fmt.Sprintf("%x", uuid)
}
|