You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

storage.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "strings"
  7. "code.gitea.io/gitea/modules/log"
  8. ini "gopkg.in/ini.v1"
  9. )
  10. // enumerate all storage types
  11. const (
  12. LocalStorageType = "local"
  13. MinioStorageType = "minio"
  14. )
  15. // Storage represents configuration of storages
  16. type Storage struct {
  17. Type string
  18. Path string
  19. ServeDirect bool
  20. Minio struct {
  21. Endpoint string
  22. AccessKeyID string
  23. SecretAccessKey string
  24. UseSSL bool
  25. Bucket string
  26. Location string
  27. BasePath string
  28. }
  29. }
  30. var (
  31. storages = make(map[string]Storage)
  32. )
  33. func getStorage(sec *ini.Section) Storage {
  34. var storage Storage
  35. storage.Type = sec.Key("STORAGE_TYPE").MustString(LocalStorageType)
  36. storage.ServeDirect = sec.Key("SERVE_DIRECT").MustBool(false)
  37. switch storage.Type {
  38. case LocalStorageType:
  39. case MinioStorageType:
  40. storage.Minio.Endpoint = sec.Key("MINIO_ENDPOINT").MustString("localhost:9000")
  41. storage.Minio.AccessKeyID = sec.Key("MINIO_ACCESS_KEY_ID").MustString("")
  42. storage.Minio.SecretAccessKey = sec.Key("MINIO_SECRET_ACCESS_KEY").MustString("")
  43. storage.Minio.Bucket = sec.Key("MINIO_BUCKET").MustString("gitea")
  44. storage.Minio.Location = sec.Key("MINIO_LOCATION").MustString("us-east-1")
  45. storage.Minio.UseSSL = sec.Key("MINIO_USE_SSL").MustBool(false)
  46. }
  47. return storage
  48. }
  49. func newStorageService() {
  50. sec := Cfg.Section("storage")
  51. storages["default"] = getStorage(sec)
  52. for _, sec := range Cfg.Section("storage").ChildSections() {
  53. name := strings.TrimPrefix(sec.Name(), "storage.")
  54. if name == "default" || name == LocalStorageType || name == MinioStorageType {
  55. log.Error("storage name %s is system reserved!", name)
  56. continue
  57. }
  58. storages[name] = getStorage(sec)
  59. }
  60. }