s3

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

README

aws-s3

Utility to sync files with AWS S3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotDir = errors.New("not a directory")
)
View Source
var OperationColored = map[Operation]string{
	OperationUpload: fmt.Sprintf("\x1b[34m%s\x1b[0m", string(OperationUpload)),
	OperationDelete: fmt.Sprintf("\x1b[31m%s\x1b[0m", string(OperationDelete)),
	OperationIgnore: fmt.Sprintf("\x1b[33m%s\x1b[0m", string(OperationIgnore)),
}

Functions

func IsS3Url

func IsS3Url(location *string) bool

func SplitS3Url

func SplitS3Url(location *string) (string, string, error)

Types

type Client

type Client struct {
	*awss3.Client
	// contains filtered or unexported fields
}

func NewFromConfig

func NewFromConfig(cfg aws.Config, log *log.Logger, region string) *Client

func (*Client) PrepareSync

func (s3 *Client) PrepareSync(params *PrepareSyncInput) (*PreparedSync, error)

func (*Client) Sync

func (s3 *Client) Sync(ctx context.Context, params *SyncInput, optFns ...func(*awss3.Options)) (*SyncOutput, error)

type ExecuteInput

type ExecuteInput struct {

	// Whether or not to perform any write operations
	DryRun bool

	// The bucket name to which the SYNC operation was initiated. When using this API
	// with an access point, you must direct requests to the access point hostname. The
	// access point hostname takes the form
	// AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this
	// operation with an access point through the AWS SDKs, you provide the access
	// point ARN in place of the bucket name. For more information about access point
	// ARNs, see Using Access Points
	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/using-access-points.html) in
	// the Amazon Simple Storage Service Developer Guide. When using this API with
	// Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname.
	// The S3 on Outposts hostname takes the form
	// AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using
	// this operation using S3 on Outposts through the AWS SDKs, you provide the
	// Outposts bucket ARN in place of the bucket name. For more information about S3
	// on Outposts ARNs, see Using S3 on Outposts
	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/S3onOutposts.html) in the
	// Amazon Simple Storage Service Developer Guide.
	//
	// This member is required.
	Bucket *string

	// Confirms that the requester knows that they will be charged for the request.
	// Bucket owners need not specify this parameter in their requests. For information
	// about downloading objects from requester pays buckets, see Downloading Objects
	// in Requestor Pays Buckets
	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html)
	// in the Amazon S3 Developer Guide.
	RequestPayer types.RequestPayer

	// The canned ACL to apply to the object. For more information, see Canned ACL
	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#CannedACL).
	// This action is not supported by Amazon S3 on Outposts.
	ACL types.ObjectCannedACL

	// Specifies whether Amazon S3 should use an S3 Bucket Key for object encryption
	// with server-side encryption using AWS KMS (SSE-KMS). Setting this header to true
	// causes Amazon S3 to use an S3 Bucket Key for object encryption with SSE-KMS.
	// Specifying this header with a PUT operation doesn't affect bucket-level settings
	// for S3 Bucket Key.
	BucketKeyEnabled bool

	// Can be used to specify caching behavior along the request/reply chain. For more
	// information, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9).
	CacheControl *string

	// Specifies presentational information for the object. For more information, see
	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1
	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1).
	ContentDisposition *string

	// Specifies what content encodings have been applied to the object and thus what
	// decoding mechanisms must be applied to obtain the media-type referenced by the
	// Content-Type header field. For more information, see
	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11).
	ContentEncoding *string

	// The language the content is in.
	ContentLanguage *string

	// Size of the body in bytes. This parameter is useful when the size of the body
	// cannot be determined automatically. For more information, see
	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13).
	ContentLength int64

	// The account id of the expected bucket owner. If the bucket is owned by a
	// different account, the request will fail with an HTTP 403 (Access Denied) error.
	ExpectedBucketOwner *string

	// The date and time at which the object is no longer cacheable. For more
	// information, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
	// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21).
	Expires *time.Time

	// Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. This
	// action is not supported by Amazon S3 on Outposts.
	GrantFullControl *string

	// Allows grantee to read the object data and its metadata. This action is not
	// supported by Amazon S3 on Outposts.
	GrantRead *string

	// Allows grantee to read the object ACL. This action is not supported by Amazon S3
	// on Outposts.
	GrantReadACP *string

	// Allows grantee to write the ACL for the applicable object. This action is not
	// supported by Amazon S3 on Outposts.
	GrantWriteACP *string

	// A map of metadata to store with the object in S3.
	Metadata map[string]string

	// Specifies whether a legal hold will be applied to this object. For more
	// information about S3 Object Lock, see Object Lock
	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock.html).
	ObjectLockLegalHoldStatus types.ObjectLockLegalHoldStatus

	// The Object Lock mode that you want to apply to this object.
	ObjectLockMode types.ObjectLockMode

	// The date and time when you want this object's Object Lock to expire.
	ObjectLockRetainUntilDate *time.Time

	// Specifies the algorithm to use to when encrypting the object (for example,
	// AES256).
	SSECustomerAlgorithm *string

	// Specifies the customer-provided encryption key for Amazon S3 to use in
	// encrypting data. This value is used to store the object and then it is
	// discarded; Amazon S3 does not store the encryption key. The key must be
	// appropriate for use with the algorithm specified in the
	// x-amz-server-side-encryption-customer-algorithm header.
	SSECustomerKey *string

	// Specifies the 128-bit MD5 digest of the encryption key according to RFC 1321.
	// Amazon S3 uses this header for a message integrity check to ensure that the
	// encryption key was transmitted without error.
	SSECustomerKeyMD5 *string

	// Specifies the AWS KMS Encryption Context to use for object encryption. The value
	// of this header is a base64-encoded UTF-8 string holding JSON with the encryption
	// context key-value pairs.
	SSEKMSEncryptionContext *string

	// If x-amz-server-side-encryption is present and has the value of aws:kms, this
	// header specifies the ID of the AWS Key Management Service (AWS KMS) symmetrical
	// customer managed customer master key (CMK) that was used for the object. If the
	// value of x-amz-server-side-encryption is aws:kms, this header specifies the ID
	// of the symmetric customer managed AWS KMS CMK that will be used for the object.
	// If you specify x-amz-server-side-encryption:aws:kms, but do not provide
	// x-amz-server-side-encryption-aws-kms-key-id, Amazon S3 uses the AWS managed CMK
	// in AWS to protect the data.
	SSEKMSKeyId *string

	// The server-side encryption algorithm used when storing this object in Amazon S3
	// (for example, AES256, aws:kms).
	ServerSideEncryption types.ServerSideEncryption

	// By default, Amazon S3 uses the STANDARD Storage Class to store newly created
	// objects. The STANDARD storage class provides high durability and high
	// availability. Depending on performance needs, you can specify a different
	// Storage Class. Amazon S3 on Outposts only uses the OUTPOSTS Storage Class. For
	// more information, see Storage Classes
	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html) in
	// the Amazon S3 Service Developer Guide.
	StorageClass types.StorageClass

	// The tag-set for the object. The tag-set must be encoded as URL Query parameters.
	// (For example, "Key1=Value1")
	Tagging *string

	// Indicates whether S3 Object Lock should bypass Governance-mode restrictions to
	// process this operation.
	BypassGovernanceRetention bool

	// The concatenation of the authentication device's serial number, a space, and the
	// value that is displayed on your authentication device. Required to permanently
	// delete a versioned object if versioning is configured with MFA delete enabled.
	MFA *string
}

