package tools import ( "context" "fmt" "os" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/ec2/types" ) func AWS() *awstool { ctx := context.TODO() accessKeyID := os.Getenv("AWS_ACCESS_KEY_ID") secretAccessKey := os.Getenv("AWS_SECRET_ACCESS_KEY") sessionToken := os.Getenv("AWS_SESSION_TOKEN") staticProvider := credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, sessionToken) cfg, err := config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(staticProvider), config.WithRegion(os.Getenv("AWS_REGION")), ) if err != nil { log.Write([]byte(fmt.Sprintf("unable to load SDK config, %v", err))) } return &awstool{ cfg: cfg, } } type ( awstool struct { cfg aws.Config } s3 struct { aws *awstool } ec2 struct { aws *awstool } cloudformation struct { aws *awstool } imagebuilder struct { aws *awstool } ecs struct { aws *awstool } eks struct { aws *awstool } ) func (t *awstool) S3() *s3 { return &s3{aws: t} } func (t *awstool) EC2() *ec2 { return &ec2{aws: t} } func (t *awstool) CloudFormation() *cloudformation { return &cloudformation{aws: t} } func (t *awstool) ImageBuilder() *imagebuilder { return &imagebuilder{aws: t} } func (t *awstool) ECS() *ecs { return &ecs{aws: t} } func (t *awstool) EKS() *eks { return &eks{aws: t} } func (t *awstool) Filter(filters map[string][]string) []types.Filter { filter := []types.Filter{} for k, v := range filters { filter = append(filter, types.Filter{ Name: aws.String(k), Values: v, }) } return filter } func (t *s3) Put(src, dst string) error { return nil } func (t *s3) Get(src, dst string) error { return nil } func (t *s3) ListObjects(bucket, path string) error { return nil } func (t *s3) ListBuckets() error { return nil } func (t *ec2) FindLatestAMI() error { return nil } func (t *ec2) Create() error { return nil } func (t *ec2) Stop() error { return nil } func (t *ec2) Start() error { return nil } func (t *ec2) Terminate() error { return nil } func (t *cloudformation) CreateStack() {} func (t *cloudformation) UpdateStack() {} func (t *cloudformation) DeleteStack() {}