allow s3 vfs scheme and sse to be configurable

This commit is contained in:
andrewsykim 2018-04-01 23:05:11 -04:00
parent 973397f28a
commit 2947bb1b9e
1 changed files with 19 additions and 3 deletions

View File

@ -39,6 +39,12 @@ type S3Path struct {
region string
key string
etag *string
// scheme is configurable in case an S3 compatible custom
// endpoint is specified
scheme string
// sse specifies if server side encryption should be enabled
sse bool
}
var _ Path = &S3Path{}
@ -49,7 +55,7 @@ type S3Acl struct {
RequestACL *string
}
func newS3Path(s3Context *S3Context, bucket string, key string) *S3Path {
func newS3Path(s3Context *S3Context, scheme string, bucket string, key string, sse bool) *S3Path {
bucket = strings.TrimSuffix(bucket, "/")
key = strings.TrimPrefix(key, "/")
@ -57,11 +63,13 @@ func newS3Path(s3Context *S3Context, bucket string, key string) *S3Path {
s3Context: s3Context,
bucket: bucket,
key: key,
scheme: scheme,
sse: sse,
}
}
func (p *S3Path) Path() string {
return "s3://" + p.bucket + "/" + p.key
return p.scheme + "://" + p.bucket + "/" + p.key
}
func (p *S3Path) Bucket() string {
@ -106,6 +114,8 @@ func (p *S3Path) Join(relativePath ...string) Path {
s3Context: p.s3Context,
bucket: p.bucket,
key: joined,
scheme: p.scheme,
sse: p.sse,
}
}
@ -124,7 +134,9 @@ func (p *S3Path) WriteFile(data io.ReadSeeker, aclObj ACL) error {
request.Body = data
request.Bucket = aws.String(p.bucket)
request.Key = aws.String(p.key)
request.ServerSideEncryption = aws.String(sse)
if p.sse {
request.ServerSideEncryption = aws.String(sse)
}
acl := os.Getenv("KOPS_STATE_S3_ACL")
acl = strings.TrimSpace(acl)
@ -250,6 +262,8 @@ func (p *S3Path) ReadDir() ([]Path, error) {
bucket: p.bucket,
key: key,
etag: o.ETag,
scheme: p.scheme,
sse: p.sse,
}
paths = append(paths, child)
}
@ -286,6 +300,8 @@ func (p *S3Path) ReadTree() ([]Path, error) {
bucket: p.bucket,
key: key,
etag: o.ETag,
scheme: p.scheme,
sse: p.sse,
}
paths = append(paths, child)
}