Compare commits

..

4 Commits

Author SHA1 Message Date
Andrea Spacca
ce043efca0 Merge pull request #249 from n8225/addS3PathStyle
Add support for S3 path style URLS.
2019-07-21 18:05:05 +02:00
nrew225
6cb2de3cff Add support for S3 path style URLS. 2019-07-21 09:29:01 -05:00
Andrea Spacca
58edf68fd7 no need for abs path flag param 2019-07-16 21:23:19 +02:00
Andrea Spacca
2e41852860 fix resolved url 2019-07-16 20:51:31 +02:00
7 changed files with 27 additions and 21 deletions

View File

@@ -165,6 +165,7 @@ aws-secret-key | aws access key | | AWS_SECRET_KEY
bucket | aws bucket | | BUCKET
s3-region | region of the s3 bucket | eu-west-1 | S3_REGION
s3-no-multipart | disables s3 multipart upload | false | |
s3-path-style | Forces path style URLs, required for Minio. | false | |
basedir | path storage for local/gdrive provider| |
gdrive-client-json-filepath | path to oauth client json config for gdrive provider| |
gdrive-local-config-path | path to store local transfer.sh config cache for gdrive provider| |

View File

@@ -130,6 +130,10 @@ var globalFlags = []cli.Flag{
Name: "s3-no-multipart",
Usage: "Disables S3 Multipart Puts",
},
cli.BoolFlag{
Name: "s3-path-style",
Usage: "Forces path style URLs, required for Minio.",
},
cli.StringFlag{
Name: "gdrive-client-json-filepath",
Usage: "",
@@ -339,7 +343,7 @@ func New() *Cmd {
panic("secret-key not set.")
} else if bucket := c.String("bucket"); bucket == "" {
panic("bucket not set.")
} else if storage, err := server.NewS3Storage(accessKey, secretKey, bucket, c.String("s3-region"), c.String("s3-endpoint"), logger, c.Bool("s3-no-multipart")); err != nil {
} else if storage, err := server.NewS3Storage(accessKey, secretKey, bucket, c.String("s3-region"), c.String("s3-endpoint"), logger, c.Bool("s3-no-multipart"), c.Bool("s3-path-style")); err != nil {
panic(err)
} else {
options = append(options, server.UseStorage(storage))

2
go.mod
View File

@@ -8,7 +8,7 @@ require (
github.com/aws/aws-sdk-go v1.20.6
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329
github.com/dutchcoders/transfer.sh-web v0.0.0-20190520063132-37110d436c89
github.com/dutchcoders/transfer.sh-web v0.0.0-20190716184912-96e06a2276ba
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/fatih/color v1.7.0
github.com/garyburd/redigo v1.6.0 // indirect

2
go.sum
View File

@@ -17,6 +17,8 @@ github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329 h1:ERqCk
github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329/go.mod h1:G5qOfE5bQZ5scycLpB7fYWgN4y3xdfXo+pYWM8z2epY=
github.com/dutchcoders/transfer.sh-web v0.0.0-20190520063132-37110d436c89 h1:FJc5t2SEtRmLXDWxHFQG4QB98Vqr7/60cIiUT2F5yAA=
github.com/dutchcoders/transfer.sh-web v0.0.0-20190520063132-37110d436c89/go.mod h1:UjR1zlrq/R2Sef7e4q3TeJm4HcbLh4vRzlCEGJP+wLg=
github.com/dutchcoders/transfer.sh-web v0.0.0-20190716184912-96e06a2276ba h1:474BcGUqYKnxg49p7O7i3m9EuFfOag+OtPw5b/nmGVk=
github.com/dutchcoders/transfer.sh-web v0.0.0-20190716184912-96e06a2276ba/go.mod h1:UjR1zlrq/R2Sef7e4q3TeJm4HcbLh4vRzlCEGJP+wLg=
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=

View File

@@ -157,9 +157,9 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
}
relativeURL, _ := url.Parse(path.Join(s.proxyPath, token, filename))
resolvedURL := resolveURL(r, getURL(r).ResolveReference(relativeURL), true)
resolvedURL := resolveURL(r, relativeURL)
relativeURLGet, _ := url.Parse(path.Join(s.proxyPath, getPathPart, token, filename))
resolvedURLGet := resolveURL(r, getURL(r).ResolveReference(relativeURLGet), true)
resolvedURLGet := resolveURL(r, relativeURLGet)
var png []byte
png, err = qrcode.Encode(resolvedURL, qrcode.High, 150)
if err != nil {
@@ -499,15 +499,13 @@ func (s *Server) putHandler(w http.ResponseWriter, r *http.Request) {
relativeURL, _ := url.Parse(path.Join(s.proxyPath, token, filename))
deleteURL, _ := url.Parse(path.Join(s.proxyPath, token, filename, metadata.DeletionToken))
w.Header().Set("X-Url-Delete", resolveURL(r, deleteURL, true))
w.Header().Set("X-Url-Delete", resolveURL(r, deleteURL))
fmt.Fprint(w, resolveURL(r, relativeURL, false))
fmt.Fprint(w, resolveURL(r, relativeURL))
}
func resolveURL(r *http.Request, u *url.URL, absolutePath bool) string {
if absolutePath {
r.URL.Path = ""
}
func resolveURL(r *http.Request, u *url.URL) string {
r.URL.Path = ""
return getURL(r).ResolveReference(u).String()
}

View File

@@ -3,10 +3,6 @@ package server
import (
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"io"
"io/ioutil"
"log"
@@ -16,7 +12,11 @@ import (
"path/filepath"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"golang.org/x/net/context"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
@@ -132,8 +132,8 @@ type S3Storage struct {
noMultipart bool
}
func NewS3Storage(accessKey, secretKey, bucketName, region, endpoint string, logger *log.Logger, disableMultipart bool) (*S3Storage, error) {
sess := getAwsSession(accessKey, secretKey, region, endpoint)
func NewS3Storage(accessKey, secretKey, bucketName, region, endpoint string, logger *log.Logger, disableMultipart bool, forcePathStyle bool) (*S3Storage, error) {
sess := getAwsSession(accessKey, secretKey, region, endpoint, forcePathStyle)
return &S3Storage{bucket: bucketName, s3: s3.New(sess), session: sess, logger: logger, noMultipart: disableMultipart}, nil
}

View File

@@ -25,7 +25,6 @@ THE SOFTWARE.
package server
import (
"github.com/aws/aws-sdk-go/aws/credentials"
"math"
"net/http"
"net/mail"
@@ -33,15 +32,17 @@ import (
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/golang/gddo/httputil/header"
)
func getAwsSession(accessKey, secretKey, region, endpoint string) *session.Session {
func getAwsSession(accessKey, secretKey, region, endpoint string, forcePathStyle bool) *session.Session {
return session.Must(session.NewSession(&aws.Config{
Region: aws.String(region),
Endpoint: aws.String(endpoint),
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
Region: aws.String(region),
Endpoint: aws.String(endpoint),
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
S3ForcePathStyle: aws.Bool(forcePathStyle),
}))
}