This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/answer-plugins.git
commit 80072ff8cc4523fb87538d3a57eb56f1da9a1a9c Author: Luffy <5...@qq52o.cn> AuthorDate: Wed Apr 23 16:42:42 2025 +0800 feat(storage): add support for configurable Object ACL in storage settings --- storage-aliyunoss/aliyunoss.go | 27 ++++++++++++++++++++------- storage-aliyunoss/i18n/en_US.yaml | 10 ++++++++++ storage-aliyunoss/i18n/translation.go | 4 ++++ storage-aliyunoss/i18n/zh_CN.yaml | 10 ++++++++++ storage-tencentyuncos/i18n/en_US.yaml | 10 ++++++++++ storage-tencentyuncos/i18n/translation.go | 4 ++++ storage-tencentyuncos/i18n/zh_CN.yaml | 10 ++++++++++ storage-tencentyuncos/tencentyuncos.go | 27 ++++++++++++++++++++------- 8 files changed, 88 insertions(+), 14 deletions(-) diff --git a/storage-aliyunoss/aliyunoss.go b/storage-aliyunoss/aliyunoss.go index 4bb29e0..771a4b5 100644 --- a/storage-aliyunoss/aliyunoss.go +++ b/storage-aliyunoss/aliyunoss.go @@ -25,7 +25,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "os" "path/filepath" "strings" "time" @@ -41,11 +40,6 @@ import ( //go:embed info.yaml var Info embed.FS -var ( - // aclPublicRead is the environment variable for some special platforms such as digital ocean - aclPublicRead = os.Getenv("ACL_PUBLIC_READ") -) - type Storage struct { Config *StorageConfig } @@ -57,6 +51,7 @@ type StorageConfig struct { AccessKeyID string `json:"access_key_id"` AccessKeySecret string `json:"access_key_secret"` VisitUrlPrefix string `json:"visit_url_prefix"` + ACL string `json:"acl"` } func init() { @@ -128,7 +123,7 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile Reader: open, } var options []oss.Option - if len(aclPublicRead) > 0 { + if s.Config.ACL == string(oss.ACLPublicRead) { options = append(options, oss.ObjectACL(oss.ACLPublicRead)) } respBody, err := bucket.DoPutObject(request, options) @@ -256,6 +251,24 @@ func (s *Storage) ConfigFields() []plugin.ConfigField { }, Value: s.Config.VisitUrlPrefix, }, + { + Name: "acl", + Type: plugin.ConfigTypeSelect, + Title: plugin.MakeTranslator(i18n.ConfigACLTitle), + Description: plugin.MakeTranslator(i18n.ConfigACLDescription), + Required: true, + Options: []plugin.ConfigFieldOption{ + { + Label: plugin.MakeTranslator(i18n.ConfigACLOptionsDefault), + Value: string(oss.ACLDefault), + }, + { + Label: plugin.MakeTranslator(i18n.ConfigACLOptionsPublicRead), + Value: string(oss.ACLPublicRead), + }, + }, + Value: s.Config.ACL, + }, } } diff --git a/storage-aliyunoss/i18n/en_US.yaml b/storage-aliyunoss/i18n/en_US.yaml index 257465a..f229a06 100644 --- a/storage-aliyunoss/i18n/en_US.yaml +++ b/storage-aliyunoss/i18n/en_US.yaml @@ -54,6 +54,16 @@ plugin: other: Access URL prefix description: other: prefix of the final access address of the uploaded file, ending with '/' https://example.com/xxx/ + acl: + title: + other: Object ACL + description: + other: Set Object ACL, default is consistent with the read and write permissions of the Bucket, can be modified to public read. + options: + default: + other: Default + public_read: + other: Public Read err: mis_storage_config: other: Wrong storage configuration causes upload failure. diff --git a/storage-aliyunoss/i18n/translation.go b/storage-aliyunoss/i18n/translation.go index 73a77c8..0ef9f53 100644 --- a/storage-aliyunoss/i18n/translation.go +++ b/storage-aliyunoss/i18n/translation.go @@ -35,6 +35,10 @@ const ( ConfigAccessKeySecretDescription = "plugin.aliyunoss_storage.backend.config.access_key_secret.description" ConfigVisitUrlPrefixTitle = "plugin.aliyunoss_storage.backend.config.visit_url_prefix.title" ConfigVisitUrlPrefixDescription = "plugin.aliyunoss_storage.backend.config.visit_url_prefix.description" + ConfigACLTitle = "plugin.aliyunoss_storage.backend.config.acl.title" + ConfigACLDescription = "plugin.aliyunoss_storage.backend.config.acl.description" + ConfigACLOptionsDefault = "plugin.aliyunoss_storage.backend.config.acl.options.default" + ConfigACLOptionsPublicRead = "plugin.aliyunoss_storage.backend.config.acl.options.public_read" ErrMisStorageConfig = "plugin.aliyunoss_storage.backend.err.mis_storage_config" ErrFileNotFound = "plugin.aliyunoss_storage.backend.err.file_not_found" diff --git a/storage-aliyunoss/i18n/zh_CN.yaml b/storage-aliyunoss/i18n/zh_CN.yaml index 7e7b77c..3abc7ed 100644 --- a/storage-aliyunoss/i18n/zh_CN.yaml +++ b/storage-aliyunoss/i18n/zh_CN.yaml @@ -54,6 +54,16 @@ plugin: other: 访问URL前缀 description: other: 上传文件最终访问地址的前缀,以 '/' 结尾 https://example.com/xxx/ + acl: + title: + other: Object ACL + description: + other: 设置 Object ACL,默认和 Bucket 的读写权限一致,可修改为公共读。 + options: + default: + other: 默认 + public_read: + other: 公共读 err: mis_storage_config: other: 错误的存储配置导致上传失败 diff --git a/storage-tencentyuncos/i18n/en_US.yaml b/storage-tencentyuncos/i18n/en_US.yaml index a9f3242..664e855 100644 --- a/storage-tencentyuncos/i18n/en_US.yaml +++ b/storage-tencentyuncos/i18n/en_US.yaml @@ -54,6 +54,16 @@ plugin: other: Access URL prefix description: other: prefix of the final access address of the uploaded file, ending with '/' https://example.com/xxx/ + acl: + title: + other: Object ACL + description: + other: Set Object ACL, default is consistent with the read and write permissions of the Bucket, can be modified to public read. + options: + default: + other: Default + public_read: + other: Public Read err: mis_storage_config: other: Wrong storage configuration causes upload failure. diff --git a/storage-tencentyuncos/i18n/translation.go b/storage-tencentyuncos/i18n/translation.go index c11b7a0..1b6b23b 100644 --- a/storage-tencentyuncos/i18n/translation.go +++ b/storage-tencentyuncos/i18n/translation.go @@ -35,6 +35,10 @@ const ( ConfigSecretKeyDescription = "plugin.tencentyuncos_storage.backend.config.secret_key.description" ConfigVisitUrlPrefixTitle = "plugin.tencentyuncos_storage.backend.config.visit_url_prefix.title" ConfigVisitUrlPrefixDescription = "plugin.tencentyuncos_storage.backend.config.visit_url_prefix.description" + ConfigACLTitle = "plugin.tencentyuncos_storage.backend.config.acl.title" + ConfigACLDescription = "plugin.tencentyuncos_storage.backend.config.acl.description" + ConfigACLOptionsDefault = "plugin.tencentyuncos_storage.backend.config.acl.options.default" + ConfigACLOptionsPublicRead = "plugin.tencentyuncos_storage.backend.config.acl.options.public_read" ErrMisStorageConfig = "plugin.tencentyuncos_storage.backend.err.mis_storage_config" ErrFileNotFound = "plugin.tencentyuncos_storage.backend.err.file_not_found" diff --git a/storage-tencentyuncos/i18n/zh_CN.yaml b/storage-tencentyuncos/i18n/zh_CN.yaml index 1aca832..6eab4a5 100644 --- a/storage-tencentyuncos/i18n/zh_CN.yaml +++ b/storage-tencentyuncos/i18n/zh_CN.yaml @@ -54,6 +54,16 @@ plugin: other: 访问URL前缀 description: other: 上传文件最终访问地址的前缀,以 '/' 结尾 https://example.com/xxx/ + acl: + title: + other: Object ACL + description: + other: 设置 Object ACL,默认和 Bucket 的读写权限一致,可修改为公共读。 + options: + default: + other: 默认 + public_read: + other: 公共读 err: mis_storage_config: other: 错误的存储配置导致上传失败 diff --git a/storage-tencentyuncos/tencentyuncos.go b/storage-tencentyuncos/tencentyuncos.go index 97a69b3..3bd62f6 100644 --- a/storage-tencentyuncos/tencentyuncos.go +++ b/storage-tencentyuncos/tencentyuncos.go @@ -27,7 +27,6 @@ import ( "fmt" "net/http" "net/url" - "os" "path/filepath" "strings" "time" @@ -43,11 +42,6 @@ import ( //go:embed info.yaml var Info embed.FS -var ( - // aclPublicRead is the environment variable for some special platforms such as digital ocean - aclPublicRead = os.Getenv("ACL_PUBLIC_READ") -) - type Storage struct { Config *StorageConfig } @@ -59,6 +53,7 @@ type StorageConfig struct { SecretID string `json:"secret_id"` SecretKey string `json:"secret_key"` VisitUrlPrefix string `json:"visit_url_prefix"` + ACL string `json:"acl"` } func init() { @@ -129,7 +124,7 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile objectKey := s.createObjectKey(file.Filename, condition.Source) var options *cos.ObjectPutOptions - if len(aclPublicRead) > 0 { + if s.Config.ACL == "public-read" { options = &cos.ObjectPutOptions{ ACLHeaderOptions: &cos.ACLHeaderOptions{ XCosACL: "public-read", @@ -268,6 +263,24 @@ func (s *Storage) ConfigFields() []plugin.ConfigField { }, Value: s.Config.VisitUrlPrefix, }, + { + Name: "acl", + Type: plugin.ConfigTypeSelect, + Title: plugin.MakeTranslator(i18n.ConfigACLTitle), + Description: plugin.MakeTranslator(i18n.ConfigACLDescription), + Required: true, + Options: []plugin.ConfigFieldOption{ + { + Label: plugin.MakeTranslator(i18n.ConfigACLOptionsDefault), + Value: "default", + }, + { + Label: plugin.MakeTranslator(i18n.ConfigACLOptionsPublicRead), + Value: "public-read", + }, + }, + Value: s.Config.ACL, + }, } }