support_bundle.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2018 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package api
  7. import (
  8. "archive/zip"
  9. "io"
  10. "github.com/syncthing/syncthing/lib/config"
  11. )
  12. // getRedactedConfig redacting some parts of config
  13. func getRedactedConfig(s *service) config.Configuration {
  14. rawConf := s.cfg.RawCopy()
  15. rawConf.GUI.APIKey = "REDACTED"
  16. if rawConf.GUI.Password != "" {
  17. rawConf.GUI.Password = "REDACTED"
  18. }
  19. if rawConf.GUI.User != "" {
  20. rawConf.GUI.User = "REDACTED"
  21. }
  22. for folderIdx, folderCfg := range rawConf.Folders {
  23. for deviceIdx, deviceCfg := range folderCfg.Devices {
  24. if deviceCfg.EncryptionPassword != "" {
  25. rawConf.Folders[folderIdx].Devices[deviceIdx].EncryptionPassword = "REDACTED"
  26. }
  27. }
  28. }
  29. return rawConf
  30. }
  31. // writeZip writes a zip file containing the given entries
  32. func writeZip(writer io.Writer, files []fileEntry) error {
  33. zipWriter := zip.NewWriter(writer)
  34. defer zipWriter.Close()
  35. for _, file := range files {
  36. zipFile, err := zipWriter.Create(file.name)
  37. if err != nil {
  38. return err
  39. }
  40. _, err = zipFile.Write(file.data)
  41. if err != nil {
  42. return err
  43. }
  44. }
  45. return zipWriter.Close()
  46. }