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 1.9KB

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. ini "gopkg.in/ini.v1"
  10. )
  11. // LFS represents the configuration for Git LFS
  12. var LFS = struct {
  13. StartServer bool `ini:"LFS_START_SERVER"`
  14. JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
  15. JWTSecretBytes []byte `ini:"-"`
  16. HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
  17. MaxFileSize int64 `ini:"LFS_MAX_FILE_SIZE"`
  18. LocksPagingNum int `ini:"LFS_LOCKS_PAGING_NUM"`
  19. Storage
  20. }{}
  21. func newLFSService() {
  22. sec := Cfg.Section("server")
  23. if err := sec.MapTo(&LFS); err != nil {
  24. log.Fatal("Failed to map LFS settings: %v", err)
  25. }
  26. lfsSec := Cfg.Section("lfs")
  27. storageType := lfsSec.Key("STORAGE_TYPE").MustString("")
  28. // Specifically default PATH to LFS_CONTENT_PATH
  29. // FIXME: DEPRECATED to be removed in v1.18.0
  30. deprecatedSetting("server", "LFS_CONTENT_PATH", "lfs", "PATH")
  31. lfsSec.Key("PATH").MustString(
  32. sec.Key("LFS_CONTENT_PATH").String())
  33. LFS.Storage = getStorage("lfs", storageType, lfsSec)
  34. // Rest of LFS service settings
  35. if LFS.LocksPagingNum == 0 {
  36. LFS.LocksPagingNum = 50
  37. }
  38. LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(20 * time.Minute)
  39. if LFS.StartServer {
  40. LFS.JWTSecretBytes = make([]byte, 32)
  41. n, err := base64.RawURLEncoding.Decode(LFS.JWTSecretBytes, []byte(LFS.JWTSecretBase64))
  42. if err != nil || n != 32 {
  43. LFS.JWTSecretBase64, err = generate.NewJwtSecretBase64()
  44. if err != nil {
  45. log.Fatal("Error generating JWT Secret for custom config: %v", err)
  46. return
  47. }
  48. // Save secret
  49. CreateOrAppendToCustomConf("server.LFS_JWT_SECRET", func(cfg *ini.File) {
  50. cfg.Section("server").Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
  51. })
  52. }
  53. }
  54. }