Skip to content

Commit

Permalink
s3cache: expose add'l config options as URL params
Browse files Browse the repository at this point in the history
this should allow using at least some s3-compatible services like minio.

Ref #120, #147
  • Loading branch information
willnorris committed Mar 16, 2019
1 parent a903995 commit 7d2d2a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,25 @@ 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 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

- 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
Expand All @@ -127,6 +140,8 @@ enabled using the `-cache` flag. It supports the following values:
Rather than specify password in the URI, use the `REDIS_PASSWORD`
environment variable.

[s3compat]: https://github.com/willnorris/imageproxy/pull/147#issuecomment-473362058

For example, to cache files on disk in the `/tmp/imageproxy` directory:

imageproxy -cache /tmp/imageproxy
Expand Down
18 changes: 17 additions & 1 deletion internal/s3cache/s3cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,23 @@ func New(s string) (*cache, error) {
prefix = path[1]
}

sess, err := session.NewSession(&aws.Config{Region: &region})
config := &aws.Config{
Region: &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.Endpoint = &v
}
if v := u.Query().Get("disableSSL"); v == "1" {
config.DisableSSL = aws.Bool(true)
}
if v := u.Query().Get("s3ForcePathStyle"); v == "1" {
config.S3ForcePathStyle = aws.Bool(true)
}

sess, err := session.NewSession(config)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7d2d2a7

Please sign in to comment.