Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions cmd/git-s3-push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions git-s3-push.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Repository struct {
}

type repoConfig struct {
Endpoint string
S3Region string
S3Bucket string
Public bool
Expand Down
9 changes: 9 additions & 0 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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,
Expand Down