summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-09 11:25:13 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-09 11:25:13 +0200
commit0cbab627c77002711029527f4697fc7ec6cd870d (patch)
tree8d730be593e60489d4e3b3131c1c5feb6ce64452 /internal/config
parentstatus boosts (#16) (diff)
downloadgotosocial-0cbab627c77002711029527f4697fc7ec6cd870d.tar.xz
Letsencrypt (#17)
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go63
-rw-r--r--internal/config/default.go18
-rw-r--r--internal/config/letsencrypt.go11
3 files changed, 76 insertions, 16 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 2421290e7..23f7d0d1c 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -27,16 +27,17 @@ import (
// Config pulls together all the configuration needed to run gotosocial
type Config struct {
- LogLevel string `yaml:"logLevel"`
- ApplicationName string `yaml:"applicationName"`
- Host string `yaml:"host"`
- Protocol string `yaml:"protocol"`
- DBConfig *DBConfig `yaml:"db"`
- TemplateConfig *TemplateConfig `yaml:"template"`
- AccountsConfig *AccountsConfig `yaml:"accounts"`
- MediaConfig *MediaConfig `yaml:"media"`
- StorageConfig *StorageConfig `yaml:"storage"`
- StatusesConfig *StatusesConfig `yaml:"statuses"`
+ LogLevel string `yaml:"logLevel"`
+ ApplicationName string `yaml:"applicationName"`
+ Host string `yaml:"host"`
+ Protocol string `yaml:"protocol"`
+ DBConfig *DBConfig `yaml:"db"`
+ TemplateConfig *TemplateConfig `yaml:"template"`
+ AccountsConfig *AccountsConfig `yaml:"accounts"`
+ MediaConfig *MediaConfig `yaml:"media"`
+ StorageConfig *StorageConfig `yaml:"storage"`
+ StatusesConfig *StatusesConfig `yaml:"statuses"`
+ LetsEncryptConfig *LetsEncryptConfig `yaml:"letsEncrypt"`
}
// FromFile returns a new config from a file, or an error if something goes amiss.
@@ -54,12 +55,13 @@ func FromFile(path string) (*Config, error) {
// Empty just returns a new empty config
func Empty() *Config {
return &Config{
- DBConfig: &DBConfig{},
- TemplateConfig: &TemplateConfig{},
- AccountsConfig: &AccountsConfig{},
- MediaConfig: &MediaConfig{},
- StorageConfig: &StorageConfig{},
- StatusesConfig: &StatusesConfig{},
+ DBConfig: &DBConfig{},
+ TemplateConfig: &TemplateConfig{},
+ AccountsConfig: &AccountsConfig{},
+ MediaConfig: &MediaConfig{},
+ StorageConfig: &StorageConfig{},
+ StatusesConfig: &StatusesConfig{},
+ LetsEncryptConfig: &LetsEncryptConfig{},
}
}
@@ -200,6 +202,19 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) {
if c.StatusesConfig.MaxMediaFiles == 0 || f.IsSet(fn.StatusesMaxMediaFiles) {
c.StatusesConfig.MaxMediaFiles = f.Int(fn.StatusesMaxMediaFiles)
}
+
+ // letsencrypt flags
+ if f.IsSet(fn.LetsEncryptEnabled) {
+ c.LetsEncryptConfig.Enabled = f.Bool(fn.LetsEncryptEnabled)
+ }
+
+ if c.LetsEncryptConfig.CertDir == "" || f.IsSet(fn.LetsEncryptCertDir) {
+ c.LetsEncryptConfig.CertDir = f.String(fn.LetsEncryptCertDir)
+ }
+
+ if c.LetsEncryptConfig.EmailAddress == "" || f.IsSet(fn.LetsEncryptEmailAddress) {
+ c.LetsEncryptConfig.EmailAddress = f.String(fn.LetsEncryptEmailAddress)
+ }
}
// KeyedFlags is a wrapper for any type that can store keyed flags and give them back.
@@ -249,6 +264,10 @@ type Flags struct {
StatusesPollMaxOptions string
StatusesPollOptionMaxChars string
StatusesMaxMediaFiles string
+
+ LetsEncryptEnabled string
+ LetsEncryptCertDir string
+ LetsEncryptEmailAddress string
}
// Defaults contains all the default values for a gotosocial config
@@ -288,6 +307,10 @@ type Defaults struct {
StatusesPollMaxOptions int
StatusesPollOptionMaxChars int
StatusesMaxMediaFiles int
+
+ LetsEncryptEnabled bool
+ LetsEncryptCertDir string
+ LetsEncryptEmailAddress string
}
// GetFlagNames returns a struct containing the names of the various flags used for
@@ -329,6 +352,10 @@ func GetFlagNames() Flags {
StatusesPollMaxOptions: "statuses-poll-max-options",
StatusesPollOptionMaxChars: "statuses-poll-option-max-chars",
StatusesMaxMediaFiles: "statuses-max-media-files",
+
+ LetsEncryptEnabled: "letsencrypt-enabled",
+ LetsEncryptCertDir: "letsencrypt-cert-dir",
+ LetsEncryptEmailAddress: "letsencrypt-email",
}
}
@@ -371,5 +398,9 @@ func GetEnvNames() Flags {
StatusesPollMaxOptions: "GTS_STATUSES_POLL_MAX_OPTIONS",
StatusesPollOptionMaxChars: "GTS_STATUSES_POLL_OPTION_MAX_CHARS",
StatusesMaxMediaFiles: "GTS_STATUSES_MAX_MEDIA_FILES",
+
+ LetsEncryptEnabled: "GTS_LETSENCRYPT_ENABLED",
+ LetsEncryptCertDir: "GTS_LETSENCRYPT_CERT_DIR",
+ LetsEncryptEmailAddress: "GTS_LETSENCRYPT_EMAIL",
}
}
diff --git a/internal/config/default.go b/internal/config/default.go
index b2d82110b..f63579753 100644
--- a/internal/config/default.go
+++ b/internal/config/default.go
@@ -45,6 +45,11 @@ func TestDefault() *Config {
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
},
+ LetsEncryptConfig: &LetsEncryptConfig{
+ Enabled: defaults.LetsEncryptEnabled,
+ CertDir: defaults.LetsEncryptCertDir,
+ EmailAddress: defaults.LetsEncryptEmailAddress,
+ },
}
}
@@ -93,6 +98,11 @@ func Default() *Config {
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
},
+ LetsEncryptConfig: &LetsEncryptConfig{
+ Enabled: defaults.LetsEncryptEnabled,
+ CertDir: defaults.LetsEncryptCertDir,
+ EmailAddress: defaults.LetsEncryptEmailAddress,
+ },
}
}
@@ -135,6 +145,10 @@ func GetDefaults() Defaults {
StatusesPollMaxOptions: 6,
StatusesPollOptionMaxChars: 50,
StatusesMaxMediaFiles: 6,
+
+ LetsEncryptEnabled: true,
+ LetsEncryptCertDir: "/gotosocial/storage/certs",
+ LetsEncryptEmailAddress: "",
}
}
@@ -176,5 +190,9 @@ func GetTestDefaults() Defaults {
StatusesPollMaxOptions: 6,
StatusesPollOptionMaxChars: 50,
StatusesMaxMediaFiles: 6,
+
+ LetsEncryptEnabled: false,
+ LetsEncryptCertDir: "",
+ LetsEncryptEmailAddress: "",
}
}
diff --git a/internal/config/letsencrypt.go b/internal/config/letsencrypt.go
new file mode 100644
index 000000000..ae40cb878
--- /dev/null
+++ b/internal/config/letsencrypt.go
@@ -0,0 +1,11 @@
+package config
+
+// LetsEncryptConfig wraps everything needed to manage letsencrypt certificates from within gotosocial.
+type LetsEncryptConfig struct {
+ // Should letsencrypt certificate fetching be enabled?
+ Enabled bool
+ // Where should certificates be stored?
+ CertDir string
+ // Email address to pass to letsencrypt for notifications about certificate expiry etc.
+ EmailAddress string
+}