Add MAGICBOX_S3_FORCE_PATH_STYLE env var
This commit is contained in:
parent
782041dab7
commit
8430ff3b28
3 changed files with 23 additions and 6 deletions
|
@ -51,6 +51,7 @@ curl -D - -X PUT -H "Authorization: Bearer <admin token>" <Magicbox admin addres
|
|||
* `MAGICBOX_S3_CREDENTIAL_SECRET`: **required**
|
||||
* `MAGICBOX_S3_ENDPOINT`: **required**
|
||||
* `MAGICBOX_S3_REGION`: **required**
|
||||
* `MAGICBOX_S3_FORCE_PATH_STYLE`: boolean, default `false`
|
||||
* Admin API config:
|
||||
* `MAGICBOX_ADMIN_ENABLED`: boolean, enable or disable the entire admin API, default `true`
|
||||
* `MAGICBOX_ADMIN_TOKEN`: when set, requires the `Authorization` header to be set with the value of the variable as a bearer token
|
||||
|
|
|
@ -16,11 +16,13 @@ type Config struct {
|
|||
AdminHTTPAddress string
|
||||
AdminToken string
|
||||
|
||||
S3BucketName string
|
||||
S3CredentialID string
|
||||
S3CredentialSecret string
|
||||
S3Endpoint string
|
||||
S3Region string
|
||||
S3BucketName string
|
||||
S3CredentialID string
|
||||
S3CredentialSecret string
|
||||
S3Endpoint string
|
||||
S3Region string
|
||||
S3ForcePathStyle bool
|
||||
s3ForcePathStyleValid bool
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -73,6 +75,16 @@ func Get() *Config {
|
|||
} else {
|
||||
conf.AdminEnabled = true
|
||||
}
|
||||
|
||||
conf.s3ForcePathStyleValid = true
|
||||
if v := os.Getenv("MAGICBOX_S3_FORCE_PATH_STYLE"); v != "" {
|
||||
parsedValue, err := strconv.ParseBool(v)
|
||||
if err != nil {
|
||||
conf.s3ForcePathStyleValid = false
|
||||
} else {
|
||||
conf.S3ForcePathStyle = parsedValue
|
||||
}
|
||||
}
|
||||
})
|
||||
return conf
|
||||
}
|
||||
|
@ -88,6 +100,10 @@ func Validate() error {
|
|||
return errors.New("MAGICBOX_ADMIN_ENABLED not a valid boolean")
|
||||
}
|
||||
|
||||
if !conf.s3ForcePathStyleValid {
|
||||
return errors.New("MAGICBOX_S3_FORCE_PATH_STYLE not a valid boolean")
|
||||
}
|
||||
|
||||
if conf.S3BucketName == "" {
|
||||
return errors.New("missing required environment variable MAGICBOX_S3_BUCKET_NAME")
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func ListenAndServe() error {
|
|||
Credentials: credentials.NewStaticCredentials(conf.S3CredentialID, conf.S3CredentialSecret, ""),
|
||||
Endpoint: aws.String(conf.S3Endpoint),
|
||||
Region: aws.String(conf.S3Region),
|
||||
S3ForcePathStyle: aws.Bool(true),
|
||||
S3ForcePathStyle: aws.Bool(conf.S3ForcePathStyle),
|
||||
}
|
||||
|
||||
awsSession, err := session.NewSession(awsConfig)
|
||||
|
|
Reference in a new issue