s3

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	CreationDate *time.Time
	Name         *string
}

Bucket contains information about an S3 bucket

type ObjectIdentifier

type ObjectIdentifier struct {
	Key       *string
	VersionID *string
}

ObjectIdentifier is used to identify a specific S3 object and version

type ObjectVersion

type ObjectVersion struct {
	ObjectIdentifier
	IsDeleteMarker bool
}

ObjectVersion defines an object and version information from an S3 bucket

type S3API

type S3API interface {
	ListBuckets(ctx context.Context,
		params *s3.ListBucketsInput,
		optFns ...func(*s3.Options)) (*s3.ListBucketsOutput, error)

	CreateBucket(ctx context.Context,
		params *s3.CreateBucketInput,
		optFns ...func(*s3.Options)) (*s3.CreateBucketOutput, error)

	PutBucketVersioning(ctx context.Context,
		params *s3.PutBucketVersioningInput,
		optFns ...func(*s3.Options)) (*s3.PutBucketVersioningOutput, error)

	PutObject(ctx context.Context,
		params *s3.PutObjectInput,
		optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)

	GetBucketLocation(ctx context.Context,
		params *s3.GetBucketLocationInput,
		optFns ...func(*s3.Options)) (*s3.GetBucketLocationOutput, error)

	ListObjectsV2(ctx context.Context,
		params *s3.ListObjectsV2Input,
		optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)

	ListObjectVersions(ctx context.Context,
		params *s3.ListObjectVersionsInput,
		optFns ...func(*s3.Options)) (*s3.ListObjectVersionsOutput, error)

	DeleteObjects(ctx context.Context,
		params *s3.DeleteObjectsInput,
		optFns ...func(*s3.Options)) (*s3.DeleteObjectsOutput, error)
}

S3API defines the interface for AWS S3 SDK functions

type Service

type Service interface {
	// ListBuckets loads buckets into memory
	GetAllBuckets(ctx context.Context) ([]Bucket, error)

	// CreateBucketSimple creates a new, simple S3 bucket in the current/default region
	//
	// (This function is mainly used in s3-nuke for testing)
	CreateBucketSimple(ctx context.Context, bucketName string, region string, versioned bool) error

	// PutBucketObject puts an object in an S3 bucket
	//
	// returns Etag, VersionID, and Error
	// (This function is mainly used in s3-nuke for testing)
	PutObjectSimple(ctx context.Context, bucketName string, keyName string, body io.Reader) (*string, *string, error)

	// GetBucketRegion will return the region of a bucket
	GetBucektRegion(ctx context.Context, bucketName string) (string, error)

	// ListObjects will return some or all (up to 1,000) of the objects in a bucket with each request.
	// Objects are returned sorted in an ascending order of the respective key names in the list.
	// use continuationToken to list the next page of objects. For first call, set continuationToken to nil
	//
	// prefix limits the response to keys that begin with the specified prefix. Set to nil if not used.
	//
	// returns:
	// `[]string“ contains the slice of keys returned by this request
	// `*string` contains the continuation token, if any
	// `error` is returned not nil if an error has occurred requesting the list
	ListObjects(ctx context.Context, bucketName string, continuationToken *string, prefix *string) ([]string, *string, error)

	// ListObjectVersions will return version information
	//
	// returns:
	// `[]ObjectVersion` contains object version information
	// `*string` contains the keyMarker which marks the last key returned in a truncated response
	// `*string` contains the versionIDMarker which marks the last version of the key returned in a truncated response
	// `error` is returned not nil if an error has occurred requesting the object version list
	ListObjectVersions(ctx context.Context, bucketName string, keyMarker *string, versionIDMarker *string, prefix *string) ([]ObjectVersion, *string, *string, error)

	// DeleteObjects will bulk delete up to 1000 objects in one call
	//
	// returns:
	// `[]ObjectIdentifier` contains list of objects deleted
	// `error` is returned not nil if an error has occurred requesting the object deletion
	DeleteObjects(ctx context.Context, bucketName string, objects []ObjectIdentifier) ([]ObjectIdentifier, error)
}

Service defines functions related to S3 operations

func NewService

func NewService(opts ...ServiceOption) Service

NewService returns an initialized S3Service

type ServiceOption

type ServiceOption func(s *service)

ServiceOption is used with NewS3Service and configures the newly created s3Service

func WithAWSEndpoint

func WithAWSEndpoint(awsEndpoint string) ServiceOption

WithAWSEndpoint sets endpoint to be used by the AWS client This cannot be used with WithS3API

func WithRegion

func WithRegion(region string) ServiceOption

WithRegion sets the AWS client region

func WithS3API

func WithS3API(s3Client S3API) ServiceOption

WithS3API should be used if you want to initialize your own S3 client (such as in cases of a mock S3 client for testing) This cannot be used with WithAWSEndpoint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL