Skip to content

Commit 846284c

Browse files
committed
introduce MINIO_CHECKSUM_ALGORITHM
1 parent 0bcac8f commit 846284c

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

cmd/migrate_storage.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,21 @@ var CmdMigrateStorage = cli.Command{
7272
cli.StringFlag{
7373
Name: "minio-base-path",
7474
Value: "",
75-
Usage: "Minio storage basepath on the bucket",
75+
Usage: "Minio storage base path on the bucket",
7676
},
7777
cli.BoolFlag{
7878
Name: "minio-use-ssl",
7979
Usage: "Enable SSL for minio",
8080
},
81+
cli.BoolFlag{
82+
Name: "minio-insecure-skip-verify",
83+
Usage: "Skip SSL verification",
84+
},
85+
cli.StringFlag{
86+
Name: "minio-checksum-algorithm",
87+
Value: "",
88+
Usage: "Minio checksum algorithm (default/md5)",
89+
},
8190
},
8291
}
8392

@@ -168,13 +177,15 @@ func runMigrateStorage(ctx *cli.Context) error {
168177
dstStorage, err = storage.NewMinioStorage(
169178
stdCtx,
170179
storage.MinioStorageConfig{
171-
Endpoint: ctx.String("minio-endpoint"),
172-
AccessKeyID: ctx.String("minio-access-key-id"),
173-
SecretAccessKey: ctx.String("minio-secret-access-key"),
174-
Bucket: ctx.String("minio-bucket"),
175-
Location: ctx.String("minio-location"),
176-
BasePath: ctx.String("minio-base-path"),
177-
UseSSL: ctx.Bool("minio-use-ssl"),
180+
Endpoint: ctx.String("minio-endpoint"),
181+
AccessKeyID: ctx.String("minio-access-key-id"),
182+
SecretAccessKey: ctx.String("minio-secret-access-key"),
183+
Bucket: ctx.String("minio-bucket"),
184+
Location: ctx.String("minio-location"),
185+
BasePath: ctx.String("minio-base-path"),
186+
UseSSL: ctx.Bool("minio-use-ssl"),
187+
InsecureSkipVerify: ctx.Bool("minio-insecure-skip-verify"),
188+
ChecksumAlgorithm: ctx.String("minio-checksum-algorithm"),
178189
})
179190
default:
180191
return fmt.Errorf("unsupported storage type: %s", ctx.String("storage"))

custom/conf/app.example.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,15 @@ ROUTER = console
583583
;; * In request Header: X-Request-ID: test-id-123
584584
;; * Configuration in app.ini: REQUEST_ID_HEADERS = X-Request-ID
585585
;; * Print in log: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "test-id-123"
586-
;;
587-
;; If you configure more than one in the .ini file, it will match in the order of configuration,
586+
;;
587+
;; If you configure more than one in the .ini file, it will match in the order of configuration,
588588
;; and the first match will be finally printed in the log.
589589
;; * E.g:
590590
;; * In reuqest Header: X-Trace-ID: trace-id-1q2w3e4r
591591
;; * Configuration in app.ini: REQUEST_ID_HEADERS = X-Request-ID, X-Trace-ID, X-Req-ID
592592
;; * Print in log: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "trace-id-1q2w3e4r"
593593
;;
594-
;; REQUEST_ID_HEADERS =
594+
;; REQUEST_ID_HEADERS =
595595

596596
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
597597
;;
@@ -1886,6 +1886,9 @@ ROUTER = console
18861886
;;
18871887
;; Minio skip SSL verification available when STORAGE_TYPE is `minio`
18881888
;MINIO_INSECURE_SKIP_VERIFY = false
1889+
;;
1890+
;; Minio checksum algorithm: default (for MinIO or AWS S3) or md5 (for Cloudflare or Backblaze)
1891+
;MINIO_CHECKSUM_ALGORITHM = default
18891892

18901893
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18911894
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ Default templates for project boards:
855855
- `MINIO_BASE_PATH`: **attachments/**: Minio base path on the bucket only available when STORAGE_TYPE is `minio`
856856
- `MINIO_USE_SSL`: **false**: Minio enabled ssl only available when STORAGE_TYPE is `minio`
857857
- `MINIO_INSECURE_SKIP_VERIFY`: **false**: Minio skip SSL verification available when STORAGE_TYPE is `minio`
858+
- `MINIO_CHECKSUM_ALGORITHM`: **default**: Minio checksum algorithm: `default` (for MinIO or AWS S3) or `md5` (for Cloudflare or Backblaze)
858859

859860
## Log (`log`)
860861

modules/setting/storage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func getStorage(rootCfg ConfigProvider, name, typ string, targetSec *ini.Section
4242
sec.Key("MINIO_LOCATION").MustString("us-east-1")
4343
sec.Key("MINIO_USE_SSL").MustBool(false)
4444
sec.Key("MINIO_INSECURE_SKIP_VERIFY").MustBool(false)
45+
sec.Key("MINIO_CHECKSUM_ALGORITHM").MustString("default")
4546

4647
if targetSec == nil {
4748
targetSec, _ = rootCfg.NewSection(name)

modules/storage/minio.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package storage
66
import (
77
"context"
88
"crypto/tls"
9+
"fmt"
910
"io"
1011
"net/http"
1112
"net/url"
@@ -53,10 +54,12 @@ type MinioStorageConfig struct {
5354
BasePath string `ini:"MINIO_BASE_PATH"`
5455
UseSSL bool `ini:"MINIO_USE_SSL"`
5556
InsecureSkipVerify bool `ini:"MINIO_INSECURE_SKIP_VERIFY"`
57+
ChecksumAlgorithm string `ini:"MINIO_CHECKSUM_ALGORITHM"`
5658
}
5759

5860
// MinioStorage returns a minio bucket storage
5961
type MinioStorage struct {
62+
cfg *MinioStorageConfig
6063
ctx context.Context
6164
client *minio.Client
6265
bucket string
@@ -91,6 +94,10 @@ func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
9194
}
9295
config := configInterface.(MinioStorageConfig)
9396

97+
if config.ChecksumAlgorithm != "" && config.ChecksumAlgorithm != "default" && config.ChecksumAlgorithm != "md5" {
98+
return nil, fmt.Errorf("invalid minio checksum algorithm: %s", config.ChecksumAlgorithm)
99+
}
100+
94101
log.Info("Creating Minio storage at %s:%s with base path %s", config.Endpoint, config.Bucket, config.BasePath)
95102

96103
minioClient, err := minio.New(config.Endpoint, &minio.Options{
@@ -113,6 +120,7 @@ func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
113120
}
114121

115122
return &MinioStorage{
123+
cfg: &config,
116124
ctx: ctx,
117125
client: minioClient,
118126
bucket: config.Bucket,
@@ -124,7 +132,7 @@ func (m *MinioStorage) buildMinioPath(p string) string {
124132
return util.PathJoinRelX(m.basePath, p)
125133
}
126134

127-
// Open open a file
135+
// Open opens a file
128136
func (m *MinioStorage) Open(path string) (Object, error) {
129137
opts := minio.GetObjectOptions{}
130138
object, err := m.client.GetObject(m.ctx, m.bucket, m.buildMinioPath(path), opts)
@@ -134,7 +142,7 @@ func (m *MinioStorage) Open(path string) (Object, error) {
134142
return &minioObject{object}, nil
135143
}
136144

137-
// Save save a file to minio
145+
// Save saves a file to minio
138146
func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error) {
139147
uploadInfo, err := m.client.PutObject(
140148
m.ctx,
@@ -148,7 +156,7 @@ func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error)
148156
// * https://developers.cloudflare.com/r2/api/s3/api/
149157
// * https://www.backblaze.com/b2/docs/s3_compatible_api.html
150158
// do not support "x-amz-checksum-algorithm" header, so use legacy MD5 checksum
151-
SendContentMd5: true,
159+
SendContentMd5: m.cfg.ChecksumAlgorithm == "md5",
152160
},
153161
)
154162
if err != nil {

0 commit comments

Comments
 (0)