2021-04-19 20:42:19 +03:00
|
|
|
package config
|
|
|
|
|
2021-07-23 11:36:28 +03:00
|
|
|
import "github.com/coreos/go-oidc/v3/oidc"
|
|
|
|
|
2021-04-19 20:42:19 +03:00
|
|
|
// TestDefault returns a default config for testing
|
|
|
|
func TestDefault() *Config {
|
|
|
|
defaults := GetTestDefaults()
|
|
|
|
return &Config{
|
|
|
|
LogLevel: defaults.LogLevel,
|
|
|
|
ApplicationName: defaults.ApplicationName,
|
|
|
|
Host: defaults.Host,
|
2021-09-20 17:46:45 +03:00
|
|
|
AccountDomain: defaults.AccountDomain,
|
2021-04-19 20:42:19 +03:00
|
|
|
Protocol: defaults.Protocol,
|
2021-07-24 20:02:41 +03:00
|
|
|
Port: defaults.Port,
|
2021-07-26 17:15:36 +03:00
|
|
|
TrustedProxies: defaults.TrustedProxies,
|
2021-06-24 15:26:08 +03:00
|
|
|
SoftwareVersion: defaults.SoftwareVersion,
|
2021-04-19 20:42:19 +03:00
|
|
|
DBConfig: &DBConfig{
|
|
|
|
Type: defaults.DbType,
|
|
|
|
Address: defaults.DbAddress,
|
|
|
|
Port: defaults.DbPort,
|
|
|
|
User: defaults.DbUser,
|
|
|
|
Password: defaults.DbPassword,
|
|
|
|
Database: defaults.DbDatabase,
|
|
|
|
ApplicationName: defaults.ApplicationName,
|
|
|
|
},
|
|
|
|
TemplateConfig: &TemplateConfig{
|
2021-06-21 20:46:10 +03:00
|
|
|
BaseDir: defaults.TemplateBaseDir,
|
|
|
|
AssetBaseDir: defaults.AssetBaseDir,
|
2021-04-19 20:42:19 +03:00
|
|
|
},
|
|
|
|
AccountsConfig: &AccountsConfig{
|
|
|
|
OpenRegistration: defaults.AccountsOpenRegistration,
|
|
|
|
RequireApproval: defaults.AccountsRequireApproval,
|
|
|
|
ReasonRequired: defaults.AccountsReasonRequired,
|
|
|
|
},
|
|
|
|
MediaConfig: &MediaConfig{
|
|
|
|
MaxImageSize: defaults.MediaMaxImageSize,
|
|
|
|
MaxVideoSize: defaults.MediaMaxVideoSize,
|
|
|
|
MinDescriptionChars: defaults.MediaMinDescriptionChars,
|
|
|
|
MaxDescriptionChars: defaults.MediaMaxDescriptionChars,
|
|
|
|
},
|
|
|
|
StorageConfig: &StorageConfig{
|
|
|
|
Backend: defaults.StorageBackend,
|
|
|
|
BasePath: defaults.StorageBasePath,
|
|
|
|
ServeProtocol: defaults.StorageServeProtocol,
|
|
|
|
ServeHost: defaults.StorageServeHost,
|
|
|
|
ServeBasePath: defaults.StorageServeBasePath,
|
|
|
|
},
|
|
|
|
StatusesConfig: &StatusesConfig{
|
|
|
|
MaxChars: defaults.StatusesMaxChars,
|
|
|
|
CWMaxChars: defaults.StatusesCWMaxChars,
|
|
|
|
PollMaxOptions: defaults.StatusesPollMaxOptions,
|
|
|
|
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
|
|
|
|
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
|
|
|
|
},
|
2021-05-09 12:25:13 +03:00
|
|
|
LetsEncryptConfig: &LetsEncryptConfig{
|
|
|
|
Enabled: defaults.LetsEncryptEnabled,
|
2021-07-24 20:02:41 +03:00
|
|
|
Port: defaults.LetsEncryptPort,
|
2021-05-09 12:25:13 +03:00
|
|
|
CertDir: defaults.LetsEncryptCertDir,
|
|
|
|
EmailAddress: defaults.LetsEncryptEmailAddress,
|
|
|
|
},
|
2021-07-23 11:36:28 +03:00
|
|
|
OIDCConfig: &OIDCConfig{
|
|
|
|
Enabled: defaults.OIDCEnabled,
|
|
|
|
IDPName: defaults.OIDCIdpName,
|
|
|
|
SkipVerification: defaults.OIDCSkipVerification,
|
|
|
|
Issuer: defaults.OIDCIssuer,
|
|
|
|
ClientID: defaults.OIDCClientID,
|
|
|
|
ClientSecret: defaults.OIDCClientSecret,
|
|
|
|
Scopes: defaults.OIDCScopes,
|
|
|
|
},
|
2021-10-31 17:46:23 +03:00
|
|
|
SMTPConfig: &SMTPConfig{
|
|
|
|
Host: defaults.SMTPHost,
|
|
|
|
Port: defaults.SMTPPort,
|
|
|
|
Username: defaults.SMTPUsername,
|
|
|
|
Password: defaults.SMTPPassword,
|
|
|
|
From: defaults.SMTPFrom,
|
|
|
|
},
|
2021-04-19 20:42:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default returns a config with all default values set
|
|
|
|
func Default() *Config {
|
|
|
|
defaults := GetDefaults()
|
|
|
|
return &Config{
|
|
|
|
LogLevel: defaults.LogLevel,
|
|
|
|
ApplicationName: defaults.ApplicationName,
|
|
|
|
Host: defaults.Host,
|
|
|
|
Protocol: defaults.Protocol,
|
2021-07-24 20:31:38 +03:00
|
|
|
Port: defaults.Port,
|
2021-07-26 17:15:36 +03:00
|
|
|
TrustedProxies: defaults.TrustedProxies,
|
2021-06-24 15:26:08 +03:00
|
|
|
SoftwareVersion: defaults.SoftwareVersion,
|
2021-04-19 20:42:19 +03:00
|
|
|
DBConfig: &DBConfig{
|
|
|
|
Type: defaults.DbType,
|
|
|
|
Address: defaults.DbAddress,
|
|
|
|
Port: defaults.DbPort,
|
|
|
|
User: defaults.DbUser,
|
|
|
|
Password: defaults.DbPassword,
|
|
|
|
Database: defaults.DbDatabase,
|
|
|
|
ApplicationName: defaults.ApplicationName,
|
|
|
|
},
|
|
|
|
TemplateConfig: &TemplateConfig{
|
2021-06-21 20:46:10 +03:00
|
|
|
BaseDir: defaults.TemplateBaseDir,
|
|
|
|
AssetBaseDir: defaults.AssetBaseDir,
|
2021-04-19 20:42:19 +03:00
|
|
|
},
|
|
|
|
AccountsConfig: &AccountsConfig{
|
|
|
|
OpenRegistration: defaults.AccountsOpenRegistration,
|
|
|
|
RequireApproval: defaults.AccountsRequireApproval,
|
|
|
|
ReasonRequired: defaults.AccountsReasonRequired,
|
|
|
|
},
|
|
|
|
MediaConfig: &MediaConfig{
|
|
|
|
MaxImageSize: defaults.MediaMaxImageSize,
|
|
|
|
MaxVideoSize: defaults.MediaMaxVideoSize,
|
|
|
|
MinDescriptionChars: defaults.MediaMinDescriptionChars,
|
|
|
|
MaxDescriptionChars: defaults.MediaMaxDescriptionChars,
|
|
|
|
},
|
|
|
|
StorageConfig: &StorageConfig{
|
|
|
|
Backend: defaults.StorageBackend,
|
|
|
|
BasePath: defaults.StorageBasePath,
|
|
|
|
ServeProtocol: defaults.StorageServeProtocol,
|
|
|
|
ServeHost: defaults.StorageServeHost,
|
|
|
|
ServeBasePath: defaults.StorageServeBasePath,
|
|
|
|
},
|
|
|
|
StatusesConfig: &StatusesConfig{
|
|
|
|
MaxChars: defaults.StatusesMaxChars,
|
|
|
|
CWMaxChars: defaults.StatusesCWMaxChars,
|
|
|
|
PollMaxOptions: defaults.StatusesPollMaxOptions,
|
|
|
|
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
|
|
|
|
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
|
|
|
|
},
|
2021-05-09 12:25:13 +03:00
|
|
|
LetsEncryptConfig: &LetsEncryptConfig{
|
|
|
|
Enabled: defaults.LetsEncryptEnabled,
|
2021-07-24 20:02:41 +03:00
|
|
|
Port: defaults.LetsEncryptPort,
|
2021-05-09 12:25:13 +03:00
|
|
|
CertDir: defaults.LetsEncryptCertDir,
|
|
|
|
EmailAddress: defaults.LetsEncryptEmailAddress,
|
|
|
|
},
|
2021-07-23 11:36:28 +03:00
|
|
|
OIDCConfig: &OIDCConfig{
|
|
|
|
Enabled: defaults.OIDCEnabled,
|
|
|
|
IDPName: defaults.OIDCIdpName,
|
|
|
|
SkipVerification: defaults.OIDCSkipVerification,
|
|
|
|
Issuer: defaults.OIDCIssuer,
|
|
|
|
ClientID: defaults.OIDCClientID,
|
|
|
|
ClientSecret: defaults.OIDCClientSecret,
|
|
|
|
Scopes: defaults.OIDCScopes,
|
|
|
|
},
|
2021-10-31 17:46:23 +03:00
|
|
|
SMTPConfig: &SMTPConfig{
|
|
|
|
Host: defaults.SMTPHost,
|
|
|
|
Port: defaults.SMTPPort,
|
|
|
|
Username: defaults.SMTPUsername,
|
|
|
|
Password: defaults.SMTPPassword,
|
|
|
|
From: defaults.SMTPFrom,
|
|
|
|
},
|
2021-04-19 20:42:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 19:14:23 +03:00
|
|
|
// GetDefaults returns a populated Defaults struct with most of the values set to reasonable defaults.
|
|
|
|
// Note that if you use this function, you still need to set Host and, if desired, ConfigPath.
|
2021-04-19 20:42:19 +03:00
|
|
|
func GetDefaults() Defaults {
|
|
|
|
return Defaults{
|
|
|
|
LogLevel: "info",
|
|
|
|
ApplicationName: "gotosocial",
|
|
|
|
ConfigPath: "",
|
|
|
|
Host: "",
|
2021-07-19 19:42:08 +03:00
|
|
|
AccountDomain: "",
|
2021-04-19 20:42:19 +03:00
|
|
|
Protocol: "https",
|
2021-07-24 20:02:41 +03:00
|
|
|
Port: 8080,
|
2021-07-26 17:15:36 +03:00
|
|
|
TrustedProxies: []string{"127.0.0.1/32"}, // localhost
|
2021-04-19 20:42:19 +03:00
|
|
|
|
2021-07-19 19:03:07 +03:00
|
|
|
DbType: "postgres",
|
|
|
|
DbAddress: "localhost",
|
|
|
|
DbPort: 5432,
|
|
|
|
DbUser: "postgres",
|
|
|
|
DbPassword: "postgres",
|
|
|
|
DbDatabase: "postgres",
|
|
|
|
DBTlsMode: "disable",
|
|
|
|
DBTlsCACert: "",
|
2021-04-19 20:42:19 +03:00
|
|
|
|
|
|
|
TemplateBaseDir: "./web/template/",
|
2021-06-21 20:46:10 +03:00
|
|
|
AssetBaseDir: "./web/assets/",
|
2021-04-19 20:42:19 +03:00
|
|
|
|
|
|
|
AccountsOpenRegistration: true,
|
|
|
|
AccountsRequireApproval: true,
|
|
|
|
AccountsReasonRequired: true,
|
|
|
|
|
2021-11-22 10:46:19 +03:00
|
|
|
MediaMaxImageSize: 2097152, // 2mb
|
|
|
|
MediaMaxVideoSize: 10485760, // 10mb
|
2021-04-19 20:42:19 +03:00
|
|
|
MediaMinDescriptionChars: 0,
|
|
|
|
MediaMaxDescriptionChars: 500,
|
|
|
|
|
|
|
|
StorageBackend: "local",
|
|
|
|
StorageBasePath: "/gotosocial/storage",
|
|
|
|
StorageServeProtocol: "https",
|
|
|
|
StorageServeHost: "localhost",
|
|
|
|
StorageServeBasePath: "/fileserver",
|
|
|
|
|
|
|
|
StatusesMaxChars: 5000,
|
|
|
|
StatusesCWMaxChars: 100,
|
|
|
|
StatusesPollMaxOptions: 6,
|
|
|
|
StatusesPollOptionMaxChars: 50,
|
|
|
|
StatusesMaxMediaFiles: 6,
|
2021-05-09 12:25:13 +03:00
|
|
|
|
|
|
|
LetsEncryptEnabled: true,
|
2021-07-24 20:02:41 +03:00
|
|
|
LetsEncryptPort: 80,
|
2021-05-09 12:25:13 +03:00
|
|
|
LetsEncryptCertDir: "/gotosocial/storage/certs",
|
|
|
|
LetsEncryptEmailAddress: "",
|
2021-07-23 11:36:28 +03:00
|
|
|
|
|
|
|
OIDCEnabled: false,
|
|
|
|
OIDCIdpName: "",
|
|
|
|
OIDCSkipVerification: false,
|
|
|
|
OIDCIssuer: "",
|
|
|
|
OIDCClientID: "",
|
|
|
|
OIDCClientSecret: "",
|
|
|
|
OIDCScopes: []string{oidc.ScopeOpenID, "profile", "email", "groups"},
|
2021-10-31 17:46:23 +03:00
|
|
|
|
|
|
|
SMTPHost: "",
|
|
|
|
SMTPPort: 0,
|
|
|
|
SMTPUsername: "",
|
|
|
|
SMTPPassword: "",
|
|
|
|
SMTPFrom: "GoToSocial",
|
2021-04-19 20:42:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 19:14:23 +03:00
|
|
|
// GetTestDefaults returns a Defaults struct with values set that are suitable for local testing.
|
2021-04-19 20:42:19 +03:00
|
|
|
func GetTestDefaults() Defaults {
|
|
|
|
return Defaults{
|
|
|
|
LogLevel: "trace",
|
|
|
|
ApplicationName: "gotosocial",
|
|
|
|
ConfigPath: "",
|
|
|
|
Host: "localhost:8080",
|
2021-09-20 17:46:45 +03:00
|
|
|
AccountDomain: "localhost:8080",
|
2021-04-19 20:42:19 +03:00
|
|
|
Protocol: "http",
|
2021-07-24 20:02:41 +03:00
|
|
|
Port: 8080,
|
2021-07-26 17:15:36 +03:00
|
|
|
TrustedProxies: []string{"127.0.0.1/32"},
|
2021-04-19 20:42:19 +03:00
|
|
|
|
2021-09-08 23:12:23 +03:00
|
|
|
DbType: "sqlite",
|
|
|
|
DbAddress: ":memory:",
|
2021-04-19 20:42:19 +03:00
|
|
|
DbPort: 5432,
|
|
|
|
DbUser: "postgres",
|
|
|
|
DbPassword: "postgres",
|
|
|
|
DbDatabase: "postgres",
|
|
|
|
|
|
|
|
TemplateBaseDir: "./web/template/",
|
2021-06-21 21:40:56 +03:00
|
|
|
AssetBaseDir: "./web/assets/",
|
2021-04-19 20:42:19 +03:00
|
|
|
|
|
|
|
AccountsOpenRegistration: true,
|
|
|
|
AccountsRequireApproval: true,
|
|
|
|
AccountsReasonRequired: true,
|
|
|
|
|
2021-11-22 10:46:19 +03:00
|
|
|
MediaMaxImageSize: 1048576, // 1mb
|
|
|
|
MediaMaxVideoSize: 5242880, // 5mb
|
2021-04-19 20:42:19 +03:00
|
|
|
MediaMinDescriptionChars: 0,
|
|
|
|
MediaMaxDescriptionChars: 500,
|
|
|
|
|
|
|
|
StorageBackend: "local",
|
|
|
|
StorageBasePath: "/gotosocial/storage",
|
|
|
|
StorageServeProtocol: "http",
|
|
|
|
StorageServeHost: "localhost:8080",
|
|
|
|
StorageServeBasePath: "/fileserver",
|
|
|
|
|
|
|
|
StatusesMaxChars: 5000,
|
|
|
|
StatusesCWMaxChars: 100,
|
|
|
|
StatusesPollMaxOptions: 6,
|
|
|
|
StatusesPollOptionMaxChars: 50,
|
|
|
|
StatusesMaxMediaFiles: 6,
|
2021-05-09 12:25:13 +03:00
|
|
|
|
|
|
|
LetsEncryptEnabled: false,
|
2021-07-24 20:02:41 +03:00
|
|
|
LetsEncryptPort: 0,
|
2021-05-09 12:25:13 +03:00
|
|
|
LetsEncryptCertDir: "",
|
|
|
|
LetsEncryptEmailAddress: "",
|
2021-07-23 11:36:28 +03:00
|
|
|
|
|
|
|
OIDCEnabled: false,
|
|
|
|
OIDCIdpName: "",
|
|
|
|
OIDCSkipVerification: false,
|
|
|
|
OIDCIssuer: "",
|
|
|
|
OIDCClientID: "",
|
|
|
|
OIDCClientSecret: "",
|
|
|
|
OIDCScopes: []string{oidc.ScopeOpenID, "profile", "email", "groups"},
|
2021-10-31 17:46:23 +03:00
|
|
|
|
|
|
|
SMTPHost: "",
|
|
|
|
SMTPPort: 0,
|
|
|
|
SMTPUsername: "",
|
|
|
|
SMTPPassword: "",
|
|
|
|
SMTPFrom: "GoToSocial",
|
2021-04-19 20:42:19 +03:00
|
|
|
}
|
|
|
|
}
|