Letsencrypt (#17)
This commit is contained in:
@ -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",
|
||||
}
|
||||
}
|
||||
|
@ -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: "",
|
||||
}
|
||||
}
|
||||
|
11
internal/config/letsencrypt.go
Normal file
11
internal/config/letsencrypt.go
Normal file
@ -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
|
||||
}
|
Reference in New Issue
Block a user