Add MAGICBOX_S3_FORCE_PATH_STYLE env var

This commit is contained in:
akp 2024-04-05 01:59:01 +01:00
parent 782041dab7
commit 8430ff3b28
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755
3 changed files with 23 additions and 6 deletions

View file

@ -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

View file

@ -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")
}

View file

@ -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)