support_bundle.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. return rawConf
  23. }
  24. // writeZip writes a zip file containing the given entries
  25. func writeZip(writer io.Writer, files []fileEntry) error {
  26. zipWriter := zip.NewWriter(writer)
  27. defer zipWriter.Close()
  28. for _, file := range files {
  29. zipFile, err := zipWriter.Create(file.name)
  30. if err != nil {
  31. return err
  32. }
  33. _, err = zipFile.Write(file.data)
  34. if err != nil {
  35. return err
  36. }
  37. }
  38. return zipWriter.Close()
  39. }