Add default storage configurations (#12813)
Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
4c6ac08182
commit
3878e985b6
19 changed files with 459 additions and 185 deletions
69
modules/setting/storage.go
Normal file
69
modules/setting/storage.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package setting
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
ini "gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
// enumerate all storage types
|
||||
const (
|
||||
LocalStorageType = "local"
|
||||
MinioStorageType = "minio"
|
||||
)
|
||||
|
||||
// Storage represents configuration of storages
|
||||
type Storage struct {
|
||||
Type string
|
||||
Path string
|
||||
ServeDirect bool
|
||||
Minio struct {
|
||||
Endpoint string
|
||||
AccessKeyID string
|
||||
SecretAccessKey string
|
||||
UseSSL bool
|
||||
Bucket string
|
||||
Location string
|
||||
BasePath string
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
storages = make(map[string]Storage)
|
||||
)
|
||||
|
||||
func getStorage(sec *ini.Section) Storage {
|
||||
var storage Storage
|
||||
storage.Type = sec.Key("STORAGE_TYPE").MustString(LocalStorageType)
|
||||
storage.ServeDirect = sec.Key("SERVE_DIRECT").MustBool(false)
|
||||
switch storage.Type {
|
||||
case LocalStorageType:
|
||||
case MinioStorageType:
|
||||
storage.Minio.Endpoint = sec.Key("MINIO_ENDPOINT").MustString("localhost:9000")
|
||||
storage.Minio.AccessKeyID = sec.Key("MINIO_ACCESS_KEY_ID").MustString("")
|
||||
storage.Minio.SecretAccessKey = sec.Key("MINIO_SECRET_ACCESS_KEY").MustString("")
|
||||
storage.Minio.Bucket = sec.Key("MINIO_BUCKET").MustString("gitea")
|
||||
storage.Minio.Location = sec.Key("MINIO_LOCATION").MustString("us-east-1")
|
||||
storage.Minio.UseSSL = sec.Key("MINIO_USE_SSL").MustBool(false)
|
||||
}
|
||||
return storage
|
||||
}
|
||||
|
||||
func newStorageService() {
|
||||
sec := Cfg.Section("storage")
|
||||
storages["default"] = getStorage(sec)
|
||||
|
||||
for _, sec := range Cfg.Section("storage").ChildSections() {
|
||||
name := strings.TrimPrefix(sec.Name(), "storage.")
|
||||
if name == "default" || name == LocalStorageType || name == MinioStorageType {
|
||||
log.Error("storage name %s is system reserved!", name)
|
||||
continue
|
||||
}
|
||||
storages[name] = getStorage(sec)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue