config.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Rufs - Remote Union File System
  3. *
  4. * Copyright 2017 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package config
  11. import "fmt"
  12. /*
  13. ProductVersion is the current version of Rufs
  14. */
  15. const ProductVersion = "1.1.0"
  16. /*
  17. Defaut configuration keys
  18. */
  19. const (
  20. // Branch configuration (export)
  21. BranchName = "BranchName"
  22. BranchSecret = "BranchSecret"
  23. EnableReadOnly = "EnableReadOnly"
  24. RPCHost = "RPCHost"
  25. RPCPort = "RPCPort"
  26. LocalFolder = "LocalFolder"
  27. // Tree configuration
  28. TreeSecret = "TreeSecret"
  29. )
  30. /*
  31. DefaultBranchExportConfig is the default configuration for an exported branch
  32. */
  33. var DefaultBranchExportConfig = map[string]interface{}{
  34. BranchName: "", // Auto name (based on available network interface)
  35. BranchSecret: "", // Secret needs to be provided by the client
  36. EnableReadOnly: false, // FS access is readonly for clients
  37. RPCHost: "", // Auto (first available external interface)
  38. RPCPort: "9020", // Communication port for this branch
  39. LocalFolder: "share", // Local folder which is being made available
  40. }
  41. /*
  42. DefaultTreeConfig is the default configuration for a tree which imports branches
  43. */
  44. var DefaultTreeConfig = map[string]interface{}{
  45. TreeSecret: "", // Secret needs to be provided by the client
  46. }
  47. // Helper functions
  48. // ================
  49. /*
  50. CheckBranchExportConfig checks a given branch export config.
  51. */
  52. func CheckBranchExportConfig(config map[string]interface{}) error {
  53. for k := range DefaultBranchExportConfig {
  54. if _, ok := config[k]; !ok {
  55. return fmt.Errorf("Missing %v key in branch export config", k)
  56. }
  57. }
  58. return nil
  59. }
  60. /*
  61. CheckTreeConfig checks a given tree config.
  62. */
  63. func CheckTreeConfig(config map[string]interface{}) error {
  64. for k := range DefaultTreeConfig {
  65. if _, ok := config[k]; !ok {
  66. return fmt.Errorf("Missing %v key in tree config", k)
  67. }
  68. }
  69. return nil
  70. }