Merge pull request 'add bucket lookup type' (#2482) from jilen/forgejo:minio_bucket_lookup into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2482 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
20e3e671c6
6 changed files with 74 additions and 8 deletions
|
@ -41,6 +41,7 @@ type MinioStorageConfig struct {
|
|||
AccessKeyID string `ini:"MINIO_ACCESS_KEY_ID" json:",omitempty"`
|
||||
SecretAccessKey string `ini:"MINIO_SECRET_ACCESS_KEY" json:",omitempty"`
|
||||
Bucket string `ini:"MINIO_BUCKET" json:",omitempty"`
|
||||
BucketLookup string `ini:"MINIO_BUCKET_LOOKUP" json:",omitempty"`
|
||||
Location string `ini:"MINIO_LOCATION" json:",omitempty"`
|
||||
BasePath string `ini:"MINIO_BASE_PATH" json:",omitempty"`
|
||||
UseSSL bool `ini:"MINIO_USE_SSL"`
|
||||
|
@ -78,6 +79,7 @@ func getDefaultStorageSection(rootCfg ConfigProvider) ConfigSection {
|
|||
storageSec.Key("MINIO_ACCESS_KEY_ID").MustString("")
|
||||
storageSec.Key("MINIO_SECRET_ACCESS_KEY").MustString("")
|
||||
storageSec.Key("MINIO_BUCKET").MustString("gitea")
|
||||
storageSec.Key("MINIO_BUCKET_LOOKUP").MustString("auto")
|
||||
storageSec.Key("MINIO_LOCATION").MustString("us-east-1")
|
||||
storageSec.Key("MINIO_USE_SSL").MustBool(false)
|
||||
storageSec.Key("MINIO_INSECURE_SKIP_VERIFY").MustBool(false)
|
||||
|
|
|
@ -82,14 +82,26 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage,
|
|||
if config.ChecksumAlgorithm != "" && config.ChecksumAlgorithm != "default" && config.ChecksumAlgorithm != "md5" {
|
||||
return nil, fmt.Errorf("invalid minio checksum algorithm: %s", config.ChecksumAlgorithm)
|
||||
}
|
||||
var lookup minio.BucketLookupType
|
||||
switch config.BucketLookup {
|
||||
case "auto", "":
|
||||
lookup = minio.BucketLookupAuto
|
||||
case "dns":
|
||||
lookup = minio.BucketLookupDNS
|
||||
case "path":
|
||||
lookup = minio.BucketLookupPath
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid minio bucket lookup type %s", config.BucketLookup)
|
||||
}
|
||||
|
||||
log.Info("Creating Minio storage at %s:%s with base path %s", config.Endpoint, config.Bucket, config.BasePath)
|
||||
|
||||
minioClient, err := minio.New(config.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.AccessKeyID, config.SecretAccessKey, ""),
|
||||
Secure: config.UseSSL,
|
||||
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify}},
|
||||
Region: config.Location,
|
||||
Creds: credentials.NewStaticV4(config.AccessKeyID, config.SecretAccessKey, ""),
|
||||
Secure: config.UseSSL,
|
||||
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify}},
|
||||
Region: config.Location,
|
||||
BucketLookup: lookup,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, convertMinioErr(err)
|
||||
|
|
|
@ -31,6 +31,23 @@ func TestMinioStorageIterator(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestVirtualHostMinioStorage(t *testing.T) {
|
||||
if os.Getenv("CI") == "" {
|
||||
t.Skip("minioStorage not present outside of CI")
|
||||
return
|
||||
}
|
||||
testStorageIterator(t, setting.MinioStorageType, &setting.Storage{
|
||||
MinioConfig: setting.MinioStorageConfig{
|
||||
Endpoint: "minio:9000",
|
||||
AccessKeyID: "123456",
|
||||
SecretAccessKey: "12345678",
|
||||
Bucket: "gitea",
|
||||
Location: "us-east-1",
|
||||
BucketLookup: "dns",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestMinioStoragePath(t *testing.T) {
|
||||
m := &MinioStorage{basePath: ""}
|
||||
assert.Equal(t, "", m.buildMinioPath("/"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue