diff --git a/README.md b/README.md index 7e15891..dec8258 100644 --- a/README.md +++ b/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 diff --git a/internal/s3cache/s3cache.go b/internal/s3cache/s3cache.go index c3bbbfd..ad9b661 100644 --- a/internal/s3cache/s3cache.go +++ b/internal/s3cache/s3cache.go @@ -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 }