From 92c36b07739af2b54b8f95875910b1d7fbc9a6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominika=20Ka=C5=82afut?= Date: Tue, 5 Oct 2021 18:23:46 +0200 Subject: [PATCH 1/2] Adding custom endpoint support --- cmd/git-s3-push.go | 1 + git-s3-push.go | 1 + s3.go | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/cmd/git-s3-push.go b/cmd/git-s3-push.go index 6ca4157..4967c72 100644 --- a/cmd/git-s3-push.go +++ b/cmd/git-s3-push.go @@ -16,6 +16,7 @@ func main() { } repo.ReadConfigFile() + flag.StringVar(&repo.Config.Endpoint, "endpoint", repo.Config.Endpoint, "Custom S3 endpoint") flag.StringVar(&repo.Config.S3Bucket, "b", repo.Config.S3Bucket, "Destination S3 bucket name") flag.StringVar(&repo.Config.S3Region, "r", repo.Config.S3Region, "AWS region of destination bucket") flag.StringVar(&repo.Config.Prefix, "p", repo.Config.Prefix, "Prefix location in bucket to push to") diff --git a/git-s3-push.go b/git-s3-push.go index 977a305..e8c12ca 100644 --- a/git-s3-push.go +++ b/git-s3-push.go @@ -31,6 +31,7 @@ type Repository struct { } type repoConfig struct { + Endpoint string S3Region string S3Bucket string Public bool diff --git a/s3.go b/s3.go index dd35847..a6d3d92 100644 --- a/s3.go +++ b/s3.go @@ -15,6 +15,7 @@ const cannedAclPrivate = "private" // S3Uploader manages S3 uploads to a specific bucket type S3Uploader struct { + endpoint string bucketName *string prefix string public bool @@ -35,13 +36,20 @@ func InitS3Uploader(config repoConfig) (*S3Uploader, error) { uploader.bucketName = aws.String(config.S3Bucket) uploader.public = config.Public uploader.prefix = config.Prefix + uploader.endpoint = config.Endpoint if len(uploader.prefix) > 0 && uploader.prefix[len(uploader.prefix)-1:] != "/" { uploader.prefix = uploader.prefix + "/" } s3config := aws.Config{Region: aws.String(config.S3Region)} + + if uploader.endpoint != "" { + s3config = aws.Config{Region: aws.String(config.S3Region), Endpoint: aws.String(uploader.endpoint)} + } + s3Session, err := session.NewSession(&s3config) + if err != nil { return nil, err } @@ -60,6 +68,7 @@ func InitS3Uploader(config repoConfig) (*S3Uploader, error) { func (uploader S3Uploader) deleteFile(path string) error { key := aws.String(uploader.prefix + path) + _, err := uploader.s3Svc.DeleteObject(&s3.DeleteObjectInput{ Bucket: uploader.bucketName, Key: key, From ccdb36b4c297f4086247ab99a667fe56150ed9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominika=20Ka=C5=82afut?= Date: Wed, 6 Oct 2021 15:56:41 +0200 Subject: [PATCH 2/2] Updated README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2953c59..c33cd5c 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,9 @@ Authentication credentials are taken from the standard AWS environment variables The `-save` flag stores the bucket name and region so you can push to the same location by just running: -```$ git-s3-push``` +```$ git-s3-push```. + +The `-endpoint` can be used to override the standard AWS S3 endpoint by custom implementations provided, for example, by MinIO or Ceph. The `-public` flag can be used to make the files uploaded to your bucket publicly readable. When running without the `-public` flag, pushed files are stored privately.