config.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. Acls []string
  12. ExecOnStartup bool
  13. ExecOnCron []string
  14. Arguments []ActionArgument
  15. }
  16. // ActionArgument objects appear on Actions.
  17. type ActionArgument struct {
  18. Name string
  19. Title string
  20. Description string
  21. Type string
  22. Default string
  23. Choices []ActionArgumentChoice
  24. }
  25. // ActionArgumentChoice represents a predefined choice for an argument.
  26. type ActionArgumentChoice struct {
  27. Value string
  28. Title string
  29. }
  30. // Entity represents a "thing" that can have multiple actions associated with it.
  31. // for example, a media player with a start and stop action.
  32. type Entity struct {
  33. Title string
  34. Icon string
  35. Actions []Action `mapstructure:"actions"`
  36. CSS map[string]string
  37. }
  38. // PermissionsList defines what users can do with an action.
  39. type PermissionsList struct {
  40. View bool
  41. Exec bool
  42. }
  43. // AccessControlList defines what permissions apply to a user or user group.
  44. type AccessControlList struct {
  45. Name string
  46. AddToEveryAction bool
  47. MatchUsergroups []string
  48. MatchUsernames []string
  49. Permissions PermissionsList
  50. }
  51. // Config is the global config used through the whole app.
  52. type Config struct {
  53. UseSingleHTTPFrontend bool
  54. ThemeName string
  55. ListenAddressSingleHTTPFrontend string
  56. ListenAddressWebUI string
  57. ListenAddressRestActions string
  58. ListenAddressGrpcActions string
  59. ExternalRestAddress string
  60. LogLevel string
  61. Actions []Action `mapstructure:"actions"`
  62. Entities []Entity `mapstructure:"entities"`
  63. CheckForUpdates bool
  64. PageTitle string
  65. ShowFooter bool
  66. ShowNavigation bool
  67. ShowNewVersions bool
  68. AuthJwtCookieName string
  69. AuthJwtSecret string
  70. AuthJwtClaimUsername string
  71. AuthJwtClaimUserGroup string
  72. AuthHttpHeaderUsername string
  73. AuthHttpHeaderUserGroup string
  74. DefaultPermissions PermissionsList
  75. AccessControlLists []AccessControlList
  76. WebUIDir string
  77. }
  78. // DefaultConfig gets a new Config structure with sensible default values.
  79. func DefaultConfig() *Config {
  80. config := Config{}
  81. config.UseSingleHTTPFrontend = true
  82. config.PageTitle = "OliveTin"
  83. config.ShowFooter = true
  84. config.ShowNavigation = true
  85. config.ShowNewVersions = true
  86. config.ListenAddressSingleHTTPFrontend = "0.0.0.0:1337"
  87. config.ListenAddressRestActions = "localhost:1338"
  88. config.ListenAddressGrpcActions = "localhost:1339"
  89. config.ListenAddressWebUI = "localhost:1340"
  90. config.ExternalRestAddress = "."
  91. config.LogLevel = "INFO"
  92. config.CheckForUpdates = true
  93. config.DefaultPermissions.Exec = true
  94. config.DefaultPermissions.View = true
  95. config.AuthJwtClaimUsername = "name"
  96. config.AuthJwtClaimUserGroup = "group"
  97. config.WebUIDir = "./webui"
  98. return &config
  99. }