mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
fix (s3): default region for s3
This commit is contained in:
parent
d4833ff565
commit
a54fa5da00
1 changed files with 21 additions and 17 deletions
|
|
@ -44,10 +44,11 @@ func (this S3Backend) Init(params map[string]string, app *App) (IBackend, error)
|
||||||
if params["encryption_key"] != "" && len(params["encryption_key"]) != 32 {
|
if params["encryption_key"] != "" && len(params["encryption_key"]) != 32 {
|
||||||
return nil, NewError(fmt.Sprintf("Encryption key needs to be 32 characters (current: %d)", len(params["encryption_key"])), 400)
|
return nil, NewError(fmt.Sprintf("Encryption key needs to be 32 characters (current: %d)", len(params["encryption_key"])), 400)
|
||||||
}
|
}
|
||||||
if params["region"] == "" {
|
region := params["region"]
|
||||||
params["region"] = "us-east-2"
|
if region == "" {
|
||||||
|
region = "us-east-1"
|
||||||
if strings.HasSuffix(params["endpoint"], ".cloudflarestorage.com") {
|
if strings.HasSuffix(params["endpoint"], ".cloudflarestorage.com") {
|
||||||
params["region"] = "auto"
|
region = "auto"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
creds := []credentials.Provider{}
|
creds := []credentials.Provider{}
|
||||||
|
|
@ -60,7 +61,7 @@ func (this S3Backend) Init(params map[string]string, app *App) (IBackend, error)
|
||||||
}
|
}
|
||||||
if params["role_arn"] != "" {
|
if params["role_arn"] != "" {
|
||||||
creds = append(creds, &stscreds.AssumeRoleProvider{
|
creds = append(creds, &stscreds.AssumeRoleProvider{
|
||||||
Client: sts.New(session.Must(session.NewSessionWithOptions(session.Options{Config: aws.Config{Region: aws.String(params["region"])}}))),
|
Client: sts.New(session.Must(session.NewSessionWithOptions(session.Options{Config: aws.Config{Region: aws.String(region)}}))),
|
||||||
RoleARN: params["role_arn"],
|
RoleARN: params["role_arn"],
|
||||||
Duration: stscreds.DefaultDuration,
|
Duration: stscreds.DefaultDuration,
|
||||||
})
|
})
|
||||||
|
|
@ -75,7 +76,7 @@ func (this S3Backend) Init(params map[string]string, app *App) (IBackend, error)
|
||||||
Credentials: credentials.NewChainCredentials(creds),
|
Credentials: credentials.NewChainCredentials(creds),
|
||||||
CredentialsChainVerboseErrors: aws.Bool(true),
|
CredentialsChainVerboseErrors: aws.Bool(true),
|
||||||
S3ForcePathStyle: aws.Bool(true),
|
S3ForcePathStyle: aws.Bool(true),
|
||||||
Region: aws.String(params["region"]),
|
Region: aws.String(region),
|
||||||
}
|
}
|
||||||
if params["endpoint"] != "" {
|
if params["endpoint"] != "" {
|
||||||
config.Endpoint = aws.String(params["endpoint"])
|
config.Endpoint = aws.String(params["endpoint"])
|
||||||
|
|
@ -524,20 +525,23 @@ func (this S3Backend) Save(path string, file io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this S3Backend) createSession(bucket string) *session.Session {
|
func (this S3Backend) createSession(bucket string) *session.Session {
|
||||||
|
if this.params["region"] == "" {
|
||||||
newParams := map[string]string{"bucket": bucket}
|
newParams := map[string]string{"bucket": bucket}
|
||||||
for k, v := range this.params {
|
for k, v := range this.params {
|
||||||
newParams[k] = v
|
newParams[k] = v
|
||||||
}
|
}
|
||||||
if c := S3Cache.Get(newParams); c == nil {
|
if c := S3Cache.Get(newParams); c == nil {
|
||||||
if res, err := this.client.GetBucketLocation(&s3.GetBucketLocationInput{
|
res, err := this.client.GetBucketLocation(&s3.GetBucketLocationInput{
|
||||||
Bucket: aws.String(bucket),
|
Bucket: aws.String(bucket),
|
||||||
}); err == nil && res.LocationConstraint != nil {
|
})
|
||||||
|
if err == nil && res.LocationConstraint != nil {
|
||||||
this.config.Region = res.LocationConstraint
|
this.config.Region = res.LocationConstraint
|
||||||
}
|
}
|
||||||
S3Cache.Set(newParams, this.config.Region)
|
S3Cache.Set(newParams, this.config.Region)
|
||||||
} else {
|
} else {
|
||||||
this.config.Region = c.(*string)
|
this.config.Region = c.(*string)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sess := session.New(this.config)
|
sess := session.New(this.config)
|
||||||
return sess
|
return sess
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue