Documentation
¶
Overview ¶
file: client.go
Contains the Client struct definition and constructors, as well as getters to read some private fields like bucketName or cfg.
If multiple clients are required, it is advised to reuse the same AWS config.
file: get.go
Contains methods to get objects or metadata from S3, with or without a used-defined psk for encryption, passing the object key or a full path in a specific aws allowed style.
Requires "s3:GetObject" action allowed by IAM policy for objects inside the bucket, as defined by `read-{bucketName}-bucket` policies in dp-setup
file: healthcheck.go
Contains methods to get the health state of an S3 client from S3, by checking that the bucket exists in the provided region.
Requires "s3:ListBucket" action allowed by IAM policy for the bucket, as defined by `check-{bucketName}-bucket` policies in dp-setup
file: upload.go
Contains methods to efficiently upload files to S3 by using the high level SDK manager uploader methods, which automatically split large objects in chunks and uploads them concurrently.
Requires "s3:PutObject" action allowed by IAM policy for the bucket, as defined by `write-{bucketName}-bucket` policies in dp-setup
file: upload_multipart.go
Contains methods to upload files to S3 in chunks by using the low level SDK methods that give the caller control over the multipart uploading process.
Requires "s3:PutObject", "s3:GetObject" and "s3:AbortMultipartUpload" actions allowed by IAM policy for the bucket, as defined by `multipart-{bucketName}-bucket` policies in dp-setup
file: url.go
Contains string manipulation methods to obtain an S3 URL in the different styles supported by AWS and translate from one to another.
Index ¶
- Constants
- type Client
- func InstantiateClient(sdkClient S3SDKClient, cryptoClient S3CryptoClient, sdkUploader S3SDKUploader, ...) *Client
- func NewClient(ctx context.Context, region string, bucketName string) (*Client, error)
- func NewClientWithConfig(bucketName string, cfg aws.Config, optFns ...func(*s3.Options)) *Client
- func NewClientWithCredentials(ctx context.Context, region string, bucketName string, awsAccessKey string, ...) (*Client, error)
- func (cli *Client) BucketName() string
- func (cli *Client) CheckPartUploaded(ctx context.Context, req *UploadPartRequest) (bool, error)
- func (cli *Client) Checker(ctx context.Context, state *health.CheckState) error
- func (cli *Client) Config() aws.Config
- func (cli *Client) Delete(ctx context.Context, key string) error
- func (cli *Client) FileExists(ctx context.Context, key string) (bool, error)
- func (cli *Client) Get(ctx context.Context, key string) (io.ReadCloser, *int64, error)
- func (cli *Client) GetBucketPolicy(ctx context.Context, BucketName string) (*s3.GetBucketPolicyOutput, error)
- func (cli *Client) GetFromS3URL(ctx context.Context, rawURL string, style URLStyle) (io.ReadCloser, *int64, error)
- func (cli *Client) GetFromS3URLWithPSK(ctx context.Context, rawURL string, style URLStyle, psk []byte) (io.ReadCloser, *int64, error)
- func (cli *Client) GetWithPSK(ctx context.Context, key string, psk []byte) (io.ReadCloser, *int64, error)
- func (cli *Client) Head(ctx context.Context, key string) (*s3.HeadObjectOutput, error)
- func (cli *Client) ListObjects(ctx context.Context, BucketName string) (*s3.ListObjectsOutput, error)
- func (cli *Client) PutBucketPolicy(ctx context.Context, BucketName string, policy string) (*s3.PutBucketPolicyOutput, error)
- func (cli *Client) PutWithPSK(ctx context.Context, key *string, reader *bytes.Reader, psk []byte) error
- func (cli *Client) Upload(ctx context.Context, input *s3.PutObjectInput, ...) (*manager.UploadOutput, error)
- func (cli *Client) UploadPart(ctx context.Context, req *UploadPartRequest, payload []byte) (MultipartUploadResponse, error)
- func (cli *Client) UploadPartWithPsk(ctx context.Context, req *UploadPartRequest, payload []byte, psk []byte) (MultipartUploadResponse, error)
- func (cli *Client) UploadWithPSK(ctx context.Context, input *s3.PutObjectInput, psk []byte) (*manager.UploadOutput, error)
- func (cli *Client) ValidateBucket(ctx context.Context) error
- func (cli *Client) ValidateUploadInput(input *s3.PutObjectInput) (log.Data, error)
- type ErrChunkNumberNotFound
- type ErrChunkTooSmall
- type ErrListParts
- type ErrNotUploaded
- type ErrUnexpectedBucket
- type ErrUnexpectedRegion
- type MultipartUploadResponse
- type S3CryptoClient
- type S3CryptoUploader
- type S3Error
- type S3SDKClient
- type S3SDKUploader
- type S3Url
- func NewURL(region, bucketName, key string) (*S3Url, error)
- func NewURLWithScheme(scheme, region, bucketName, key string) (*S3Url, error)
- func ParseAliasVirtualHostedURL(avhURL string) (*S3Url, error)
- func ParseGlobalPathStyleURL(gpURL string) (*S3Url, error)
- func ParseGlobalVirtualHostedURL(gvhURL string) (*S3Url, error)
- func ParsePathStyleURL(pathStyleURL string) (*S3Url, error)
- func ParseURL(rawURL string, style URLStyle) (*S3Url, error)
- func ParseVirtualHostedURL(vhURL string) (*S3Url, error)
- type URLStyle
- type UploadPartRequest
Constants ¶
const ( // PathStyle example: 'https://s3-eu-west-1.amazonaws.com/myBucket/my/s3/object/key' PathStyle = iota // GlobalPathStyle example: 'https://s3.amazonaws.com/myBucket/my/s3/object/key' GlobalPathStyle // VirtualHostedStyle example: 'https://myBucket.s3-eu-west-1.amazonaws.com/my/s3/object/key' VirtualHostedStyle // GlobalVirtualHostedStyle example: 'https://myBucket.s3.amazonaws.com/my/s3/object/key' GlobalVirtualHostedStyle // AliasVirtualHostedStyle example: 'https://myBucket/my/s3/object/key' AliasVirtualHostedStyle )
Possible S3 URL format styles, as defined in https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html
const MsgHealthy = "S3 is healthy"
MsgHealthy is the message in the Check structure when S3 is healthy
const ServiceName = "S3"
ServiceName S3
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client: client with sdkClient, cryptoClient, sdkUploader, cryptoUploader, bucketName, region, mutexUploadID and cfg
func InstantiateClient ¶
func InstantiateClient(sdkClient S3SDKClient, cryptoClient S3CryptoClient, sdkUploader S3SDKUploader, cryptoUploader S3CryptoUploader, bucketName, region string, cfg aws.Config) *Client
InstantiateClient creates a new instance of S3 struct with the provided clients, bucket and region.
func NewClient ¶
NewClient creates a new S3 Client configured for the given region and bucket name. Note: This function will create a new config, if you already have a config, please use NewUploader instead Any error establishing the AWS config will be returned
func NewClientWithConfig ¶
NewClientWithConfig creates a new S3 Client configured for the given bucket name, using the provided config and region within it.
func NewClientWithCredentials ¶
func NewClientWithCredentials(ctx context.Context, region string, bucketName string, awsAccessKey string, awsSecretKey string) (*Client, error)
NewClientWithCredentials creates a new S3 Client configured for the given region and bucket name with creds. Note: This function will create a new config, if you already have a config, please use NewUploader instead Any error establishing the AWS config will be returned
func (*Client) BucketName ¶
BucketName returns the bucket name used by this S3 client
func (*Client) CheckPartUploaded ¶
CheckPartUploaded returns true only if the chunk corresponding to the provided chunkNumber has been uploaded. If all the chunks have been uploaded, we complete the upload operation. A boolean value which indicates if the call uploaded the last part is returned. If an error happens, it will be wrapped and returned.
func (*Client) Checker ¶
Checker validates that the S3 bucket exists, and updates the provided CheckState accordingly. Any error during the state update will be returned
func (*Client) Delete ¶ added in v3.3.0
Delete removes the object with the specified key from the S3 bucket.
func (*Client) FileExists ¶
func (*Client) Get ¶
Get returns an io.ReadCloser instance for the given path (inside the bucket configured for this client) and the content length (size in bytes). They 'key' parameter refers to the path for the file under the bucket.
The caller is responsible for closing the returned ReadCloser. For example, it may be closed in a defer statement: defer r.Close()
func (*Client) GetBucketPolicy ¶
func (*Client) GetFromS3URL ¶
func (cli *Client) GetFromS3URL(ctx context.Context, rawURL string, style URLStyle) (io.ReadCloser, *int64, error)
GetFromS3URL returns an io.ReadCloser instance and the content length (size in bytes) for the given S3 URL, in the format specified by URLStyle. More information about s3 URL styles: https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html If the URL defines a region (if provided) or bucket different from the one configured in this client, an error will be returned.
The caller is responsible for closing the returned ReadCloser. For example, it may be closed in a defer statement: defer r.Close()
func (*Client) GetFromS3URLWithPSK ¶
func (cli *Client) GetFromS3URLWithPSK(ctx context.Context, rawURL string, style URLStyle, psk []byte) (io.ReadCloser, *int64, error)
GetFromS3URLWithPSK returns an io.ReadCloser instance and the content length (size in bytes) for the given S3 URL, in the format specified by URLStyle, using the provided PSK for encryption. More information about s3 URL styles: https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html If the URL defines a region (if provided) or bucket different from the one configured in this client, an error will be returned.
The caller is responsible for closing the returned ReadCloser. For example, it may be closed in a defer statement: defer r.Close()
func (*Client) GetWithPSK ¶
func (cli *Client) GetWithPSK(ctx context.Context, key string, psk []byte) (io.ReadCloser, *int64, error)
GetWithPSK returns an io.ReadCloser instance for the given path (inside the bucket configured for this client) and the content length (size in bytes). It uses the provided PSK for encryption. The 'key' parameter refers to the path for the file under the bucket.
The caller is responsible for closing the returned ReadCloser. For example, it may be closed in a defer statement: defer r.Close()
func (*Client) Head ¶
Head returns a HeadObjectOutput containing an object metadata obtained from a HTTP HEAD call
func (*Client) ListObjects ¶
func (*Client) PutBucketPolicy ¶
func (*Client) PutWithPSK ¶
func (cli *Client) PutWithPSK(ctx context.Context, key *string, reader *bytes.Reader, psk []byte) error
PutWithPSK uploads the provided contents to the key in the bucket configured for this client, using the provided PSK. The 'key' parameter refers to the path for the file under the bucket.
func (*Client) Upload ¶
func (cli *Client) Upload(ctx context.Context, input *s3.PutObjectInput, options ...func(*manager.Uploader)) (*manager.UploadOutput, error)
Upload uploads a file to S3 using the AWS Manager, which will automatically split up large objects and upload them concurrently.
func (*Client) UploadPart ¶
func (cli *Client) UploadPart(ctx context.Context, req *UploadPartRequest, payload []byte) (MultipartUploadResponse, error)
UploadPart handles the uploading a file to AWS S3, into the bucket configured for this client
func (*Client) UploadPartWithPsk ¶
func (cli *Client) UploadPartWithPsk(ctx context.Context, req *UploadPartRequest, payload []byte, psk []byte) (MultipartUploadResponse, error)
UploadPartWithPsk handles the uploading a file to AWS S3, into the bucket configured for this client, using a user-defined psk
func (*Client) UploadWithPSK ¶
func (cli *Client) UploadWithPSK(ctx context.Context, input *s3.PutObjectInput, psk []byte) (*manager.UploadOutput, error)
UploadWithPSK uploads a file to S3 using cryptoclient, which allows you to encrypt the file with a given psk.
func (*Client) ValidateBucket ¶
ValidateBucket checks that the bucket exists and returns an error if it does not exist or there was some other error trying to get this information.
func (*Client) ValidateUploadInput ¶
ValidateUploadInput checks the upload input and returns an error if there is a bucket override mismatch or s3 key is not provided
type ErrChunkNumberNotFound ¶
type ErrChunkNumberNotFound struct {
S3Error
}
ErrChunkNumberNotFound if a chunk number could not be found in an existing multipart upload.
func NewChunkNumberNotFound ¶
func NewChunkNumberNotFound(err error, logData map[string]interface{}) *ErrChunkNumberNotFound
type ErrChunkTooSmall ¶
type ErrChunkTooSmall struct {
S3Error
}
func NewChunkTooSmallError ¶
func NewChunkTooSmallError(err error, logData map[string]interface{}) *ErrChunkTooSmall
type ErrListParts ¶
type ErrListParts struct {
S3Error
}
ErrListParts represents an error returned by S3 ListParts
func NewListPartsError ¶
func NewListPartsError(err error, logData map[string]interface{}) *ErrListParts
type ErrNotUploaded ¶
type ErrNotUploaded struct {
S3Error
}
ErrNotUploaded if an s3Key could not be found in ListMultipartUploads
func NewErrNotUploaded ¶
func NewErrNotUploaded(err error, logData map[string]interface{}) *ErrNotUploaded
type ErrUnexpectedBucket ¶
type ErrUnexpectedBucket struct {
S3Error
}
ErrUnexpectedBucket if a request tried to access an unexpected bucket
func NewUnexpectedBucketError ¶
func NewUnexpectedBucketError(err error, logData map[string]interface{}) *ErrUnexpectedBucket
type ErrUnexpectedRegion ¶
type ErrUnexpectedRegion struct {
S3Error
}
ErrUnexpectedRegion if a request tried to access an unexpected region
func NewUnexpectedRegionError ¶
func NewUnexpectedRegionError(err error, logData map[string]interface{}) *ErrUnexpectedRegion
type MultipartUploadResponse ¶
type S3CryptoClient ¶
type S3CryptoClient interface { UploadPartWithPSK(ctx context.Context, in *s3.UploadPartInput, psk []byte) (out *s3.UploadPartOutput, err error) GetObjectWithPSK(ctx context.Context, in *s3.GetObjectInput, psk []byte) (out *s3.GetObjectOutput, err error) PutObjectWithPSK(ctx context.Context, in *s3.PutObjectInput, psk []byte) (out *s3.PutObjectOutput, err error) }
S3CryptoClient represents the cryptoclient with methods required to upload parts with encryption
type S3CryptoUploader ¶
type S3CryptoUploader interface {
UploadWithPSK(ctx context.Context, in *s3.PutObjectInput, psk []byte) (out *manager.UploadOutput, err error)
}
S3CryptoUploader represents the s3crypto Uploader with methods required to upload parts with encryption
type S3Error ¶
type S3Error struct {
// contains filtered or unexported fields
}
S3Error is the s3 package's error type
type S3SDKClient ¶
type S3SDKClient interface { ListMultipartUploads(ctx context.Context, in *s3.ListMultipartUploadsInput, optFns ...func(*s3.Options)) (*s3.ListMultipartUploadsOutput, error) ListParts(ctx context.Context, in *s3.ListPartsInput, optFns ...func(*s3.Options)) (*s3.ListPartsOutput, error) CompleteMultipartUpload(ctx context.Context, in *s3.CompleteMultipartUploadInput, optFns ...func(*s3.Options)) (*s3.CompleteMultipartUploadOutput, error) CreateMultipartUpload(ctx context.Context, in *s3.CreateMultipartUploadInput, optFns ...func(*s3.Options)) (*s3.CreateMultipartUploadOutput, error) UploadPart(ctx context.Context, in *s3.UploadPartInput, optFns ...func(*s3.Options)) (*s3.UploadPartOutput, error) HeadBucket(ctx context.Context, in *s3.HeadBucketInput, optFns ...func(*s3.Options)) (*s3.HeadBucketOutput, error) HeadObject(ctx context.Context, in *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error) GetObject(ctx context.Context, in *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) GetBucketPolicy(ctx context.Context, in *s3.GetBucketPolicyInput, optFns ...func(*s3.Options)) (*s3.GetBucketPolicyOutput, error) PutBucketPolicy(ctx context.Context, in *s3.PutBucketPolicyInput, optFns ...func(*s3.Options)) (*s3.PutBucketPolicyOutput, error) ListObjects(ctx context.Context, in *s3.ListObjectsInput, optFns ...func(*s3.Options)) (*s3.ListObjectsOutput, error) DeleteObject(ctx context.Context, in *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) }
S3SDKClient represents the sdk client with methods required by dp-s3 client
type S3SDKUploader ¶
type S3SDKUploader interface {
Upload(ctx context.Context, in *s3.PutObjectInput, options ...func(*manager.Uploader)) (out *manager.UploadOutput, err error)
}
S3SDKUploader represents the sdk uploader with methods required by dp-s3 client
type S3Url ¶
S3Url represents an S3 URL with bucketName, key and region (optional). This struct is intended to be used for S3 URL string manipulation/translation in its possible format styles.
func NewURL ¶
NewURL instantiates a new S3Url struct with the provided region, bucket name and object key
func NewURLWithScheme ¶
NewURLWithScheme instantiates a new S3Url struct with the provided scheme, region, bucket and object key
func ParseAliasVirtualHostedURL ¶
ParseAliasVirtualHostedURL creates an S3Url struct from the provided dns-alias-virtual-hosted-style url string Example: 'https://myBucket/my/s3/object/key'
func ParseGlobalPathStyleURL ¶
ParseGlobalPathStyleURL creates an S3Url struct from the provided global-path-style url string Example: 'https://s3.amazonaws.com/myBucket/my/s3/object/key' This method is compatible with PathStyle format (if region is present in the URL, it will be ignored)
func ParseGlobalVirtualHostedURL ¶
ParseGlobalVirtualHostedURL creates an S3Url struct from the provided global-virtual-hosted-style url string Example: 'https://myBucket.s3.amazonaws.com/my/s3/object/key'
func ParsePathStyleURL ¶
ParsePathStyleURL creates an S3Url struct from the provided path-style url string Example: 'https://s3-eu-west-1.amazonaws.com/myBucket/my/s3/object/key'.
func ParseVirtualHostedURL ¶
ParseVirtualHostedURL creates an S3Url struct from the provided virtual-hosted-style url string Example: 'https://myBucket.s3-eu-west-1.amazonaws.com/my/s3/object/key'