2021-03-03 17:12:02 +00:00
|
|
|
/*
|
|
|
|
GoToSocial
|
|
|
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2021-05-22 12:26:45 +00:00
|
|
|
"errors"
|
2021-03-03 17:12:02 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2021-03-03 20:15:20 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2021-03-03 17:12:02 +00:00
|
|
|
)
|
|
|
|
|
2021-05-30 11:12:00 +00:00
|
|
|
// Flags and usage strings for configuration.
|
2021-05-22 12:26:45 +00:00
|
|
|
const (
|
|
|
|
UsernameFlag = "username"
|
|
|
|
UsernameUsage = "the username to create/delete/etc"
|
|
|
|
|
|
|
|
EmailFlag = "email"
|
|
|
|
EmailUsage = "the email address of this account"
|
|
|
|
|
|
|
|
PasswordFlag = "password"
|
|
|
|
PasswordUsage = "the password to set for this account"
|
2021-09-09 14:15:25 +00:00
|
|
|
|
|
|
|
TransPathFlag = "path"
|
|
|
|
TransPathUsage = "the path of the file to import from/export to"
|
2021-05-22 12:26:45 +00:00
|
|
|
)
|
|
|
|
|
2021-03-04 13:38:18 +00:00
|
|
|
// Config pulls together all the configuration needed to run gotosocial
|
2021-03-03 17:12:02 +00:00
|
|
|
type Config struct {
|
2021-05-22 12:26:45 +00:00
|
|
|
/*
|
|
|
|
Parseable from .yaml configuration file.
|
|
|
|
For long-running commands (server start etc).
|
|
|
|
*/
|
|
|
|
|
2021-05-09 09:25:13 +00:00
|
|
|
LogLevel string `yaml:"logLevel"`
|
|
|
|
ApplicationName string `yaml:"applicationName"`
|
|
|
|
Host string `yaml:"host"`
|
2021-07-19 16:42:08 +00:00
|
|
|
AccountDomain string `yaml:"accountDomain"`
|
2021-05-09 09:25:13 +00:00
|
|
|
Protocol string `yaml:"protocol"`
|
2021-11-22 09:55:52 +00:00
|
|
|
BindAddress string `yaml:"bindAddress"`
|
2021-07-24 16:55:24 +00:00
|
|
|
Port int `yaml:"port"`
|
2021-07-26 14:15:36 +00:00
|
|
|
TrustedProxies []string `yaml:"trustedProxies"`
|
2021-05-09 09:25:13 +00:00
|
|
|
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"`
|
2021-07-23 08:36:28 +00:00
|
|
|
OIDCConfig *OIDCConfig `yaml:"oidc"`
|
2021-10-31 14:46:23 +00:00
|
|
|
SMTPConfig *SMTPConfig `yaml:"smtp"`
|
2021-05-22 12:26:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Not parsed from .yaml configuration file.
|
|
|
|
*/
|
|
|
|
AccountCLIFlags map[string]string
|
2021-09-09 14:15:25 +00:00
|
|
|
ExportCLIFlags map[string]string
|
2021-06-24 12:26:08 +00:00
|
|
|
SoftwareVersion string
|
2021-03-03 17:12:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 22:27:43 +00:00
|
|
|
// FromFile returns a new config from a file, or an error if something goes amiss.
|
|
|
|
func FromFile(path string) (*Config, error) {
|
2021-04-01 18:46:45 +00:00
|
|
|
if path != "" {
|
|
|
|
c, err := loadFromFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error creating config: %s", err)
|
|
|
|
}
|
|
|
|
return c, nil
|
2021-03-03 17:12:02 +00:00
|
|
|
}
|
2021-11-24 16:01:38 +00:00
|
|
|
return Default(), nil
|
2021-03-03 17:12:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 20:15:20 +00:00
|
|
|
// loadFromFile takes a path to a yaml file and attempts to load a Config object from it
|
2021-03-03 17:12:02 +00:00
|
|
|
func loadFromFile(path string) (*Config, error) {
|
|
|
|
bytes, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not read file at path %s: %s", path, err)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
config := Default()
|
2021-03-03 20:15:20 +00:00
|
|
|
if err := yaml.Unmarshal(bytes, config); err != nil {
|
2021-03-03 17:12:02 +00:00
|
|
|
return nil, fmt.Errorf("could not unmarshal file at path %s: %s", path, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
2021-03-18 22:27:43 +00:00
|
|
|
// ParseCLIFlags sets flags on the config using the provided Flags object
|
2021-06-28 10:17:20 +00:00
|
|
|
func (c *Config) ParseCLIFlags(f KeyedFlags, version string) error {
|
2021-03-04 13:38:18 +00:00
|
|
|
fn := GetFlagNames()
|
|
|
|
|
|
|
|
// For all of these flags, we only want to set them on the config if:
|
|
|
|
//
|
|
|
|
// a) They haven't been set at all in the config file we already parsed,
|
|
|
|
// and so we take the default from the flags object.
|
|
|
|
//
|
|
|
|
// b) They may have been set in the config, but they've *also* been set explicitly
|
|
|
|
// as a command-line argument or an env variable, which takes priority.
|
|
|
|
|
|
|
|
// general flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.LogLevel) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.LogLevel = f.String(fn.LogLevel)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.ApplicationName) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.ApplicationName = f.String(fn.ApplicationName)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.Host) {
|
2021-03-22 21:26:54 +00:00
|
|
|
c.Host = f.String(fn.Host)
|
|
|
|
}
|
2021-05-22 12:26:45 +00:00
|
|
|
if c.Host == "" {
|
|
|
|
return errors.New("host was not set")
|
|
|
|
}
|
2021-03-22 21:26:54 +00:00
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.AccountDomain) {
|
2021-07-19 16:42:08 +00:00
|
|
|
c.AccountDomain = f.String(fn.AccountDomain)
|
|
|
|
}
|
|
|
|
if c.AccountDomain == "" {
|
|
|
|
c.AccountDomain = c.Host // default to whatever the host is, if this is empty
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.Protocol) {
|
2021-03-22 21:26:54 +00:00
|
|
|
c.Protocol = f.String(fn.Protocol)
|
|
|
|
}
|
2021-05-22 12:26:45 +00:00
|
|
|
if c.Protocol == "" {
|
|
|
|
return errors.New("protocol was not set")
|
|
|
|
}
|
2021-03-22 21:26:54 +00:00
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.BindAddress) {
|
2021-11-22 09:55:52 +00:00
|
|
|
c.BindAddress = f.String(fn.BindAddress)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.Port) {
|
2021-07-24 16:55:24 +00:00
|
|
|
c.Port = f.Int(fn.Port)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.TrustedProxies) {
|
2021-07-26 14:15:36 +00:00
|
|
|
c.TrustedProxies = f.StringSlice(fn.TrustedProxies)
|
|
|
|
}
|
|
|
|
|
2021-03-04 13:38:18 +00:00
|
|
|
// db flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbType) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.DBConfig.Type = f.String(fn.DbType)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbAddress) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.DBConfig.Address = f.String(fn.DbAddress)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbPort) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.DBConfig.Port = f.Int(fn.DbPort)
|
|
|
|
}
|
2021-03-03 20:15:20 +00:00
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbUser) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.DBConfig.User = f.String(fn.DbUser)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbPassword) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.DBConfig.Password = f.String(fn.DbPassword)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbDatabase) {
|
2021-03-04 13:38:18 +00:00
|
|
|
c.DBConfig.Database = f.String(fn.DbDatabase)
|
|
|
|
}
|
2021-03-18 22:27:43 +00:00
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbTLSMode) {
|
2021-07-19 16:03:07 +00:00
|
|
|
c.DBConfig.TLSMode = DBTLSMode(f.String(fn.DbTLSMode))
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.DbTLSCACert) {
|
2021-07-19 16:03:07 +00:00
|
|
|
c.DBConfig.TLSCACert = f.String(fn.DbTLSCACert)
|
|
|
|
}
|
|
|
|
|
2021-03-18 22:27:43 +00:00
|
|
|
// template flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.TemplateBaseDir) {
|
2021-03-18 22:27:43 +00:00
|
|
|
c.TemplateConfig.BaseDir = f.String(fn.TemplateBaseDir)
|
|
|
|
}
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-06-21 17:46:10 +00:00
|
|
|
// template flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.AssetBaseDir) {
|
2021-06-21 17:46:10 +00:00
|
|
|
c.TemplateConfig.AssetBaseDir = f.String(fn.AssetBaseDir)
|
|
|
|
}
|
|
|
|
|
2021-04-01 18:46:45 +00:00
|
|
|
// accounts flags
|
|
|
|
if f.IsSet(fn.AccountsOpenRegistration) {
|
|
|
|
c.AccountsConfig.OpenRegistration = f.Bool(fn.AccountsOpenRegistration)
|
|
|
|
}
|
|
|
|
|
2021-04-19 17:42:19 +00:00
|
|
|
if f.IsSet(fn.AccountsApprovalRequired) {
|
|
|
|
c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsApprovalRequired)
|
2021-04-01 18:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// media flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.MediaMaxImageSize) {
|
2021-04-01 18:46:45 +00:00
|
|
|
c.MediaConfig.MaxImageSize = f.Int(fn.MediaMaxImageSize)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.MediaMaxVideoSize) {
|
2021-04-01 18:46:45 +00:00
|
|
|
c.MediaConfig.MaxVideoSize = f.Int(fn.MediaMaxVideoSize)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.MediaMinDescriptionChars) {
|
2021-04-19 17:42:19 +00:00
|
|
|
c.MediaConfig.MinDescriptionChars = f.Int(fn.MediaMinDescriptionChars)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.MediaMaxDescriptionChars) {
|
2021-04-19 17:42:19 +00:00
|
|
|
c.MediaConfig.MaxDescriptionChars = f.Int(fn.MediaMaxDescriptionChars)
|
|
|
|
}
|
|
|
|
|
2021-04-01 18:46:45 +00:00
|
|
|
// storage flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StorageBackend) {
|
2021-04-01 18:46:45 +00:00
|
|
|
c.StorageConfig.Backend = f.String(fn.StorageBackend)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StorageBasePath) {
|
2021-04-01 18:46:45 +00:00
|
|
|
c.StorageConfig.BasePath = f.String(fn.StorageBasePath)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StorageServeProtocol) {
|
2021-04-01 18:46:45 +00:00
|
|
|
c.StorageConfig.ServeProtocol = f.String(fn.StorageServeProtocol)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StorageServeHost) {
|
2021-04-01 18:46:45 +00:00
|
|
|
c.StorageConfig.ServeHost = f.String(fn.StorageServeHost)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StorageServeBasePath) {
|
2021-04-01 18:46:45 +00:00
|
|
|
c.StorageConfig.ServeBasePath = f.String(fn.StorageServeBasePath)
|
|
|
|
}
|
2021-04-19 17:42:19 +00:00
|
|
|
|
|
|
|
// statuses flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StatusesMaxChars) {
|
2021-04-19 17:42:19 +00:00
|
|
|
c.StatusesConfig.MaxChars = f.Int(fn.StatusesMaxChars)
|
|
|
|
}
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StatusesCWMaxChars) {
|
2021-04-19 17:42:19 +00:00
|
|
|
c.StatusesConfig.CWMaxChars = f.Int(fn.StatusesCWMaxChars)
|
|
|
|
}
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StatusesPollMaxOptions) {
|
2021-04-19 17:42:19 +00:00
|
|
|
c.StatusesConfig.PollMaxOptions = f.Int(fn.StatusesPollMaxOptions)
|
|
|
|
}
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StatusesPollOptionMaxChars) {
|
2021-04-19 17:42:19 +00:00
|
|
|
c.StatusesConfig.PollOptionMaxChars = f.Int(fn.StatusesPollOptionMaxChars)
|
|
|
|
}
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.StatusesMaxMediaFiles) {
|
2021-04-19 17:42:19 +00:00
|
|
|
c.StatusesConfig.MaxMediaFiles = f.Int(fn.StatusesMaxMediaFiles)
|
|
|
|
}
|
2021-05-09 09:25:13 +00:00
|
|
|
|
|
|
|
// letsencrypt flags
|
|
|
|
if f.IsSet(fn.LetsEncryptEnabled) {
|
|
|
|
c.LetsEncryptConfig.Enabled = f.Bool(fn.LetsEncryptEnabled)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.LetsEncryptPort) {
|
2021-07-24 16:55:24 +00:00
|
|
|
c.LetsEncryptConfig.Port = f.Int(fn.LetsEncryptPort)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.LetsEncryptCertDir) {
|
2021-05-09 09:25:13 +00:00
|
|
|
c.LetsEncryptConfig.CertDir = f.String(fn.LetsEncryptCertDir)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.LetsEncryptEmailAddress) {
|
2021-05-09 09:25:13 +00:00
|
|
|
c.LetsEncryptConfig.EmailAddress = f.String(fn.LetsEncryptEmailAddress)
|
|
|
|
}
|
2021-05-22 12:26:45 +00:00
|
|
|
|
2021-07-23 08:36:28 +00:00
|
|
|
// OIDC flags
|
|
|
|
if f.IsSet(fn.OIDCEnabled) {
|
|
|
|
c.OIDCConfig.Enabled = f.Bool(fn.OIDCEnabled)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.OIDCIdpName) {
|
2021-07-23 08:36:28 +00:00
|
|
|
c.OIDCConfig.IDPName = f.String(fn.OIDCIdpName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.IsSet(fn.OIDCSkipVerification) {
|
|
|
|
c.OIDCConfig.SkipVerification = f.Bool(fn.OIDCSkipVerification)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.OIDCIssuer) {
|
2021-07-23 08:36:28 +00:00
|
|
|
c.OIDCConfig.Issuer = f.String(fn.OIDCIssuer)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.OIDCClientID) {
|
2021-07-23 08:36:28 +00:00
|
|
|
c.OIDCConfig.ClientID = f.String(fn.OIDCClientID)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.OIDCClientSecret) {
|
2021-07-23 08:36:28 +00:00
|
|
|
c.OIDCConfig.ClientSecret = f.String(fn.OIDCClientSecret)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.OIDCScopes) {
|
2021-07-23 08:36:28 +00:00
|
|
|
c.OIDCConfig.Scopes = f.StringSlice(fn.OIDCScopes)
|
|
|
|
}
|
2021-06-24 12:26:08 +00:00
|
|
|
|
2021-10-31 14:46:23 +00:00
|
|
|
// smtp flags
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.SMTPHost) {
|
2021-10-31 14:46:23 +00:00
|
|
|
c.SMTPConfig.Host = f.String(fn.SMTPHost)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.SMTPPort) {
|
2021-10-31 14:46:23 +00:00
|
|
|
c.SMTPConfig.Port = f.Int(fn.SMTPPort)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.SMTPUsername) {
|
2021-10-31 14:46:23 +00:00
|
|
|
c.SMTPConfig.Username = f.String(fn.SMTPUsername)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.SMTPPassword) {
|
2021-10-31 14:46:23 +00:00
|
|
|
c.SMTPConfig.Password = f.String(fn.SMTPPassword)
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:01:38 +00:00
|
|
|
if f.IsSet(fn.SMTPFrom) {
|
2021-10-31 14:46:23 +00:00
|
|
|
c.SMTPConfig.From = f.String(fn.SMTPFrom)
|
|
|
|
}
|
|
|
|
|
2021-05-22 12:26:45 +00:00
|
|
|
// command-specific flags
|
|
|
|
|
|
|
|
// admin account CLI flags
|
|
|
|
c.AccountCLIFlags[UsernameFlag] = f.String(UsernameFlag)
|
|
|
|
c.AccountCLIFlags[EmailFlag] = f.String(EmailFlag)
|
|
|
|
c.AccountCLIFlags[PasswordFlag] = f.String(PasswordFlag)
|
|
|
|
|
2021-09-09 14:15:25 +00:00
|
|
|
// export CLI flags
|
|
|
|
c.ExportCLIFlags[TransPathFlag] = f.String(TransPathFlag)
|
|
|
|
|
2021-06-28 10:17:20 +00:00
|
|
|
c.SoftwareVersion = version
|
2021-05-22 12:26:45 +00:00
|
|
|
return nil
|
2021-03-03 17:12:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 13:38:18 +00:00
|
|
|
// KeyedFlags is a wrapper for any type that can store keyed flags and give them back.
|
|
|
|
// HINT: This works with a urfave cli context struct ;)
|
|
|
|
type KeyedFlags interface {
|
2021-04-01 18:46:45 +00:00
|
|
|
Bool(k string) bool
|
2021-03-03 17:12:02 +00:00
|
|
|
String(k string) string
|
2021-07-23 08:36:28 +00:00
|
|
|
StringSlice(k string) []string
|
2021-03-03 17:12:02 +00:00
|
|
|
Int(k string) int
|
2021-03-04 13:38:18 +00:00
|
|
|
IsSet(k string) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flags is used for storing the names of the various flags used for
|
|
|
|
// initializing and storing urfavecli flag variables.
|
|
|
|
type Flags struct {
|
|
|
|
LogLevel string
|
|
|
|
ApplicationName string
|
|
|
|
ConfigPath string
|
2021-03-22 21:26:54 +00:00
|
|
|
Host string
|
2021-07-19 16:42:08 +00:00
|
|
|
AccountDomain string
|
2021-03-22 21:26:54 +00:00
|
|
|
Protocol string
|
2021-11-22 09:55:52 +00:00
|
|
|
BindAddress string
|
2021-07-24 16:55:24 +00:00
|
|
|
Port string
|
2021-07-26 14:15:36 +00:00
|
|
|
TrustedProxies string
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-07-19 16:03:07 +00:00
|
|
|
DbType string
|
|
|
|
DbAddress string
|
|
|
|
DbPort string
|
|
|
|
DbUser string
|
|
|
|
DbPassword string
|
|
|
|
DbDatabase string
|
|
|
|
DbTLSMode string
|
|
|
|
DbTLSCACert string
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-03-18 22:27:43 +00:00
|
|
|
TemplateBaseDir string
|
2021-06-21 17:46:10 +00:00
|
|
|
AssetBaseDir string
|
2021-04-01 18:46:45 +00:00
|
|
|
|
|
|
|
AccountsOpenRegistration string
|
2021-04-19 17:42:19 +00:00
|
|
|
AccountsApprovalRequired string
|
|
|
|
AccountsReasonRequired string
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-04-19 17:42:19 +00:00
|
|
|
MediaMaxImageSize string
|
|
|
|
MediaMaxVideoSize string
|
|
|
|
MediaMinDescriptionChars string
|
|
|
|
MediaMaxDescriptionChars string
|
2021-04-01 18:46:45 +00:00
|
|
|
|
|
|
|
StorageBackend string
|
|
|
|
StorageBasePath string
|
|
|
|
StorageServeProtocol string
|
|
|
|
StorageServeHost string
|
|
|
|
StorageServeBasePath string
|
2021-04-19 17:42:19 +00:00
|
|
|
|
|
|
|
StatusesMaxChars string
|
|
|
|
StatusesCWMaxChars string
|
|
|
|
StatusesPollMaxOptions string
|
|
|
|
StatusesPollOptionMaxChars string
|
|
|
|
StatusesMaxMediaFiles string
|
2021-05-09 09:25:13 +00:00
|
|
|
|
|
|
|
LetsEncryptEnabled string
|
|
|
|
LetsEncryptCertDir string
|
|
|
|
LetsEncryptEmailAddress string
|
2021-07-24 16:55:24 +00:00
|
|
|
LetsEncryptPort string
|
2021-07-23 08:36:28 +00:00
|
|
|
|
|
|
|
OIDCEnabled string
|
|
|
|
OIDCIdpName string
|
|
|
|
OIDCSkipVerification string
|
|
|
|
OIDCIssuer string
|
|
|
|
OIDCClientID string
|
|
|
|
OIDCClientSecret string
|
|
|
|
OIDCScopes string
|
2021-10-31 14:46:23 +00:00
|
|
|
|
|
|
|
SMTPHost string
|
|
|
|
SMTPPort string
|
|
|
|
SMTPUsername string
|
|
|
|
SMTPPassword string
|
|
|
|
SMTPFrom string
|
2021-04-19 17:42:19 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 16:14:23 +00:00
|
|
|
// Defaults contains all the default values for a gotosocial config
|
2021-04-19 17:42:19 +00:00
|
|
|
type Defaults struct {
|
|
|
|
LogLevel string
|
|
|
|
ApplicationName string
|
|
|
|
ConfigPath string
|
|
|
|
Host string
|
2021-07-19 16:42:08 +00:00
|
|
|
AccountDomain string
|
2021-04-19 17:42:19 +00:00
|
|
|
Protocol string
|
2021-11-22 09:55:52 +00:00
|
|
|
BindAddress string
|
2021-07-24 16:55:24 +00:00
|
|
|
Port int
|
2021-07-26 14:15:36 +00:00
|
|
|
TrustedProxies []string
|
2021-06-24 12:26:08 +00:00
|
|
|
SoftwareVersion string
|
2021-04-19 17:42:19 +00:00
|
|
|
|
2021-07-19 16:03:07 +00:00
|
|
|
DbType string
|
|
|
|
DbAddress string
|
|
|
|
DbPort int
|
|
|
|
DbUser string
|
|
|
|
DbPassword string
|
|
|
|
DbDatabase string
|
|
|
|
DBTlsMode string
|
|
|
|
DBTlsCACert string
|
2021-04-19 17:42:19 +00:00
|
|
|
|
|
|
|
TemplateBaseDir string
|
2021-06-21 17:46:10 +00:00
|
|
|
AssetBaseDir string
|
2021-04-19 17:42:19 +00:00
|
|
|
|
|
|
|
AccountsOpenRegistration bool
|
|
|
|
AccountsRequireApproval bool
|
|
|
|
AccountsReasonRequired bool
|
|
|
|
|
|
|
|
MediaMaxImageSize int
|
|
|
|
MediaMaxVideoSize int
|
|
|
|
MediaMinDescriptionChars int
|
|
|
|
MediaMaxDescriptionChars int
|
|
|
|
|
|
|
|
StorageBackend string
|
|
|
|
StorageBasePath string
|
|
|
|
StorageServeProtocol string
|
|
|
|
StorageServeHost string
|
|
|
|
StorageServeBasePath string
|
|
|
|
|
|
|
|
StatusesMaxChars int
|
|
|
|
StatusesCWMaxChars int
|
|
|
|
StatusesPollMaxOptions int
|
|
|
|
StatusesPollOptionMaxChars int
|
|
|
|
StatusesMaxMediaFiles int
|
2021-05-09 09:25:13 +00:00
|
|
|
|
|
|
|
LetsEncryptEnabled bool
|
|
|
|
LetsEncryptCertDir string
|
|
|
|
LetsEncryptEmailAddress string
|
2021-07-24 16:55:24 +00:00
|
|
|
LetsEncryptPort int
|
2021-07-23 08:36:28 +00:00
|
|
|
|
|
|
|
OIDCEnabled bool
|
|
|
|
OIDCIdpName string
|
|
|
|
OIDCSkipVerification bool
|
|
|
|
OIDCIssuer string
|
|
|
|
OIDCClientID string
|
|
|
|
OIDCClientSecret string
|
|
|
|
OIDCScopes []string
|
2021-10-31 14:46:23 +00:00
|
|
|
|
|
|
|
SMTPHost string
|
|
|
|
SMTPPort int
|
|
|
|
SMTPUsername string
|
|
|
|
SMTPPassword string
|
|
|
|
SMTPFrom string
|
2021-03-04 13:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetFlagNames returns a struct containing the names of the various flags used for
|
|
|
|
// initializing and storing urfavecli flag variables.
|
|
|
|
func GetFlagNames() Flags {
|
|
|
|
return Flags{
|
|
|
|
LogLevel: "log-level",
|
|
|
|
ApplicationName: "application-name",
|
|
|
|
ConfigPath: "config-path",
|
2021-03-22 21:26:54 +00:00
|
|
|
Host: "host",
|
2021-07-19 16:42:08 +00:00
|
|
|
AccountDomain: "account-domain",
|
2021-03-22 21:26:54 +00:00
|
|
|
Protocol: "protocol",
|
2021-11-22 09:55:52 +00:00
|
|
|
BindAddress: "bind-address",
|
2021-07-24 16:55:24 +00:00
|
|
|
Port: "port",
|
2021-07-26 14:15:36 +00:00
|
|
|
TrustedProxies: "trusted-proxies",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-07-19 16:03:07 +00:00
|
|
|
DbType: "db-type",
|
|
|
|
DbAddress: "db-address",
|
|
|
|
DbPort: "db-port",
|
|
|
|
DbUser: "db-user",
|
|
|
|
DbPassword: "db-password",
|
|
|
|
DbDatabase: "db-database",
|
|
|
|
DbTLSMode: "db-tls-mode",
|
|
|
|
DbTLSCACert: "db-tls-ca-cert",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-03-18 22:27:43 +00:00
|
|
|
TemplateBaseDir: "template-basedir",
|
2021-06-21 17:46:10 +00:00
|
|
|
AssetBaseDir: "asset-basedir",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
|
|
|
AccountsOpenRegistration: "accounts-open-registration",
|
2021-04-19 17:42:19 +00:00
|
|
|
AccountsApprovalRequired: "accounts-approval-required",
|
|
|
|
AccountsReasonRequired: "accounts-reason-required",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-04-19 17:42:19 +00:00
|
|
|
MediaMaxImageSize: "media-max-image-size",
|
|
|
|
MediaMaxVideoSize: "media-max-video-size",
|
|
|
|
MediaMinDescriptionChars: "media-min-description-chars",
|
|
|
|
MediaMaxDescriptionChars: "media-max-description-chars",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
|
|
|
StorageBackend: "storage-backend",
|
|
|
|
StorageBasePath: "storage-base-path",
|
|
|
|
StorageServeProtocol: "storage-serve-protocol",
|
|
|
|
StorageServeHost: "storage-serve-host",
|
|
|
|
StorageServeBasePath: "storage-serve-base-path",
|
2021-04-19 17:42:19 +00:00
|
|
|
|
|
|
|
StatusesMaxChars: "statuses-max-chars",
|
|
|
|
StatusesCWMaxChars: "statuses-cw-max-chars",
|
|
|
|
StatusesPollMaxOptions: "statuses-poll-max-options",
|
|
|
|
StatusesPollOptionMaxChars: "statuses-poll-option-max-chars",
|
|
|
|
StatusesMaxMediaFiles: "statuses-max-media-files",
|
2021-05-09 09:25:13 +00:00
|
|
|
|
|
|
|
LetsEncryptEnabled: "letsencrypt-enabled",
|
2021-07-24 16:55:24 +00:00
|
|
|
LetsEncryptPort: "letsencrypt-port",
|
2021-05-09 09:25:13 +00:00
|
|
|
LetsEncryptCertDir: "letsencrypt-cert-dir",
|
|
|
|
LetsEncryptEmailAddress: "letsencrypt-email",
|
2021-07-23 08:36:28 +00:00
|
|
|
|
|
|
|
OIDCEnabled: "oidc-enabled",
|
|
|
|
OIDCIdpName: "oidc-idp-name",
|
|
|
|
OIDCSkipVerification: "oidc-skip-verification",
|
|
|
|
OIDCIssuer: "oidc-issuer",
|
|
|
|
OIDCClientID: "oidc-client-id",
|
|
|
|
OIDCClientSecret: "oidc-client-secret",
|
|
|
|
OIDCScopes: "oidc-scopes",
|
2021-10-31 14:46:23 +00:00
|
|
|
|
|
|
|
SMTPHost: "smtp-host",
|
|
|
|
SMTPPort: "smtp-port",
|
|
|
|
SMTPUsername: "smtp-username",
|
|
|
|
SMTPPassword: "smtp-password",
|
|
|
|
SMTPFrom: "smtp-from",
|
2021-03-04 13:38:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetEnvNames returns a struct containing the names of the environment variable keys used for
|
|
|
|
// initializing and storing urfavecli flag variables.
|
|
|
|
func GetEnvNames() Flags {
|
|
|
|
return Flags{
|
|
|
|
LogLevel: "GTS_LOG_LEVEL",
|
|
|
|
ApplicationName: "GTS_APPLICATION_NAME",
|
|
|
|
ConfigPath: "GTS_CONFIG_PATH",
|
2021-03-22 21:26:54 +00:00
|
|
|
Host: "GTS_HOST",
|
2021-07-19 16:42:08 +00:00
|
|
|
AccountDomain: "GTS_ACCOUNT_DOMAIN",
|
2021-03-22 21:26:54 +00:00
|
|
|
Protocol: "GTS_PROTOCOL",
|
2021-11-22 09:55:52 +00:00
|
|
|
BindAddress: "GTS_BIND_ADDRESS",
|
2021-07-24 16:55:24 +00:00
|
|
|
Port: "GTS_PORT",
|
2021-07-26 14:15:36 +00:00
|
|
|
TrustedProxies: "GTS_TRUSTED_PROXIES",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-07-19 16:03:07 +00:00
|
|
|
DbType: "GTS_DB_TYPE",
|
|
|
|
DbAddress: "GTS_DB_ADDRESS",
|
|
|
|
DbPort: "GTS_DB_PORT",
|
|
|
|
DbUser: "GTS_DB_USER",
|
|
|
|
DbPassword: "GTS_DB_PASSWORD",
|
|
|
|
DbDatabase: "GTS_DB_DATABASE",
|
|
|
|
DbTLSMode: "GTS_DB_TLS_MODE",
|
|
|
|
DbTLSCACert: "GTS_DB_CA_CERT",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-03-18 22:27:43 +00:00
|
|
|
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
|
2021-06-21 17:46:10 +00:00
|
|
|
AssetBaseDir: "GTS_ASSET_BASEDIR",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
|
|
|
AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
|
2021-04-19 17:42:19 +00:00
|
|
|
AccountsApprovalRequired: "GTS_ACCOUNTS_APPROVAL_REQUIRED",
|
|
|
|
AccountsReasonRequired: "GTS_ACCOUNTS_REASON_REQUIRED",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
2021-04-19 17:42:19 +00:00
|
|
|
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
|
|
|
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
|
|
|
MediaMinDescriptionChars: "GTS_MEDIA_MIN_DESCRIPTION_CHARS",
|
|
|
|
MediaMaxDescriptionChars: "GTS_MEDIA_MAX_DESCRIPTION_CHARS",
|
2021-04-01 18:46:45 +00:00
|
|
|
|
|
|
|
StorageBackend: "GTS_STORAGE_BACKEND",
|
|
|
|
StorageBasePath: "GTS_STORAGE_BASE_PATH",
|
|
|
|
StorageServeProtocol: "GTS_STORAGE_SERVE_PROTOCOL",
|
|
|
|
StorageServeHost: "GTS_STORAGE_SERVE_HOST",
|
|
|
|
StorageServeBasePath: "GTS_STORAGE_SERVE_BASE_PATH",
|
2021-04-19 17:42:19 +00:00
|
|
|
|
|
|
|
StatusesMaxChars: "GTS_STATUSES_MAX_CHARS",
|
|
|
|
StatusesCWMaxChars: "GTS_STATUSES_CW_MAX_CHARS",
|
|
|
|
StatusesPollMaxOptions: "GTS_STATUSES_POLL_MAX_OPTIONS",
|
|
|
|
StatusesPollOptionMaxChars: "GTS_STATUSES_POLL_OPTION_MAX_CHARS",
|
|
|
|
StatusesMaxMediaFiles: "GTS_STATUSES_MAX_MEDIA_FILES",
|
2021-05-09 09:25:13 +00:00
|
|
|
|
|
|
|
LetsEncryptEnabled: "GTS_LETSENCRYPT_ENABLED",
|
2021-07-24 16:55:24 +00:00
|
|
|
LetsEncryptPort: "GTS_LETSENCRYPT_PORT",
|
2021-05-09 09:25:13 +00:00
|
|
|
LetsEncryptCertDir: "GTS_LETSENCRYPT_CERT_DIR",
|
|
|
|
LetsEncryptEmailAddress: "GTS_LETSENCRYPT_EMAIL",
|
2021-07-23 08:36:28 +00:00
|
|
|
|
|
|
|
OIDCEnabled: "GTS_OIDC_ENABLED",
|
|
|
|
OIDCIdpName: "GTS_OIDC_IDP_NAME",
|
|
|
|
OIDCSkipVerification: "GTS_OIDC_SKIP_VERIFICATION",
|
|
|
|
OIDCIssuer: "GTS_OIDC_ISSUER",
|
|
|
|
OIDCClientID: "GTS_OIDC_CLIENT_ID",
|
|
|
|
OIDCClientSecret: "GTS_OIDC_CLIENT_SECRET",
|
|
|
|
OIDCScopes: "GTS_OIDC_SCOPES",
|
2021-10-31 14:46:23 +00:00
|
|
|
|
|
|
|
SMTPHost: "SMTP_HOST",
|
|
|
|
SMTPPort: "SMTP_PORT",
|
|
|
|
SMTPUsername: "SMTP_USERNAME",
|
|
|
|
SMTPPassword: "SMTP_PASSWORD",
|
|
|
|
SMTPFrom: "SMTP_FROM",
|
2021-03-04 13:38:18 +00:00
|
|
|
}
|
2021-03-03 17:12:02 +00:00
|
|
|
}
|