func (rd *S3BucketDeleter) AddResourceNames(ns ...arn.ResourceName) {
	rd.ResourceNames = append(rd.ResourceNames, ns...)
}
AddResourceNames adds S3 bucket names to ResourceNames
package deleter
import (
	"fmt"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/aws/aws-sdk-go/service/s3/s3iface"
	"github.com/coreos/grafiti/arn"
	"github.com/sirupsen/logrus"
)
type S3ObjectDeleter struct {
	Client            s3iface.S3API
	ResourceType      arn.ResourceType
	BucketName        arn.ResourceName
	ObjectIdentifiers []*s3.ObjectIdentifier
}
func (rd *S3ObjectDeleter) String() string {
	return fmt.Sprintf(`{"Type": "%s", "BucketName": "%s", "ObjectIdentifiers": %v}`, rd.ResourceType, rd.BucketName, rd.ObjectIdentifiers)
}
func (rd *S3ObjectDeleter) GetClient() s3iface.S3API {
	if rd.Client == nil {
		rd.Client = s3.New(setUpAWSSession())
	}
	return rd.Client
}
func (rd *S3ObjectDeleter) AddResourceNames(keys ...arn.ResourceName) {
	for _, key := range keys {
		rd.ObjectIdentifiers = append(rd.ObjectIdentifiers, &s3.ObjectIdentifier{Key: key.AWSString()})
	}
}
func (rd *S3ObjectDeleter) DeleteResources(cfg *DeleteConfig) error {
	if rd.BucketName == "" || len(rd.ObjectIdentifiers) == 0 {
		return nil
	}
	fmtStr := "Deleted S3 Object"
	if cfg.DryRun {
		for _, o := range rd.ObjectIdentifiers {
			fmt.Printf("%s %s %s from S3 Bucket %s\n", drStr, fmtStr, aws.StringValue(o.Key), rd.BucketName)
		}
		return nil
	}
	params := &s3.DeleteObjectsInput{
		Bucket: rd.BucketName.AWSString(),
		Delete: &s3.Delete{Objects: rd.ObjectIdentifiers},
	}
	ctx := aws.BackgroundContext()
	resp, err := rd.GetClient().DeleteObjectsWithContext(ctx, params)
	if err != nil {
		for _, o := range rd.ObjectIdentifiers {
			cfg.logRequestError(arn.S3ObjectRType, aws.StringValue(o.Key), err, logrus.Fields{
				"parent_resource_type": arn.S3BucketRType,
				"parent_resource_name": rd.BucketName,
			})
		}
		if cfg.IgnoreErrors {
			return nil
		}
		return err
	}
	for _, o := range resp.Deleted {
		keyStr := aws.StringValue(o.Key)
		cfg.logRequestSuccess(arn.S3ObjectRType, keyStr, logrus.Fields{
			"parent_resource_type": arn.S3BucketRType,
			"parent_resource_name": rd.BucketName,
		})
		fmt.Printf("%s %s from S3 Bucket %s\n", fmtStr, keyStr, rd.BucketName)
	}
	return nil
}
func (rd *S3ObjectDeleter) RequestS3ObjectsFromBucket() ([]*s3.Object, error) {
	objs := make([]*s3.Object, 0)
	params := &s3.ListObjectsV2Input{
		Bucket: rd.BucketName.AWSString(),
	}
	for {
		ctx := aws.BackgroundContext()
		resp, err := rd.GetClient().ListObjectsV2WithContext(ctx, params)
		if err != nil {
			fmt.Printf("{\"error\": \"%s\"}\n", err)
			return objs, err
		}
		objs = append(objs, resp.Contents...)
		if !aws.BoolValue(resp.IsTruncated) {
			break
		}
		params.ContinuationToken = resp.ContinuationToken
	}
	return objs, nil
}
type S3BucketDeleter struct {
	Client        s3iface.S3API
	ResourceType  arn.ResourceType
	ResourceNames arn.ResourceNames
}
func (rd *S3BucketDeleter) String() string {
	return fmt.Sprintf(`{"Type": "%s", "ResourceNames": %v}`, rd.ResourceType, rd.ResourceNames)
}
func (rd *S3BucketDeleter) GetClient() s3iface.S3API {
	if rd.Client == nil {
		rd.Client = s3.New(setUpAWSSession())
	}
	return rd.Client
}