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.

lfs.go 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import (
  5. "encoding/base64"
  6. "time"
  7. "code.gitea.io/gitea/modules/generate"
  8. "code.gitea.io/gitea/modules/log"
  9. )
  10. // LFS represents the configuration for Git LFS
  11. var LFS = struct {
  12. StartServer bool `ini:"LFS_START_SERVER"`
  13. JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
  14. JWTSecretBytes []byte `ini:"-"`
  15. HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
  16. MaxFileSize int64 `ini:"LFS_MAX_FILE_SIZE"`
  17. LocksPagingNum int `ini:"LFS_LOCKS_PAGING_NUM"`
  18. Storage
  19. }{}
  20. func loadLFSFrom(rootCfg ConfigProvider) {
  21. sec := rootCfg.Section("server")
  22. if err := sec.MapTo(&LFS); err != nil {
  23. log.Fatal("Failed to map LFS settings: %v", err)
  24. }
  25. lfsSec := rootCfg.Section("lfs")
  26. storageType := lfsSec.Key("STORAGE_TYPE").MustString("")
  27. // Specifically default PATH to LFS_CONTENT_PATH
  28. // DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
  29. // if these are removed, the warning will not be shown
  30. deprecatedSetting(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0")
  31. lfsSec.Key("PATH").MustString(sec.Key("LFS_CONTENT_PATH").String())
  32. LFS.Storage = getStorage(rootCfg, "lfs", storageType, lfsSec)
  33. // Rest of LFS service settings
  34. if LFS.LocksPagingNum == 0 {
  35. LFS.LocksPagingNum = 50
  36. }
  37. LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
  38. if LFS.StartServer {
  39. LFS.JWTSecretBytes = make([]byte, 32)
  40. n, err := base64.RawURLEncoding.Decode(LFS.JWTSecretBytes, []byte(LFS.JWTSecretBase64))
  41. if err != nil || n != 32 {
  42. LFS.JWTSecretBase64, err = generate.NewJwtSecretBase64()
  43. if err != nil {
  44. log.Fatal("Error generating JWT Secret for custom config: %v", err)
  45. return
  46. }
  47. // Save secret
  48. sec.Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
  49. if err := rootCfg.Save(); err != nil {
  50. log.Fatal("Error saving JWT Secret for custom config: %v", err)
  51. return
  52. }
  53. }
  54. }
  55. }