2020-10-16 19:12:53 +02:00
|
|
|
package config
|
2020-10-08 18:21:27 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2020-10-09 10:27:20 +02:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2020-10-08 18:21:27 +02:00
|
|
|
)
|
|
|
|
|
2020-10-19 14:55:20 +02:00
|
|
|
const (
|
|
|
|
DefaultServerRoot = "http://localhost:8000"
|
|
|
|
DefaultPort = 8000
|
|
|
|
)
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
type AmazonS3Config struct {
|
2021-07-09 03:09:02 +02:00
|
|
|
AccessKeyID string
|
2021-05-24 19:06:11 +02:00
|
|
|
SecretAccessKey string
|
|
|
|
Bucket string
|
|
|
|
PathPrefix string
|
|
|
|
Region string
|
|
|
|
Endpoint string
|
|
|
|
SSL bool
|
|
|
|
SignV2 bool
|
|
|
|
SSE bool
|
|
|
|
Trace bool
|
|
|
|
}
|
|
|
|
|
2020-10-22 15:22:36 +02:00
|
|
|
// Configuration is the app configuration stored in a json file.
|
2020-10-08 18:21:27 +02:00
|
|
|
type Configuration struct {
|
2021-11-02 02:12:43 +01:00
|
|
|
ServerRoot string `json:"serverRoot" mapstructure:"serverRoot"`
|
|
|
|
Port int `json:"port" mapstructure:"port"`
|
|
|
|
DBType string `json:"dbtype" mapstructure:"dbtype"`
|
|
|
|
DBConfigString string `json:"dbconfig" mapstructure:"dbconfig"`
|
|
|
|
DBTablePrefix string `json:"dbtableprefix" mapstructure:"dbtableprefix"`
|
|
|
|
UseSSL bool `json:"useSSL" mapstructure:"useSSL"`
|
|
|
|
SecureCookie bool `json:"secureCookie" mapstructure:"secureCookie"`
|
|
|
|
WebPath string `json:"webpath" mapstructure:"webpath"`
|
|
|
|
FilesDriver string `json:"filesdriver" mapstructure:"filesdriver"`
|
|
|
|
FilesS3Config AmazonS3Config `json:"filess3config" mapstructure:"filess3config"`
|
|
|
|
FilesPath string `json:"filespath" mapstructure:"filespath"`
|
2022-03-29 13:09:39 +02:00
|
|
|
MaxFileSize int64 `json:"maxfilesize" mapstructure:"mafilesize"`
|
2021-11-02 02:12:43 +01:00
|
|
|
Telemetry bool `json:"telemetry" mapstructure:"telemetry"`
|
|
|
|
TelemetryID string `json:"telemetryid" mapstructure:"telemetryid"`
|
2022-04-12 23:43:29 +02:00
|
|
|
PrometheusAddress string `json:"prometheusaddress" mapstructure:"prometheusaddress"`
|
2021-11-02 02:12:43 +01:00
|
|
|
WebhookUpdate []string `json:"webhook_update" mapstructure:"webhook_update"`
|
|
|
|
Secret string `json:"secret" mapstructure:"secret"`
|
|
|
|
SessionExpireTime int64 `json:"session_expire_time" mapstructure:"session_expire_time"`
|
|
|
|
SessionRefreshTime int64 `json:"session_refresh_time" mapstructure:"session_refresh_time"`
|
|
|
|
LocalOnly bool `json:"localonly" mapstructure:"localonly"`
|
|
|
|
EnableLocalMode bool `json:"enableLocalMode" mapstructure:"enableLocalMode"`
|
|
|
|
LocalModeSocketLocation string `json:"localModeSocketLocation" mapstructure:"localModeSocketLocation"`
|
|
|
|
EnablePublicSharedBoards bool `json:"enablePublicSharedBoards" mapstructure:"enablePublicSharedBoards"`
|
|
|
|
FeatureFlags map[string]string `json:"featureFlags" mapstructure:"featureFlags"`
|
2021-03-26 19:01:54 +01:00
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
AuthMode string `json:"authMode" mapstructure:"authMode"`
|
2021-05-29 08:23:10 +02:00
|
|
|
|
2021-06-18 16:01:36 +02:00
|
|
|
LoggingCfgFile string `json:"logging_cfg_file" mapstructure:"logging_cfg_file"`
|
|
|
|
LoggingCfgJSON string `json:"logging_cfg_json" mapstructure:"logging_cfg_json"`
|
2021-06-11 14:24:51 +02:00
|
|
|
|
2021-06-18 16:01:36 +02:00
|
|
|
AuditCfgFile string `json:"audit_cfg_file" mapstructure:"audit_cfg_file"`
|
|
|
|
AuditCfgJSON string `json:"audit_cfg_json" mapstructure:"audit_cfg_json"`
|
2021-12-10 16:46:37 +01:00
|
|
|
|
|
|
|
NotifyFreqCardSeconds int `json:"notify_freq_card_seconds" mapstructure:"notify_freq_card_seconds"`
|
|
|
|
NotifyFreqBoardSeconds int `json:"notify_freq_board_seconds" mapstructure:"notify_freq_board_seconds"`
|
|
|
|
}
|
|
|
|
|
2020-10-22 15:22:36 +02:00
|
|
|
// ReadConfigFile read the configuration from the filesystem.
|
2021-10-26 14:19:20 +02:00
|
|
|
func ReadConfigFile(configFilePath string) (*Configuration, error) {
|
|
|
|
if configFilePath == "" {
|
|
|
|
viper.SetConfigFile("./config.json")
|
|
|
|
} else {
|
|
|
|
viper.SetConfigFile(configFilePath)
|
|
|
|
}
|
|
|
|
|
2021-04-01 12:36:56 +02:00
|
|
|
viper.SetEnvPrefix("focalboard")
|
|
|
|
viper.AutomaticEnv() // read config values from env like FOCALBOARD_SERVERROOT=...
|
2020-10-19 14:55:20 +02:00
|
|
|
viper.SetDefault("ServerRoot", DefaultServerRoot)
|
|
|
|
viper.SetDefault("Port", DefaultPort)
|
2020-10-09 10:27:20 +02:00
|
|
|
viper.SetDefault("DBType", "sqlite3")
|
2021-04-17 09:06:57 +02:00
|
|
|
viper.SetDefault("DBConfigString", "./focalboard.db")
|
|
|
|
viper.SetDefault("DBTablePrefix", "")
|
2021-03-26 19:01:54 +01:00
|
|
|
viper.SetDefault("SecureCookie", false)
|
2020-10-09 10:27:20 +02:00
|
|
|
viper.SetDefault("WebPath", "./pack")
|
|
|
|
viper.SetDefault("FilesPath", "./files")
|
2021-05-24 19:06:11 +02:00
|
|
|
viper.SetDefault("FilesDriver", "local")
|
2021-01-27 00:29:13 +01:00
|
|
|
viper.SetDefault("Telemetry", true)
|
2021-09-01 23:53:27 +02:00
|
|
|
viper.SetDefault("TelemetryID", "")
|
2020-10-29 21:09:02 +01:00
|
|
|
viper.SetDefault("WebhookUpdate", nil)
|
2020-12-07 17:04:35 +01:00
|
|
|
viper.SetDefault("SessionExpireTime", 60*60*24*30) // 30 days session lifetime
|
|
|
|
viper.SetDefault("SessionRefreshTime", 60*60*5) // 5 minutes session refresh
|
2021-01-27 00:29:13 +01:00
|
|
|
viper.SetDefault("LocalOnly", false)
|
2021-01-20 22:52:25 +01:00
|
|
|
viper.SetDefault("EnableLocalMode", false)
|
2021-02-01 19:31:06 +01:00
|
|
|
viper.SetDefault("LocalModeSocketLocation", "/var/tmp/focalboard_local.socket")
|
2021-09-16 21:31:02 +02:00
|
|
|
viper.SetDefault("EnablePublicSharedBoards", false)
|
2021-11-02 02:12:43 +01:00
|
|
|
viper.SetDefault("FeatureFlags", map[string]string{})
|
2021-03-26 19:01:54 +01:00
|
|
|
viper.SetDefault("AuthMode", "native")
|
2021-12-10 16:46:37 +01:00
|
|
|
viper.SetDefault("NotifyFreqCardSeconds", 120) // 2 minutes after last card edit
|
|
|
|
viper.SetDefault("NotifyFreqBoardSeconds", 86400) // 1 day after last card edit
|
2022-04-12 23:43:29 +02:00
|
|
|
viper.SetDefault("PrometheusAddress", "")
|
2021-03-26 19:01:54 +01:00
|
|
|
|
2020-10-09 10:27:20 +02:00
|
|
|
err := viper.ReadInConfig() // Find and read the config file
|
|
|
|
if err != nil { // Handle errors reading the config file
|
|
|
|
return nil, err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 10:27:20 +02:00
|
|
|
configuration := Configuration{}
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-09 10:28:39 +02:00
|
|
|
err = viper.Unmarshal(&configuration)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-10-08 18:21:27 +02:00
|
|
|
|
|
|
|
log.Println("readConfigFile")
|
2021-03-26 19:01:54 +01:00
|
|
|
log.Printf("%+v", removeSecurityData(configuration))
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2020-10-09 10:27:20 +02:00
|
|
|
return &configuration, nil
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2021-03-26 19:01:54 +01:00
|
|
|
|
|
|
|
func removeSecurityData(config Configuration) Configuration {
|
|
|
|
clean := config
|
|
|
|
return clean
|
|
|
|
}
|