You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/04/03 03:15:25 UTC

(incubator-answer-plugins) 01/01: feat(s3): support to set ACL_PUBLIC_READ ENV

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/digital-ocean
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git

commit d36ea149e6c5ff58ea71329c8d57aa4845fc59ac
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Wed Apr 3 11:14:36 2024 +0800

    feat(s3): support to set ACL_PUBLIC_READ ENV
---
 storage-s3/s3.go        |  2 +-
 storage-s3/s3_client.go | 20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/storage-s3/s3.go b/storage-s3/s3.go
index 012e63c..61f273f 100644
--- a/storage-s3/s3.go
+++ b/storage-s3/s3.go
@@ -68,7 +68,7 @@ func (s *Storage) Info() plugin.Info {
 		SlugName:    "s3_storage",
 		Description: plugin.MakeTranslator(i18n.InfoDescription),
 		Author:      "answerdev",
-		Version:     "1.2.5",
+		Version:     "1.2.6",
 		Link:        "https://github.com/apache/incubator-answer-plugins/tree/main/storage-s3",
 	}
 }
diff --git a/storage-s3/s3_client.go b/storage-s3/s3_client.go
index 445e1dd..6931bfc 100644
--- a/storage-s3/s3_client.go
+++ b/storage-s3/s3_client.go
@@ -21,12 +21,14 @@ package s3
 
 import (
 	"fmt"
+	"io"
+	"os"
+	"strings"
+
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws/credentials"
 	"github.com/aws/aws-sdk-go/aws/session"
 	"github.com/aws/aws-sdk-go/service/s3"
-	"io"
-	"strings"
 )
 
 type Client struct {
@@ -55,6 +57,7 @@ func (s *Client) PutObject(key, ext string, file io.ReadSeeker) (err error) {
 	}
 	contentType := fmt.Sprintf("image/%s", strings.TrimPrefix(ext, "."))
 	_, err = s3.New(newSession).PutObject(&s3.PutObjectInput{
+		ACL:         getACLConfig(),
 		Body:        file,
 		Bucket:      aws.String(s.bucket),
 		Key:         aws.String(key),
@@ -65,3 +68,16 @@ func (s *Client) PutObject(key, ext string, file io.ReadSeeker) (err error) {
 	}
 	return nil
 }
+
+var (
+	// aclPublicRead is the environment variable for some special platforms such as digital ocean
+	// https://github.com/apache/incubator-answer-plugins/issues/97
+	aclPublicRead = os.Getenv("ACL_PUBLIC_READ")
+)
+
+func getACLConfig() *string {
+	if len(aclPublicRead) > 0 {
+		return aws.String("public-read")
+	}
+	return nil
+}