Skip to content

Commit 80072ff

Browse files
sy-recordsLinkinStars
authored andcommitted
feat(storage): add support for configurable Object ACL in storage settings
1 parent 4997847 commit 80072ff

File tree

8 files changed

+88
-14
lines changed

8 files changed

+88
-14
lines changed

storage-aliyunoss/aliyunoss.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"encoding/hex"
2626
"encoding/json"
2727
"fmt"
28-
"os"
2928
"path/filepath"
3029
"strings"
3130
"time"
@@ -41,11 +40,6 @@ import (
4140
//go:embed info.yaml
4241
var Info embed.FS
4342

44-
var (
45-
// aclPublicRead is the environment variable for some special platforms such as digital ocean
46-
aclPublicRead = os.Getenv("ACL_PUBLIC_READ")
47-
)
48-
4943
type Storage struct {
5044
Config *StorageConfig
5145
}
@@ -57,6 +51,7 @@ type StorageConfig struct {
5751
AccessKeyID string `json:"access_key_id"`
5852
AccessKeySecret string `json:"access_key_secret"`
5953
VisitUrlPrefix string `json:"visit_url_prefix"`
54+
ACL string `json:"acl"`
6055
}
6156

6257
func init() {
@@ -128,7 +123,7 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile
128123
Reader: open,
129124
}
130125
var options []oss.Option
131-
if len(aclPublicRead) > 0 {
126+
if s.Config.ACL == string(oss.ACLPublicRead) {
132127
options = append(options, oss.ObjectACL(oss.ACLPublicRead))
133128
}
134129
respBody, err := bucket.DoPutObject(request, options)
@@ -256,6 +251,24 @@ func (s *Storage) ConfigFields() []plugin.ConfigField {
256251
},
257252
Value: s.Config.VisitUrlPrefix,
258253
},
254+
{
255+
Name: "acl",
256+
Type: plugin.ConfigTypeSelect,
257+
Title: plugin.MakeTranslator(i18n.ConfigACLTitle),
258+
Description: plugin.MakeTranslator(i18n.ConfigACLDescription),
259+
Required: true,
260+
Options: []plugin.ConfigFieldOption{
261+
{
262+
Label: plugin.MakeTranslator(i18n.ConfigACLOptionsDefault),
263+
Value: string(oss.ACLDefault),
264+
},
265+
{
266+
Label: plugin.MakeTranslator(i18n.ConfigACLOptionsPublicRead),
267+
Value: string(oss.ACLPublicRead),
268+
},
269+
},
270+
Value: s.Config.ACL,
271+
},
259272
}
260273
}
261274

storage-aliyunoss/i18n/en_US.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ plugin:
5454
other: Access URL prefix
5555
description:
5656
other: prefix of the final access address of the uploaded file, ending with '/' https://example.com/xxx/
57+
acl:
58+
title:
59+
other: Object ACL
60+
description:
61+
other: Set Object ACL, default is consistent with the read and write permissions of the Bucket, can be modified to public read.
62+
options:
63+
default:
64+
other: Default
65+
public_read:
66+
other: Public Read
5767
err:
5868
mis_storage_config:
5969
other: Wrong storage configuration causes upload failure.

