From 2947bb1b9e80d75585525469bb8180a506851caf Mon Sep 17 00:00:00 2001 From: andrewsykim Date: Sun, 1 Apr 2018 23:05:11 -0400 Subject: [PATCH] allow s3 vfs scheme and sse to be configurable --- util/pkg/vfs/s3fs.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/util/pkg/vfs/s3fs.go b/util/pkg/vfs/s3fs.go index 1a86652781..f2929e4306 100644 --- a/util/pkg/vfs/s3fs.go +++ b/util/pkg/vfs/s3fs.go @@ -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) }