Provide pathstyle for S3 log storage

This commit is contained in:
Thomas Boerger 2019-02-26 22:09:56 +01:00
parent 7c1f21d872
commit 876645a1b0
No known key found for this signature in database
GPG key ID: 09745AFF9D63C79B
3 changed files with 16 additions and 5 deletions

View file

@ -330,9 +330,10 @@ type (
// S3 provides the storage configuration.
S3 struct {
Bucket string `envconfig:"DRONE_S3_BUCKET"`
Prefix string `envconfig:"DRONE_S3_PREFIX"`
Endpoint string `envconfig:"DRONE_S3_ENDPOINT"`
Bucket string `envconfig:"DRONE_S3_BUCKET"`
Prefix string `envconfig:"DRONE_S3_PREFIX"`
Endpoint string `envconfig:"DRONE_S3_ENDPOINT"`
PathStyle bool `envconfig:"DRONE_S3_PATH_STYLE"`
}
// HTTP provides http configuration.

View file

@ -86,6 +86,7 @@ func provideLogStore(db *db.DB, config config.Config) core.LogStore {
config.S3.Bucket,
config.S3.Prefix,
config.S3.Endpoint,
config.S3.PathStyle,
)
}

View file

@ -9,6 +9,7 @@ import (
"fmt"
"io"
"path"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
@ -22,13 +23,21 @@ import (
// s3gof3r as an alternate. github.com/rlmcpherson/s3gof3r
// NewS3Env returns a new S3 log store.
func NewS3Env(bucket, prefix, endpoint string) core.LogStore {
func NewS3Env(bucket, prefix, endpoint string, pathStyle bool) core.LogStore {
disableSSL := false
if endpoint != "" {
disableSSL = !strings.HasPrefix(endpoint, "https://")
}
return &s3store{
bucket: bucket,
prefix: prefix,
session: session.Must(
session.NewSession(&aws.Config{
Endpoint: aws.String(endpoint),
Endpoint: aws.String(endpoint),
DisableSSL: aws.Bool(disableSSL),
S3ForcePathStyle: aws.Bool(pathStyle),
}),
),
}