storage-aliyunoss/i18n/translation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const (
3535
ConfigAccessKeySecretDescription = "plugin.aliyunoss_storage.backend.config.access_key_secret.description"
3636
ConfigVisitUrlPrefixTitle = "plugin.aliyunoss_storage.backend.config.visit_url_prefix.title"
3737
ConfigVisitUrlPrefixDescription = "plugin.aliyunoss_storage.backend.config.visit_url_prefix.description"
38+
ConfigACLTitle = "plugin.aliyunoss_storage.backend.config.acl.title"
39+
ConfigACLDescription = "plugin.aliyunoss_storage.backend.config.acl.description"
40+
ConfigACLOptionsDefault = "plugin.aliyunoss_storage.backend.config.acl.options.default"
41+
ConfigACLOptionsPublicRead = "plugin.aliyunoss_storage.backend.config.acl.options.public_read"
3842

3943
ErrMisStorageConfig = "plugin.aliyunoss_storage.backend.err.mis_storage_config"
4044
ErrFileNotFound = "plugin.aliyunoss_storage.backend.err.file_not_found"

storage-aliyunoss/i18n/zh_CN.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ plugin:
5454
other: 访问URL前缀
5555
description:
5656
other: 上传文件最终访问地址的前缀,以 '/' 结尾 https://example.com/xxx/
57+
acl:
58+
title:
59+
other: Object ACL
60+
description:
61+
other: 设置 Object ACL,默认和 Bucket 的读写权限一致,可修改为公共读。
62+
options:
63+
default:
64+
other: 默认
65+
public_read:
66+
other: 公共读
5767
err:
5868
mis_storage_config:
5969
other: 错误的存储配置导致上传失败

storage-tencentyuncos/i18n/en_US.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ plugin:
5454
other: Access URL prefix
5555
description:
5656
other: prefix of the final access address of the uploaded file, ending with '/' https://example.com/xxx/
57+
acl:
58+
title:
59+
other: Object ACL
60+
description:
61+
other: Set Object ACL, default is consistent with the read and write permissions of the Bucket, can be modified to public read.
62+
options:
63+
default:
64+
other: Default
65+
public_read:
66+
other: Public Read
5767
err:
5868
mis_storage_config:
5969
other: Wrong storage configuration causes upload failure.

storage-tencentyuncos/i18n/translation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const (
3535
ConfigSecretKeyDescription = "plugin.tencentyuncos_storage.backend.config.secret_key.description"
3636
ConfigVisitUrlPrefixTitle = "plugin.tencentyuncos_storage.backend.config.visit_url_prefix.title"
3737
ConfigVisitUrlPrefixDescription = "plugin.tencentyuncos_storage.backend.config.visit_url_prefix.description"
38+
ConfigACLTitle = "plugin.tencentyuncos_storage.backend.config.acl.title"
39+
ConfigACLDescription = "plugin.tencentyuncos_storage.backend.config.acl.description"
40+
ConfigACLOptionsDefault = "plugin.tencentyuncos_storage.backend.config.acl.options.default"
41+
ConfigACLOptionsPublicRead = "plugin.tencentyuncos_storage.backend.config.acl.options.public_read"
3842

3943
ErrMisStorageConfig = "plugin.tencentyuncos_storage.backend.err.mis_storage_config"
4044
ErrFileNotFound = "plugin.tencentyuncos_storage.backend.err.file_not_found"

storage-tencentyuncos/i18n/zh_CN.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ plugin:
5454
other: 访问URL前缀
5555
description:
5656
other: 上传文件最终访问地址的前缀,以 '/' 结尾 https://example.com/xxx/
57+
acl:
58+
title:
59+
other: Object ACL
60+
description:
61+
other: 设置 Object ACL,默认和 Bucket 的读写权限一致,可修改为公共读。
62+
options:
63+
default:
64+
other: 默认
65+
public_read:
66+
other: 公共读
5767
err:
5868
mis_storage_config:
5969
other: 错误的存储配置导致上传失败

storage-tencentyuncos/tencentyuncos.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"fmt"
2828
"net/http"
2929
"net/url"
30-
"os"
3130
"path/filepath"
3231
"strings"
3332
"time"
@@ -43,11 +42,6 @@ import (
4342
//go:embed info.yaml
4443
var Info embed.FS
4544

46-
var (
47-
// aclPublicRead is the environment variable for some special platforms such as digital ocean
48-
aclPublicRead = os.Getenv("ACL_PUBLIC_READ")
49-
)
50-
5145
type Storage struct {
5246
Config *StorageConfig
5347
}
@@ -59,6 +53,7 @@ type StorageConfig struct {
5953
SecretID string `json:"secret_id"`
6054
SecretKey string `json:"secret_key"`
6155
VisitUrlPrefix string `json:"visit_url_prefix"`
56+
ACL string `json:"acl"`
6257
}
6358

6459
func init() {
@@ -129,7 +124,7 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile
129124

130125
objectKey := s.createObjectKey(file.Filename, condition.Source)
131126
var options *cos.ObjectPutOptions
132-
if len(aclPublicRead) > 0 {
127+
if s.Config.ACL == "public-read" {
133128
options = &cos.ObjectPutOptions{
134129
ACLHeaderOptions: &cos.ACLHeaderOptions{
135130
XCosACL: "public-read",
@@ -268,6 +263,24 @@ func (s *Storage) ConfigFields() []plugin.ConfigField {
268263
},
269264
Value: s.Config.VisitUrlPrefix,
270265
},
266+
{
267+
Name: "acl",
268+
Type: plugin.ConfigTypeSelect,
269+
Title: plugin.MakeTranslator(i18n.ConfigACLTitle),
270+
Description: plugin.MakeTranslator(i18n.ConfigACLDescription),
271+
Required: true,
272+
Options: []plugin.ConfigFieldOption{
273+
{
274+
Label: plugin.MakeTranslator(i18n.ConfigACLOptionsDefault),
275+
Value: "default",
276+
},
277+
{
278+
Label: plugin.MakeTranslator(i18n.ConfigACLOptionsPublicRead),
279+
Value: "public-read",
280+
},
281+
},
282+
Value: s.Config.ACL,
283+
},
271284
}
272285
}
273286

0 commit comments

Comments
 (0)