config.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package config
  2. // Action represents the core functionality of OliveTin - commands that show up
  3. // as buttons in the UI.
  4. type Action struct {
  5. ID string
  6. Title string
  7. Icon string
  8. Shell string
  9. CSS map[string]string `mapstructure:"omitempty"`
  10. Timeout int
  11. Permissions []PermissionsEntry
  12. Arguments []ActionArgument
  13. }
  14. // ActionArgument objects appear on Actions.
  15. type ActionArgument struct {
  16. Name string
  17. Title string
  18. Type string
  19. Default string
  20. Choices []ActionArgumentChoice
  21. }
  22. // ActionArgumentChoice represents a predefined choice for an argument.
  23. type ActionArgumentChoice struct {
  24. Value string
  25. Title string
  26. }
  27. // Entity represents a "thing" that can have multiple actions associated with it.
  28. // for example, a media player with a start and stop action.
  29. type Entity struct {
  30. Title string
  31. Icon string
  32. Actions []Action `mapstructure:"actions"`
  33. CSS map[string]string
  34. }
  35. // PermissionsEntry defines what users can do with an action.
  36. type PermissionsEntry struct {
  37. Usergroup string
  38. View bool
  39. Exec bool
  40. }
  41. // DefaultPermissions will be used when no PermissionsEntry overrides it.
  42. type DefaultPermissions struct {
  43. View bool
  44. Exec bool
  45. }
  46. // UserGroup is a group of users.
  47. type UserGroup struct {
  48. Name string
  49. Members []string
  50. }
  51. // Config is the global config used through the whole app.
  52. type Config struct {
  53. UseSingleHTTPFrontend bool
  54. ThemeName string
  55. HideNavigation bool
  56. ShowFooter bool
  57. ListenAddressSingleHTTPFrontend string
  58. ListenAddressWebUI string
  59. ListenAddressRestActions string
  60. ListenAddressGrpcActions string
  61. ExternalRestAddress string
  62. LogLevel string
  63. Actions []Action `mapstructure:"actions"`
  64. Entities []Entity `mapstructure:"entities"`
  65. CheckForUpdates bool
  66. ShowNewVersions bool
  67. Usergroups []UserGroup
  68. DefaultPermissions DefaultPermissions
  69. }
  70. // DefaultConfig gets a new Config structure with sensible default values.
  71. func DefaultConfig() *Config {
  72. config := Config{}
  73. config.UseSingleHTTPFrontend = true
  74. config.HideNavigation = false
  75. config.ShowFooter = true
  76. config.ListenAddressSingleHTTPFrontend = "0.0.0.0:1337"
  77. config.ListenAddressRestActions = "localhost:1338"
  78. config.ListenAddressGrpcActions = "localhost:1339"
  79. config.ListenAddressWebUI = "localhost:1340"
  80. config.LogLevel = "INFO"
  81. config.CheckForUpdates = true
  82. config.ShowNewVersions = true
  83. config.DefaultPermissions.Exec = true
  84. config.DefaultPermissions.View = true
  85. return &config
  86. }