config.go 3.4 KB

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