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.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2019 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. "encoding/base64"
  7. "time"
  8. "code.gitea.io/gitea/modules/generate"
  9. "code.gitea.io/gitea/modules/log"
  10. ini "gopkg.in/ini.v1"
  11. )
  12. // LFS represents the configuration for Git LFS
  13. var LFS = struct {
  14. StartServer bool `ini:"LFS_START_SERVER"`
  15. JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
  16. JWTSecretBytes []byte `ini:"-"`
  17. HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
  18. MaxFileSize int64 `ini:"LFS_MAX_FILE_SIZE"`
  19. LocksPagingNum int `ini:"LFS_LOCKS_PAGING_NUM"`
  20. Storage
  21. }{}
  22. func newLFSService() {
  23. sec := Cfg.Section("server")
  24. if err := sec.MapTo(&LFS); err != nil {
  25. log.Fatal("Failed to map LFS settings: %v", err)
  26. }
  27. lfsSec := Cfg.Section("lfs")
  28. storageType := lfsSec.Key("STORAGE_TYPE").MustString("")
  29. // Specifically default PATH to LFS_CONTENT_PATH
  30. lfsSec.Key("PATH").MustString(
  31. sec.Key("LFS_CONTENT_PATH").String())
  32. LFS.Storage = getStorage("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(20 * time.Minute)
  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. CreateOrAppendToCustomConf(func(cfg *ini.File) {
  49. cfg.Section("server").Key("LFS_JWT_SECRET").SetValue(LFS.JWTSecretBase64)
  50. })
  51. }
  52. }
  53. }