From 7d2d2a7c9e5a91cec6b427e870f63e47729fa4d0 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Sat, 12 Jan 2019 06:37:00 +0000 Subject: [PATCH] s3cache: expose add'l config options as URL params this should allow using at least some s3-compatible services like minio. Ref #120, #147 --- README.md | 15 +++++++++++++++ internal/s3cache/s3cache.go | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e158912a..19ef903a9 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/internal/s3cache/s3cache.go b/internal/s3cache/s3cache.go index c3bbbfd8f..b29560371 100644 --- a/internal/s3cache/s3cache.go +++ b/internal/s3cache/s3cache.go @@ -97,7 +97,23 @@ func New(s string) (*cache, error) { prefix = path[1] } - sess, err := session.NewSession(&aws.Config{Region: ®ion}) + config := &aws.Config{ + Region: ®ion, + } + + // 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 }