config.go 3.5 KB

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