summaryrefslogtreecommitdiffstats
path: root/modules/storage/minio.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-06-14 11:42:38 +0800
committerGitHub <noreply@github.com>2023-06-14 11:42:38 +0800
commitd6dd6d641b593c54fe1a1041c153111ce81dbc20 (patch)
treef9e7959356124bd830ce0b9e9e51c1373aa71932 /modules/storage/minio.go
parentdc0a7168f1450d45164fde63c56f04a1e5bbb949 (diff)
downloadgitea-d6dd6d641b593c54fe1a1041c153111ce81dbc20.tar.gz
gitea-d6dd6d641b593c54fe1a1041c153111ce81dbc20.zip
Fix all possible setting error related storages and added some tests (#23911)
Follow up #22405 Fix #20703 This PR rewrites storage configuration read sequences with some breaks and tests. It becomes more strict than before and also fixed some inherit problems. - Move storage's MinioConfig struct into setting, so after the configuration loading, the values will be stored into the struct but not still on some section. - All storages configurations should be stored on one section, configuration items cannot be overrided by multiple sections. The prioioty of configuration is `[attachment]` > `[storage.attachments]` | `[storage.customized]` > `[storage]` > `default` - For extra override configuration items, currently are `SERVE_DIRECT`, `MINIO_BASE_PATH`, `MINIO_BUCKET`, which could be configured in another section. The prioioty of the override configuration is `[attachment]` > `[storage.attachments]` > `default`. - Add more tests for storages configurations. - Update the storage documentations. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/storage/minio.go')
-rw-r--r--modules/storage/minio.go30
1 files changed, 5 insertions, 25 deletions
diff --git a/modules/storage/minio.go b/modules/storage/minio.go
index c78f351e9c..81774fb9cf 100644
--- a/modules/storage/minio.go
+++ b/modules/storage/minio.go
@@ -16,6 +16,7 @@ import (
"time"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/minio/minio-go/v7"
@@ -41,25 +42,9 @@ func (m *minioObject) Stat() (os.FileInfo, error) {
return &minioFileInfo{oi}, nil
}
-// MinioStorageType is the type descriptor for minio storage
-const MinioStorageType Type = "minio"
-
-// MinioStorageConfig represents the configuration for a minio storage
-type MinioStorageConfig struct {
- Endpoint string `ini:"MINIO_ENDPOINT"`
- AccessKeyID string `ini:"MINIO_ACCESS_KEY_ID"`
- SecretAccessKey string `ini:"MINIO_SECRET_ACCESS_KEY"`
- Bucket string `ini:"MINIO_BUCKET"`
- Location string `ini:"MINIO_LOCATION"`
- BasePath string `ini:"MINIO_BASE_PATH"`
- UseSSL bool `ini:"MINIO_USE_SSL"`
- InsecureSkipVerify bool `ini:"MINIO_INSECURE_SKIP_VERIFY"`
- ChecksumAlgorithm string `ini:"MINIO_CHECKSUM_ALGORITHM"`
-}
-
// MinioStorage returns a minio bucket storage
type MinioStorage struct {
- cfg *MinioStorageConfig
+ cfg *setting.MinioStorageConfig
ctx context.Context
client *minio.Client
bucket string
@@ -87,13 +72,8 @@ func convertMinioErr(err error) error {
}
// NewMinioStorage returns a minio storage
-func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error) {
- configInterface, err := toConfig(MinioStorageConfig{}, cfg)
- if err != nil {
- return nil, convertMinioErr(err)
- }
- config := configInterface.(MinioStorageConfig)
-
+func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage, error) {
+ config := cfg.MinioConfig
if config.ChecksumAlgorithm != "" && config.ChecksumAlgorithm != "default" && config.ChecksumAlgorithm != "md5" {
return nil, fmt.Errorf("invalid minio checksum algorithm: %s", config.ChecksumAlgorithm)
}
@@ -258,5 +238,5 @@ func (m *MinioStorage) IterateObjects(dirName string, fn func(path string, obj O
}
func init() {
- RegisterStorageType(MinioStorageType, NewMinioStorage)
+ RegisterStorageType(setting.MinioStorageType, NewMinioStorage)
}