mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-30 22:34:18 -05:00
s3cache: expose add'l config options as URL params
this should allow using at least some s3-compatible services like minio. Fixes #120, #147
This commit is contained in:
parent
a903995ee7
commit
e860748032
2 changed files with 31 additions and 1 deletions
16
README.md
16
README.md
|
@ -108,12 +108,28 @@ enabled using the `-cache` flag. It supports the following values:
|
|||
cache items no longer than 4 hours.
|
||||
- directory on local disk (e.g. `/tmp/imageproxy`) - will cache images
|
||||
on disk
|
||||
|
||||
- s3 URL (e.g. `s3://region/bucket-name/optional-path-prefix`) - will cache
|
||||
images on Amazon S3. This requires either an IAM role and instance profile
|
||||
with access to your your bucket or `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`
|
||||
environmental variables be set. (Additional methods of loading credentials
|
||||
are documented in the [aws-sdk-go session
|
||||
package](https://docs.aws.amazon.com/sdk-for-go/api/aws/session/)).
|
||||
|
||||
Additional configuration options ([further documented here][aws-options])
|
||||
may be specified as URL query string parameters, which are mostly useful
|
||||
when working with s3-compatible services:
|
||||
- "endpoint" - specify an alternate API endpoint
|
||||
- "disableSSL" - set to "1" to disable SSL when calling the API
|
||||
- "s3ForcePathStyle" - set to "1" to force the request to use path-style addressing
|
||||
|
||||
For example, when working with [minio](https://minio.io), which doesn't use
|
||||
regions, provide a dummy region value and custom endpoint value:
|
||||
|
||||
s3://fake-region/bucket/folder?endpoint=minio:9000&disableSSL=1&s3ForcePathStyle=1
|
||||
|
||||
[aws-options]: https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
|
||||
|
||||
- gcs URL (e.g. `gcs://bucket-name/optional-path-prefix`) - will cache images
|
||||
on Google Cloud Storage. Authentication is documented in Google's
|
||||
[Application Default Credentials
|
||||
|
|
|
@ -97,7 +97,21 @@ func New(s string) (*cache, error) {
|
|||
prefix = path[1]
|
||||
}
|
||||
|
||||
sess, err := session.NewSession(&aws.Config{Region: ®ion})
|
||||
config := aws.NewConfig().WithRegion(region)
|
||||
|
||||
// allow overriding some additional config options, mostly useful when
|
||||
// working with s3-compatible services other than AWS.
|
||||
if v := u.Query().Get("endpoint"); v != "" {
|
||||
config = config.WithEndpoint(v)
|
||||
}
|
||||
if v := u.Query().Get("disableSSL"); v == "1" {
|
||||
config = config.WithDisableSSL(true)
|
||||
}
|
||||
if v := u.Query().Get("s3ForcePathStyle"); v == "1" {
|
||||
config = config.WithS3ForcePathStyle(true)
|
||||
}
|
||||
|
||||
sess, err := session.NewSession(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue