2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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/>.
|
2022-05-30 13:41:24 +01:00
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: consolidate these methods into the Configuration{} or ConfigState{} structs.
|
|
|
|
|
|
|
|
// AddGlobalFlags will attach global configuration flags to given cobra command, loading defaults from global config.
|
|
|
|
func AddGlobalFlags(cmd *cobra.Command) {
|
2022-11-15 15:53:19 +00:00
|
|
|
global.AddGlobalFlags(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddGlobalFlags will attach global configuration flags to given cobra command, loading defaults from State.
|
|
|
|
func (s *ConfigState) AddGlobalFlags(cmd *cobra.Command) {
|
|
|
|
s.Config(func(cfg *Configuration) {
|
2022-05-30 13:41:24 +01:00
|
|
|
// General
|
|
|
|
cmd.PersistentFlags().String(ApplicationNameFlag(), cfg.ApplicationName, fieldtag("ApplicationName", "usage"))
|
2022-11-03 12:15:31 +00:00
|
|
|
cmd.PersistentFlags().String(LandingPageUserFlag(), cfg.LandingPageUser, fieldtag("LandingPageUser", "usage"))
|
2022-05-30 13:41:24 +01:00
|
|
|
cmd.PersistentFlags().String(HostFlag(), cfg.Host, fieldtag("Host", "usage"))
|
|
|
|
cmd.PersistentFlags().String(AccountDomainFlag(), cfg.AccountDomain, fieldtag("AccountDomain", "usage"))
|
|
|
|
cmd.PersistentFlags().String(ProtocolFlag(), cfg.Protocol, fieldtag("Protocol", "usage"))
|
|
|
|
cmd.PersistentFlags().String(LogLevelFlag(), cfg.LogLevel, fieldtag("LogLevel", "usage"))
|
2023-08-21 19:07:55 +01:00
|
|
|
cmd.PersistentFlags().String(LogTimestampFormatFlag(), cfg.LogTimestampFormat, fieldtag("LogTimestampFormat", "usage"))
|
2022-05-30 13:41:24 +01:00
|
|
|
cmd.PersistentFlags().Bool(LogDbQueriesFlag(), cfg.LogDbQueries, fieldtag("LogDbQueries", "usage"))
|
|
|
|
cmd.PersistentFlags().String(ConfigPathFlag(), cfg.ConfigPath, fieldtag("ConfigPath", "usage"))
|
|
|
|
|
|
|
|
// Database
|
|
|
|
cmd.PersistentFlags().String(DbTypeFlag(), cfg.DbType, fieldtag("DbType", "usage"))
|
|
|
|
cmd.PersistentFlags().String(DbAddressFlag(), cfg.DbAddress, fieldtag("DbAddress", "usage"))
|
|
|
|
cmd.PersistentFlags().Int(DbPortFlag(), cfg.DbPort, fieldtag("DbPort", "usage"))
|
|
|
|
cmd.PersistentFlags().String(DbUserFlag(), cfg.DbUser, fieldtag("DbUser", "usage"))
|
|
|
|
cmd.PersistentFlags().String(DbPasswordFlag(), cfg.DbPassword, fieldtag("DbPassword", "usage"))
|
|
|
|
cmd.PersistentFlags().String(DbDatabaseFlag(), cfg.DbDatabase, fieldtag("DbDatabase", "usage"))
|
|
|
|
cmd.PersistentFlags().String(DbTLSModeFlag(), cfg.DbTLSMode, fieldtag("DbTLSMode", "usage"))
|
|
|
|
cmd.PersistentFlags().String(DbTLSCACertFlag(), cfg.DbTLSCACert, fieldtag("DbTLSCACert", "usage"))
|
2023-01-26 14:12:48 +00:00
|
|
|
cmd.PersistentFlags().Int(DbMaxOpenConnsMultiplierFlag(), cfg.DbMaxOpenConnsMultiplier, fieldtag("DbMaxOpenConnsMultiplier", "usage"))
|
2023-01-17 12:29:44 +00:00
|
|
|
cmd.PersistentFlags().String(DbSqliteJournalModeFlag(), cfg.DbSqliteJournalMode, fieldtag("DbSqliteJournalMode", "usage"))
|
|
|
|
cmd.PersistentFlags().String(DbSqliteSynchronousFlag(), cfg.DbSqliteSynchronous, fieldtag("DbSqliteSynchronous", "usage"))
|
|
|
|
cmd.PersistentFlags().Uint64(DbSqliteCacheSizeFlag(), uint64(cfg.DbSqliteCacheSize), fieldtag("DbSqliteCacheSize", "usage"))
|
|
|
|
cmd.PersistentFlags().Duration(DbSqliteBusyTimeoutFlag(), cfg.DbSqliteBusyTimeout, fieldtag("DbSqliteBusyTimeout", "usage"))
|
2023-07-07 15:17:39 +01:00
|
|
|
|
|
|
|
// HTTPClient
|
|
|
|
cmd.PersistentFlags().StringSlice(HTTPClientAllowIPsFlag(), cfg.HTTPClient.AllowIPs, "no usage string")
|
|
|
|
cmd.PersistentFlags().StringSlice(HTTPClientBlockIPsFlag(), cfg.HTTPClient.BlockIPs, "no usage string")
|
|
|
|
cmd.PersistentFlags().Duration(HTTPClientTimeoutFlag(), cfg.HTTPClient.Timeout, "no usage string")
|
2023-08-01 18:50:17 +01:00
|
|
|
cmd.PersistentFlags().Bool(HTTPClientTLSInsecureSkipVerifyFlag(), cfg.HTTPClient.TLSInsecureSkipVerify, "no usage string")
|
2022-05-30 13:41:24 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddServerFlags will attach server configuration flags to given cobra command, loading defaults from global config.
|
|
|
|
func AddServerFlags(cmd *cobra.Command) {
|
2022-11-15 15:53:19 +00:00
|
|
|
global.AddServerFlags(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddServerFlags will attach server configuration flags to given cobra command, loading defaults from State.
|
|
|
|
func (s *ConfigState) AddServerFlags(cmd *cobra.Command) {
|
|
|
|
s.Config(func(cfg *Configuration) {
|
2022-05-30 13:41:24 +01:00
|
|
|
// Router
|
|
|
|
cmd.PersistentFlags().String(BindAddressFlag(), cfg.BindAddress, fieldtag("BindAddress", "usage"))
|
|
|
|
cmd.PersistentFlags().Int(PortFlag(), cfg.Port, fieldtag("Port", "usage"))
|
|
|
|
cmd.PersistentFlags().StringSlice(TrustedProxiesFlag(), cfg.TrustedProxies, fieldtag("TrustedProxies", "usage"))
|
|
|
|
|
|
|
|
// Template
|
|
|
|
cmd.Flags().String(WebTemplateBaseDirFlag(), cfg.WebTemplateBaseDir, fieldtag("WebTemplateBaseDir", "usage"))
|
|
|
|
cmd.Flags().String(WebAssetBaseDirFlag(), cfg.WebAssetBaseDir, fieldtag("WebAssetBaseDir", "usage"))
|
|
|
|
|
2022-06-23 15:54:54 +01:00
|
|
|
// Instance
|
2023-09-21 11:12:04 +01:00
|
|
|
cmd.Flags().String(InstanceFederationModeFlag(), cfg.InstanceFederationMode, fieldtag("InstanceFederationMode", "usage"))
|
2024-02-27 12:22:05 +00:00
|
|
|
cmd.Flags().Bool(InstanceFederationSpamFilterFlag(), cfg.InstanceFederationSpamFilter, fieldtag("InstanceFederationSpamFilter", "usage"))
|
2022-06-23 15:54:54 +01:00
|
|
|
cmd.Flags().Bool(InstanceExposePeersFlag(), cfg.InstanceExposePeers, fieldtag("InstanceExposePeers", "usage"))
|
|
|
|
cmd.Flags().Bool(InstanceExposeSuspendedFlag(), cfg.InstanceExposeSuspended, fieldtag("InstanceExposeSuspended", "usage"))
|
2023-01-25 17:06:41 +00:00
|
|
|
cmd.Flags().Bool(InstanceExposeSuspendedWebFlag(), cfg.InstanceExposeSuspendedWeb, fieldtag("InstanceExposeSuspendedWeb", "usage"))
|
2022-09-23 20:27:35 +01:00
|
|
|
cmd.Flags().Bool(InstanceDeliverToSharedInboxesFlag(), cfg.InstanceDeliverToSharedInboxes, fieldtag("InstanceDeliverToSharedInboxes", "usage"))
|
2023-11-17 11:29:03 +00:00
|
|
|
cmd.Flags().StringSlice(InstanceLanguagesFlag(), cfg.InstanceLanguages.TagStrs(), fieldtag("InstanceLanguages", "usage"))
|
2022-06-23 15:54:54 +01:00
|
|
|
|
2022-05-30 13:41:24 +01:00
|
|
|
// Accounts
|
|
|
|
cmd.Flags().Bool(AccountsRegistrationOpenFlag(), cfg.AccountsRegistrationOpen, fieldtag("AccountsRegistrationOpen", "usage"))
|
|
|
|
cmd.Flags().Bool(AccountsReasonRequiredFlag(), cfg.AccountsReasonRequired, fieldtag("AccountsReasonRequired", "usage"))
|
2022-09-12 12:14:29 +01:00
|
|
|
cmd.Flags().Bool(AccountsAllowCustomCSSFlag(), cfg.AccountsAllowCustomCSS, fieldtag("AccountsAllowCustomCSS", "usage"))
|
2022-05-30 13:41:24 +01:00
|
|
|
|
|
|
|
// Media
|
|
|
|
cmd.Flags().Int(MediaDescriptionMinCharsFlag(), cfg.MediaDescriptionMinChars, fieldtag("MediaDescriptionMinChars", "usage"))
|
|
|
|
cmd.Flags().Int(MediaDescriptionMaxCharsFlag(), cfg.MediaDescriptionMaxChars, fieldtag("MediaDescriptionMaxChars", "usage"))
|
|
|
|
cmd.Flags().Int(MediaRemoteCacheDaysFlag(), cfg.MediaRemoteCacheDays, fieldtag("MediaRemoteCacheDays", "usage"))
|
2024-07-12 10:39:47 +01:00
|
|
|
cmd.Flags().Uint64(MediaLocalMaxSizeFlag(), uint64(cfg.MediaLocalMaxSize), fieldtag("MediaLocalMaxSize", "usage"))
|
|
|
|
cmd.Flags().Uint64(MediaRemoteMaxSizeFlag(), uint64(cfg.MediaRemoteMaxSize), fieldtag("MediaRemoteMaxSize", "usage"))
|
2022-09-29 21:50:43 +01:00
|
|
|
cmd.Flags().Uint64(MediaEmojiLocalMaxSizeFlag(), uint64(cfg.MediaEmojiLocalMaxSize), fieldtag("MediaEmojiLocalMaxSize", "usage"))
|
|
|
|
cmd.Flags().Uint64(MediaEmojiRemoteMaxSizeFlag(), uint64(cfg.MediaEmojiRemoteMaxSize), fieldtag("MediaEmojiRemoteMaxSize", "usage"))
|
2023-10-30 17:35:11 +00:00
|
|
|
cmd.Flags().String(MediaCleanupFromFlag(), cfg.MediaCleanupFrom, fieldtag("MediaCleanupFrom", "usage"))
|
|
|
|
cmd.Flags().Duration(MediaCleanupEveryFlag(), cfg.MediaCleanupEvery, fieldtag("MediaCleanupEvery", "usage"))
|
2022-05-30 13:41:24 +01:00
|
|
|
|
|
|
|
// Storage
|
|
|
|
cmd.Flags().String(StorageBackendFlag(), cfg.StorageBackend, fieldtag("StorageBackend", "usage"))
|
|
|
|
cmd.Flags().String(StorageLocalBasePathFlag(), cfg.StorageLocalBasePath, fieldtag("StorageLocalBasePath", "usage"))
|
|
|
|
|
|
|
|
// Statuses
|
|
|
|
cmd.Flags().Int(StatusesMaxCharsFlag(), cfg.StatusesMaxChars, fieldtag("StatusesMaxChars", "usage"))
|
|
|
|
cmd.Flags().Int(StatusesPollMaxOptionsFlag(), cfg.StatusesPollMaxOptions, fieldtag("StatusesPollMaxOptions", "usage"))
|
|
|
|
cmd.Flags().Int(StatusesPollOptionMaxCharsFlag(), cfg.StatusesPollOptionMaxChars, fieldtag("StatusesPollOptionMaxChars", "usage"))
|
|
|
|
cmd.Flags().Int(StatusesMediaMaxFilesFlag(), cfg.StatusesMediaMaxFiles, fieldtag("StatusesMediaMaxFiles", "usage"))
|
|
|
|
|
|
|
|
// LetsEncrypt
|
|
|
|
cmd.Flags().Bool(LetsEncryptEnabledFlag(), cfg.LetsEncryptEnabled, fieldtag("LetsEncryptEnabled", "usage"))
|
|
|
|
cmd.Flags().Int(LetsEncryptPortFlag(), cfg.LetsEncryptPort, fieldtag("LetsEncryptPort", "usage"))
|
|
|
|
cmd.Flags().String(LetsEncryptCertDirFlag(), cfg.LetsEncryptCertDir, fieldtag("LetsEncryptCertDir", "usage"))
|
|
|
|
cmd.Flags().String(LetsEncryptEmailAddressFlag(), cfg.LetsEncryptEmailAddress, fieldtag("LetsEncryptEmailAddress", "usage"))
|
|
|
|
|
2023-03-04 17:24:02 +00:00
|
|
|
// Manual TLS
|
|
|
|
cmd.Flags().String(TLSCertificateChainFlag(), cfg.TLSCertificateChain, fieldtag("TLSCertificateChain", "usage"))
|
|
|
|
cmd.Flags().String(TLSCertificateKeyFlag(), cfg.TLSCertificateKey, fieldtag("TLSCertificateKey", "usage"))
|
|
|
|
|
2022-05-30 13:41:24 +01:00
|
|
|
// OIDC
|
|
|
|
cmd.Flags().Bool(OIDCEnabledFlag(), cfg.OIDCEnabled, fieldtag("OIDCEnabled", "usage"))
|
|
|
|
cmd.Flags().String(OIDCIdpNameFlag(), cfg.OIDCIdpName, fieldtag("OIDCIdpName", "usage"))
|
|
|
|
cmd.Flags().Bool(OIDCSkipVerificationFlag(), cfg.OIDCSkipVerification, fieldtag("OIDCSkipVerification", "usage"))
|
|
|
|
cmd.Flags().String(OIDCIssuerFlag(), cfg.OIDCIssuer, fieldtag("OIDCIssuer", "usage"))
|
|
|
|
cmd.Flags().String(OIDCClientIDFlag(), cfg.OIDCClientID, fieldtag("OIDCClientID", "usage"))
|
|
|
|
cmd.Flags().String(OIDCClientSecretFlag(), cfg.OIDCClientSecret, fieldtag("OIDCClientSecret", "usage"))
|
|
|
|
cmd.Flags().StringSlice(OIDCScopesFlag(), cfg.OIDCScopes, fieldtag("OIDCScopes", "usage"))
|
|
|
|
|
|
|
|
// SMTP
|
|
|
|
cmd.Flags().String(SMTPHostFlag(), cfg.SMTPHost, fieldtag("SMTPHost", "usage"))
|
|
|
|
cmd.Flags().Int(SMTPPortFlag(), cfg.SMTPPort, fieldtag("SMTPPort", "usage"))
|
|
|
|
cmd.Flags().String(SMTPUsernameFlag(), cfg.SMTPUsername, fieldtag("SMTPUsername", "usage"))
|
|
|
|
cmd.Flags().String(SMTPPasswordFlag(), cfg.SMTPPassword, fieldtag("SMTPPassword", "usage"))
|
|
|
|
cmd.Flags().String(SMTPFromFlag(), cfg.SMTPFrom, fieldtag("SMTPFrom", "usage"))
|
2023-03-19 12:11:46 +00:00
|
|
|
cmd.Flags().Bool(SMTPDiscloseRecipientsFlag(), cfg.SMTPDiscloseRecipients, fieldtag("SMTPDiscloseRecipients", "usage"))
|
2022-05-30 13:41:24 +01:00
|
|
|
|
|
|
|
// Syslog
|
|
|
|
cmd.Flags().Bool(SyslogEnabledFlag(), cfg.SyslogEnabled, fieldtag("SyslogEnabled", "usage"))
|
|
|
|
cmd.Flags().String(SyslogProtocolFlag(), cfg.SyslogProtocol, fieldtag("SyslogProtocol", "usage"))
|
|
|
|
cmd.Flags().String(SyslogAddressFlag(), cfg.SyslogAddress, fieldtag("SyslogAddress", "usage"))
|
2022-06-03 14:40:38 +01:00
|
|
|
|
|
|
|
// Advanced flags
|
|
|
|
cmd.Flags().String(AdvancedCookiesSamesiteFlag(), cfg.AdvancedCookiesSamesite, fieldtag("AdvancedCookiesSamesite", "usage"))
|
2022-11-06 09:47:48 +00:00
|
|
|
cmd.Flags().Int(AdvancedRateLimitRequestsFlag(), cfg.AdvancedRateLimitRequests, fieldtag("AdvancedRateLimitRequests", "usage"))
|
2023-08-23 13:32:27 +01:00
|
|
|
cmd.Flags().StringSlice(AdvancedRateLimitExceptionsFlag(), cfg.AdvancedRateLimitExceptions, fieldtag("AdvancedRateLimitExceptions", "usage"))
|
2023-01-04 10:57:59 +00:00
|
|
|
cmd.Flags().Int(AdvancedThrottlingMultiplierFlag(), cfg.AdvancedThrottlingMultiplier, fieldtag("AdvancedThrottlingMultiplier", "usage"))
|
2023-02-10 20:16:01 +00:00
|
|
|
cmd.Flags().Duration(AdvancedThrottlingRetryAfterFlag(), cfg.AdvancedThrottlingRetryAfter, fieldtag("AdvancedThrottlingRetryAfter", "usage"))
|
2023-05-08 18:03:38 +01:00
|
|
|
cmd.Flags().Int(AdvancedSenderMultiplierFlag(), cfg.AdvancedSenderMultiplier, fieldtag("AdvancedSenderMultiplier", "usage"))
|
2023-08-20 12:35:55 +01:00
|
|
|
cmd.Flags().StringSlice(AdvancedCSPExtraURIsFlag(), cfg.AdvancedCSPExtraURIs, fieldtag("AdvancedCSPExtraURIs", "usage"))
|
2023-12-18 14:18:25 +00:00
|
|
|
cmd.Flags().String(AdvancedHeaderFilterModeFlag(), cfg.AdvancedHeaderFilterMode, fieldtag("AdvancedHeaderFilterMode", "usage"))
|
2023-02-17 11:02:29 +00:00
|
|
|
|
|
|
|
cmd.Flags().String(RequestIDHeaderFlag(), cfg.RequestIDHeader, fieldtag("RequestIDHeader", "usage"))
|
2022-05-30 13:41:24 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAdminAccount attaches flags pertaining to admin account actions.
|
|
|
|
func AddAdminAccount(cmd *cobra.Command) {
|
|
|
|
name := AdminAccountUsernameFlag()
|
|
|
|
usage := fieldtag("AdminAccountUsername", "usage")
|
|
|
|
cmd.Flags().String(name, "", usage) // REQUIRED
|
|
|
|
if err := cmd.MarkFlagRequired(name); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAdminAccountPassword attaches flags pertaining to admin account password reset.
|
|
|
|
func AddAdminAccountPassword(cmd *cobra.Command) {
|
|
|
|
name := AdminAccountPasswordFlag()
|
|
|
|
usage := fieldtag("AdminAccountPassword", "usage")
|
|
|
|
cmd.Flags().String(name, "", usage) // REQUIRED
|
|
|
|
if err := cmd.MarkFlagRequired(name); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAdminAccountCreate attaches flags pertaining to admin account creation.
|
|
|
|
func AddAdminAccountCreate(cmd *cobra.Command) {
|
|
|
|
// Requires both account and password
|
|
|
|
AddAdminAccount(cmd)
|
|
|
|
AddAdminAccountPassword(cmd)
|
|
|
|
|
|
|
|
name := AdminAccountEmailFlag()
|
|
|
|
usage := fieldtag("AdminAccountEmail", "usage")
|
|
|
|
cmd.Flags().String(name, "", usage) // REQUIRED
|
|
|
|
if err := cmd.MarkFlagRequired(name); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAdminTrans attaches flags pertaining to import/export commands.
|
|
|
|
func AddAdminTrans(cmd *cobra.Command) {
|
|
|
|
name := AdminTransPathFlag()
|
|
|
|
usage := fieldtag("AdminTransPath", "usage")
|
|
|
|
cmd.Flags().String(name, "", usage) // REQUIRED
|
|
|
|
if err := cmd.MarkFlagRequired(name); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2022-11-25 17:23:42 +00:00
|
|
|
|
2023-08-23 17:01:16 +01:00
|
|
|
// AddAdminMediaList attaches flags pertaining to media list commands.
|
|
|
|
func AddAdminMediaList(cmd *cobra.Command) {
|
|
|
|
localOnly := AdminMediaListLocalOnlyFlag()
|
|
|
|
localOnlyUsage := fieldtag("AdminMediaListLocalOnly", "usage")
|
|
|
|
cmd.Flags().Bool(localOnly, false, localOnlyUsage)
|
|
|
|
|
|
|
|
remoteOnly := AdminMediaListRemoteOnlyFlag()
|
|
|
|
remoteOnlyUsage := fieldtag("AdminMediaListRemoteOnly", "usage")
|
|
|
|
cmd.Flags().Bool(remoteOnly, false, remoteOnlyUsage)
|
|
|
|
}
|
|
|
|
|
2022-11-25 17:23:42 +00:00
|
|
|
// AddAdminMediaPrune attaches flags pertaining to media storage prune commands.
|
|
|
|
func AddAdminMediaPrune(cmd *cobra.Command) {
|
|
|
|
name := AdminMediaPruneDryRunFlag()
|
|
|
|
usage := fieldtag("AdminMediaPruneDryRun", "usage")
|
|
|
|
cmd.Flags().Bool(name, true, usage)
|
|
|
|
}
|