summaryrefslogtreecommitdiff
path: root/internal/config/default.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-12-07 13:31:39 +0100
committerLibravatar GitHub <noreply@github.com>2021-12-07 13:31:39 +0100
commit0884f89431cd26bcc9674b3b7ab628b090f5881e (patch)
treecdd3b3f77f780a8b59d075dbcc3d4d013811e405 /internal/config/default.go
parentUpdate dependencies (#333) (diff)
downloadgotosocial-0884f89431cd26bcc9674b3b7ab628b090f5881e.tar.xz
Implement Cobra CLI tooling, Viper config tooling (#336)
* start pulling out + replacing urfave and config * replace many many instances of config * move more stuff => viper * properly remove urfave * move some flags to root command * add testrig commands to root * alias config file keys * start adding cli parsing tests * reorder viper init * remove config path alias * fmt * change config file keys to non-nested * we're more or less in business now * tidy up the common func * go fmt * get tests passing again * add note about the cliparsing tests * reorganize * update docs with changes * structure cmd dir better * rename + move some files around * fix dangling comma
Diffstat (limited to 'internal/config/default.go')
-rw-r--r--internal/config/default.go289
1 files changed, 0 insertions, 289 deletions
diff --git a/internal/config/default.go b/internal/config/default.go
deleted file mode 100644
index 6e8f63177..000000000
--- a/internal/config/default.go
+++ /dev/null
@@ -1,289 +0,0 @@
-package config
-
-import "github.com/coreos/go-oidc/v3/oidc"
-
-// TestDefault returns a default config for testing
-func TestDefault() *Config {
- defaults := GetTestDefaults()
- return &Config{
- LogLevel: defaults.LogLevel,
- ApplicationName: defaults.ApplicationName,
- Host: defaults.Host,
- AccountDomain: defaults.AccountDomain,
- Protocol: defaults.Protocol,
- BindAddress: defaults.BindAddress,
- Port: defaults.Port,
- TrustedProxies: defaults.TrustedProxies,
- SoftwareVersion: defaults.SoftwareVersion,
- 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{
- BaseDir: defaults.TemplateBaseDir,
- AssetBaseDir: defaults.AssetBaseDir,
- },
- 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,
- },
- LetsEncryptConfig: &LetsEncryptConfig{
- Enabled: defaults.LetsEncryptEnabled,
- Port: defaults.LetsEncryptPort,
- CertDir: defaults.LetsEncryptCertDir,
- EmailAddress: defaults.LetsEncryptEmailAddress,
- },
- OIDCConfig: &OIDCConfig{
- Enabled: defaults.OIDCEnabled,
- IDPName: defaults.OIDCIdpName,
- SkipVerification: defaults.OIDCSkipVerification,
- Issuer: defaults.OIDCIssuer,
- ClientID: defaults.OIDCClientID,
- ClientSecret: defaults.OIDCClientSecret,
- Scopes: defaults.OIDCScopes,
- },
- SMTPConfig: &SMTPConfig{
- Host: defaults.SMTPHost,
- Port: defaults.SMTPPort,
- Username: defaults.SMTPUsername,
- Password: defaults.SMTPPassword,
- From: defaults.SMTPFrom,
- },
- }
-}
-
-// 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,
- BindAddress: defaults.BindAddress,
- Port: defaults.Port,
- TrustedProxies: defaults.TrustedProxies,
- SoftwareVersion: defaults.SoftwareVersion,
- 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{
- BaseDir: defaults.TemplateBaseDir,
- AssetBaseDir: defaults.AssetBaseDir,
- },
- 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,
- },
- LetsEncryptConfig: &LetsEncryptConfig{
- Enabled: defaults.LetsEncryptEnabled,
- Port: defaults.LetsEncryptPort,
- CertDir: defaults.LetsEncryptCertDir,
- EmailAddress: defaults.LetsEncryptEmailAddress,
- },
- OIDCConfig: &OIDCConfig{
- Enabled: defaults.OIDCEnabled,
- IDPName: defaults.OIDCIdpName,
- SkipVerification: defaults.OIDCSkipVerification,
- Issuer: defaults.OIDCIssuer,
- ClientID: defaults.OIDCClientID,
- ClientSecret: defaults.OIDCClientSecret,
- Scopes: defaults.OIDCScopes,
- },
- SMTPConfig: &SMTPConfig{
- Host: defaults.SMTPHost,
- Port: defaults.SMTPPort,
- Username: defaults.SMTPUsername,
- Password: defaults.SMTPPassword,
- From: defaults.SMTPFrom,
- },
- AccountCLIFlags: make(map[string]string),
- ExportCLIFlags: make(map[string]string),
- }
-}
-
-// 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.
-func GetDefaults() Defaults {
- return Defaults{
- LogLevel: "info",
- ApplicationName: "gotosocial",
- ConfigPath: "",
- Host: "",
- AccountDomain: "",
- Protocol: "https",
- BindAddress: "0.0.0.0",
- Port: 8080,
- TrustedProxies: []string{"127.0.0.1/32"}, // localhost
-
- DbType: "postgres",
- DbAddress: "localhost",
- DbPort: 5432,
- DbUser: "postgres",
- DbPassword: "postgres",
- DbDatabase: "postgres",
- DBTlsMode: "disable",
- DBTlsCACert: "",
-
- TemplateBaseDir: "./web/template/",
- AssetBaseDir: "./web/assets/",
-
- AccountsOpenRegistration: true,
- AccountsRequireApproval: true,
- AccountsReasonRequired: true,
-
- MediaMaxImageSize: 2097152, // 2mb
- MediaMaxVideoSize: 10485760, // 10mb
- 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,
-
- LetsEncryptEnabled: true,
- LetsEncryptPort: 80,
- LetsEncryptCertDir: "/gotosocial/storage/certs",
- LetsEncryptEmailAddress: "",
-
- OIDCEnabled: false,
- OIDCIdpName: "",
- OIDCSkipVerification: false,
- OIDCIssuer: "",
- OIDCClientID: "",
- OIDCClientSecret: "",
- OIDCScopes: []string{oidc.ScopeOpenID, "profile", "email", "groups"},
-
- SMTPHost: "",
- SMTPPort: 0,
- SMTPUsername: "",
- SMTPPassword: "",
- SMTPFrom: "GoToSocial",
- }
-}
-
-// GetTestDefaults returns a Defaults struct with values set that are suitable for local testing.
-func GetTestDefaults() Defaults {
- return Defaults{
- LogLevel: "trace",
- ApplicationName: "gotosocial",
- ConfigPath: "",
- Host: "localhost:8080",
- AccountDomain: "localhost:8080",
- Protocol: "http",
- BindAddress: "127.0.0.1",
- Port: 8080,
- TrustedProxies: []string{"127.0.0.1/32"},
-
- DbType: "sqlite",
- DbAddress: ":memory:",
- DbPort: 5432,
- DbUser: "postgres",
- DbPassword: "postgres",
- DbDatabase: "postgres",
-
- TemplateBaseDir: "./web/template/",
- AssetBaseDir: "./web/assets/",
-
- AccountsOpenRegistration: true,
- AccountsRequireApproval: true,
- AccountsReasonRequired: true,
-
- MediaMaxImageSize: 1048576, // 1mb
- MediaMaxVideoSize: 5242880, // 5mb
- 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,
-
- LetsEncryptEnabled: false,
- LetsEncryptPort: 0,
- LetsEncryptCertDir: "",
- LetsEncryptEmailAddress: "",
-
- OIDCEnabled: false,
- OIDCIdpName: "",
- OIDCSkipVerification: false,
- OIDCIssuer: "",
- OIDCClientID: "",
- OIDCClientSecret: "",
- OIDCScopes: []string{oidc.ScopeOpenID, "profile", "email", "groups"},
-
- SMTPHost: "",
- SMTPPort: 0,
- SMTPUsername: "",
- SMTPPassword: "",
- SMTPFrom: "GoToSocial",
- }
-}