Browse Source

Add -s3-force-path-style flag and config option (#157)

This option forces path-style addressing instead of using a subdomain.
This appears to be needed by Minio.
pull/158/head
mutantmonkey 5 years ago
committed by Andrei Marcu
parent
commit
207c19e3df
  1. 2
      README.md
  2. 5
      backends/s3/s3.go
  3. 5
      server.go

2
README.md

@ -60,7 +60,7 @@ The following storage backends are available:
|Name|Options|Notes
|----|-------|-----
|LocalFS|```-filespath files/``` -- Path to store uploads (default is files/)<br />```-metapath meta/``` -- Path to store information about uploads (default is meta/)|Enabled by default, this backend uses the filesystem|
|S3|```-s3-endpoint https://...``` -- S3 endpoint<br>```-s3-region us-east-1``` -- S3 region<br>```-s3-bucket mybucket``` -- S3 bucket to use for files and metadata<br><br>Environment variables to provide:<br>```AWS_ACCESS_KEY_ID``` -- the S3 access key<br>```AWS_SECRET_ACCESS_KEY ``` -- the S3 secret key<br>```AWS_SESSION_TOKEN``` (optional) -- the S3 session token|Use with any S3-compatible provider.<br> This implementation will stream files through the linx instance (every download will request and stream the file from the S3 bucket).<br><br>For high-traffic environments, one might consider using an external caching layer such as described [in this article](https://blog.sentry.io/2017/03/01/dodging-s3-downtime-with-nginx-and-haproxy.html).|
|S3|```-s3-endpoint https://...``` -- S3 endpoint<br>```-s3-region us-east-1``` -- S3 region<br>```-s3-bucket mybucket``` -- S3 bucket to use for files and metadata<br>```-s3-use-path-style``` -- force path-style addresing (e.g. https://s3.amazonaws.com/linx/example.txt)<br><br>Environment variables to provide:<br>```AWS_ACCESS_KEY_ID``` -- the S3 access key<br>```AWS_SECRET_ACCESS_KEY ``` -- the S3 secret key<br>```AWS_SESSION_TOKEN``` (optional) -- the S3 session token|Use with any S3-compatible provider.<br> This implementation will stream files through the linx instance (every download will request and stream the file from the S3 bucket).<br><br>For high-traffic environments, one might consider using an external caching layer such as described [in this article](https://blog.sentry.io/2017/03/01/dodging-s3-downtime-with-nginx-and-haproxy.html).|
#### SSL with built-in server

5
backends/s3/s3.go

@ -177,7 +177,7 @@ func (b S3Backend) List() ([]string, error) {
return output, nil
}
func NewS3Backend(bucket string, region string, endpoint string) S3Backend {
func NewS3Backend(bucket string, region string, endpoint string, forcePathStyle bool) S3Backend {
awsConfig := &aws.Config{}
if region != "" {
awsConfig.Region = aws.String(region)
@ -185,6 +185,9 @@ func NewS3Backend(bucket string, region string, endpoint string) S3Backend {
if endpoint != "" {
awsConfig.Endpoint = aws.String(endpoint)
}
if forcePathStyle == true {
awsConfig.S3ForcePathStyle = aws.Bool(true)
}
sess := session.Must(session.NewSession(awsConfig))
svc := s3.New(sess)

5
server.go

@ -64,6 +64,7 @@ var Config struct {
s3Endpoint string
s3Region string
s3Bucket string
s3ForcePathStyle bool
}
var Templates = make(map[string]*pongo2.Template)
@ -138,7 +139,7 @@ func setup() *web.Mux {
}
if Config.s3Bucket != "" {
storageBackend = s3.NewS3Backend(Config.s3Bucket, Config.s3Region, Config.s3Endpoint)
storageBackend = s3.NewS3Backend(Config.s3Bucket, Config.s3Region, Config.s3Endpoint, Config.s3ForcePathStyle)
} else {
storageBackend = localfs.NewLocalfsBackend(Config.metaDir, Config.filesDir)
}
@ -265,6 +266,8 @@ func main() {
"S3 region")
flag.StringVar(&Config.s3Bucket, "s3-bucket", "",
"S3 bucket to use for files and metadata")
flag.BoolVar(&Config.s3ForcePathStyle, "s3-force-path-style", false,
"Force path-style addressing for S3 (e.g. https://s3.amazonaws.com/linx/example.txt)")
iniflags.Parse()

Loading…
Cancel
Save