فهرست منبع

Add IMGPROXY_GCS_ENDPOINT config

DarthSim 3 سال پیش
والد
کامیت
3d93bc6836
5فایلهای تغییر یافته به همراه26 افزوده شده و 7 حذف شده
  1. 1 0
      CHANGELOG.md
  2. 4 2
      config/config.go
  3. 3 1
      docs/configuration.md
  4. 2 1
      docs/serving_files_from_google_cloud_storage.md
  5. 16 3
      transport/gcs/gcs.go

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 - Add `IMGPROXY_FALLBACK_IMAGE_TTL` config.
 - (pro) Add [watermark_size](https://docs.imgproxy.net/generating_the_url?id=watermark-size) processing option.
 - Add OpenStack Object Storage ("Swift") support.
+- Add `IMGPROXY_GCS_ENDPOINT` config.
 
 ### Change
 - (pro) Don't check `Content-Length` header of videos.

+ 4 - 2
config/config.go

@@ -85,8 +85,9 @@ var (
 	S3Region   string
 	S3Endpoint string
 
-	GCSEnabled bool
-	GCSKey     string
+	GCSEnabled  bool
+	GCSKey      string
+	GCSEndpoint string
 
 	ABSEnabled  bool
 	ABSName     string
@@ -400,6 +401,7 @@ func Configure() error {
 
 	configurators.Bool(&GCSEnabled, "IMGPROXY_USE_GCS")
 	configurators.String(&GCSKey, "IMGPROXY_GCS_KEY")
+	configurators.String(&GCSEndpoint, "IMGPROXY_GCS_ENDPOINT")
 
 	configurators.Bool(&ABSEnabled, "IMGPROXY_USE_ABS")
 	configurators.String(&ABSName, "IMGPROXY_ABS_NAME")

+ 3 - 1
docs/configuration.md

@@ -308,9 +308,11 @@ Check out the [Serving files from S3](serving_files_from_s3.md) guide to learn m
 
 ## Serving files from Google Cloud Storage
 
-imgproxy can process files from Google Cloud Storage buckets, but this feature is disabled by default. To enable it, set the value of `IMGPROXY_GCS_KEY` to the content of the Google Cloud JSON key:
+imgproxy can process files from Google Cloud Storage buckets, but this feature is disabled by default. To enable it, set the value of `IMGPROXY_USE_GCS` to `true`:
 
+* `IMGPROXY_USE_GCS`: when `true`, enables image fetching from Google Cloud Storage buckets. Default: `false`
 * `IMGPROXY_GCS_KEY`: the Google Cloud JSON key. When set, enables image fetching from Google Cloud Storage buckets. Default: blank
+* `IMGPROXY_GCS_ENDPOINT`: a custom Google Cloud Storage endpoint to being used by imgproxy
 
 Check out the [Serving files from Google Cloud Storage](serving_files_from_google_cloud_storage.md) guide to learn more.
 

+ 2 - 1
docs/serving_files_from_google_cloud_storage.md

@@ -4,7 +4,8 @@ imgproxy can process images from Google Cloud Storage buckets. To use this featu
 
 1. Set the `IMGPROXY_USE_GCS` environment variable to `true`.
 2. [Set up credentials](#setup-credentials) to grant access to your bucket.
-3. Use `gs://%bucket_name/%file_key` as the source image URL.
+3. _(optional)_ Specify the Google Cloud Storage endpoint with `IMGPROXY_GCS_ENDPOINT`.
+4. Use `gs://%bucket_name/%file_key` as the source image URL.
 
 If you need to specify generation of the source object, you can use the query string of the source URL:
 

+ 16 - 3
transport/gcs/gcs.go

@@ -13,6 +13,9 @@ import (
 	"github.com/imgproxy/imgproxy/v3/config"
 )
 
+// For tests
+var noAuth bool = false
+
 type transport struct {
 	client *storage.Client
 }
@@ -23,12 +26,22 @@ func New() (http.RoundTripper, error) {
 		err    error
 	)
 
+	opts := []option.ClientOption{}
+
 	if len(config.GCSKey) > 0 {
-		client, err = storage.NewClient(context.Background(), option.WithCredentialsJSON([]byte(config.GCSKey)))
-	} else {
-		client, err = storage.NewClient(context.Background())
+		opts = append(opts, option.WithCredentialsJSON([]byte(config.GCSKey)))
+	}
+
+	if len(config.GCSEndpoint) > 0 {
+		opts = append(opts, option.WithEndpoint(config.GCSEndpoint))
 	}
 
+	if noAuth {
+		opts = append(opts, option.WithoutAuthentication())
+	}
+
+	client, err = storage.NewClient(context.Background(), opts...)
+
 	if err != nil {
 		return nil, fmt.Errorf("Can't create GCS client: %s", err)
 	}