type FileInfo

type FileInfo struct {
	Exists       bool
	Key          string
	Size         int64
	LastModified time.Time
	Base         string
}

type Operation

type Operation string
const (
	OperationUpload Operation = "upload"
	OperationDelete Operation = "delete"
	OperationIgnore Operation = "ignore"
)

type PrepareSyncInput

type PrepareSyncInput struct {
	// Path to local Source location.
	Source *string

	// S3 URL to destination (e.g.: s3://bucketname/prefix/).
	Destination *string

	// KeyPrefix is used to mutate (nested) prefixes when adding remote (destination) files to the buffer.
	KeyPrefix *string

	// Force upload, even if the local and remote versions seem the same.
	ForceUpload bool

	// Print verbose output when listing the files to upload.
	Verbose bool
}

type PreparedSync

type PreparedSync struct {
	ForceUpload bool
	Verbose     bool
	// contains filtered or unexported fields
}

func (*PreparedSync) Add

func (ps *PreparedSync) Add(params *PrepareSyncInput) error

func (*PreparedSync) Execute

func (ps *PreparedSync) Execute(ctx context.Context, params *ExecuteInput, optFns ...func(*awss3.Options)) (*SyncOutput, error)

type SyncFileInfo

type SyncFileInfo struct {
	Key string

	ForceUpload bool
	Verbose     bool

	Source      FileInfo
	Destination FileInfo
}

func (*SyncFileInfo) Op

func (sfi *SyncFileInfo) Op() (Operation, string)

func (*SyncFileInfo) OpColored

func (sfi *SyncFileInfo) OpColored() (string, string)

func (*SyncFileInfo) String

func (sfi *SyncFileInfo) String() string

type SyncInput

type SyncInput struct {
	ExecuteInput
	PrepareSyncInput
}

type SyncOutput

type SyncOutput struct {

	// TODO Documentation
	Files []*SyncFileInfo

	// The amount of files changed.
	// Upload and delete actions both count for +1 change
	Changes int
}

Jump to

Keyboard shortcuts

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