diff options
Diffstat (limited to 'cmd/gotosocial/flag')
-rw-r--r-- | cmd/gotosocial/flag/admin.go | 62 | ||||
-rw-r--r-- | cmd/gotosocial/flag/global.go | 45 | ||||
-rw-r--r-- | cmd/gotosocial/flag/server.go | 111 | ||||
-rw-r--r-- | cmd/gotosocial/flag/usage.go | 80 |
4 files changed, 298 insertions, 0 deletions
diff --git a/cmd/gotosocial/flag/admin.go b/cmd/gotosocial/flag/admin.go new file mode 100644 index 000000000..b087071bb --- /dev/null +++ b/cmd/gotosocial/flag/admin.go @@ -0,0 +1,62 @@ +/* + 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 flag + +import ( + "github.com/spf13/cobra" + "github.com/superseriousbusiness/gotosocial/internal/config" +) + +// AdminAccount attaches flags pertaining to admin account actions. +func AdminAccount(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.AdminAccountUsername, "", usage.AdminAccountUsername) // REQUIRED + if err := cmd.MarkFlagRequired(config.Keys.AdminAccountUsername); err != nil { + panic(err) + } +} + +// AdminAccountPassword attaches flags pertaining to admin account password reset. +func AdminAccountPassword(cmd *cobra.Command, values config.Values) { + AdminAccount(cmd, values) + cmd.Flags().String(config.Keys.AdminAccountPassword, "", usage.AdminAccountPassword) // REQUIRED + if err := cmd.MarkFlagRequired(config.Keys.AdminAccountPassword); err != nil { + panic(err) + } +} + +// AdminAccountCreate attaches flags pertaining to admin account creation. +func AdminAccountCreate(cmd *cobra.Command, values config.Values) { + AdminAccount(cmd, values) + cmd.Flags().String(config.Keys.AdminAccountPassword, "", usage.AdminAccountPassword) // REQUIRED + if err := cmd.MarkFlagRequired(config.Keys.AdminAccountPassword); err != nil { + panic(err) + } + cmd.Flags().String(config.Keys.AdminAccountEmail, "", usage.AdminAccountEmail) // REQUIRED + if err := cmd.MarkFlagRequired(config.Keys.AdminAccountEmail); err != nil { + panic(err) + } +} + +// AdminTrans attaches flags pertaining to import/export commands. +func AdminTrans(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.AdminTransPath, "", usage.AdminTransPath) // REQUIRED + if err := cmd.MarkFlagRequired(config.Keys.AdminTransPath); err != nil { + panic(err) + } +} diff --git a/cmd/gotosocial/flag/global.go b/cmd/gotosocial/flag/global.go new file mode 100644 index 000000000..b7fb03e17 --- /dev/null +++ b/cmd/gotosocial/flag/global.go @@ -0,0 +1,45 @@ +/* + 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 flag + +import ( + "github.com/spf13/cobra" + "github.com/superseriousbusiness/gotosocial/internal/config" +) + +// Global attaches flags that are common to all commands, aka persistent commands. +func Global(cmd *cobra.Command, values config.Values) { + // general stuff + cmd.PersistentFlags().String(config.Keys.ApplicationName, values.ApplicationName, usage.ApplicationName) + cmd.PersistentFlags().String(config.Keys.Host, values.Host, usage.Host) + cmd.PersistentFlags().String(config.Keys.AccountDomain, values.AccountDomain, usage.AccountDomain) + cmd.PersistentFlags().String(config.Keys.Protocol, values.Protocol, usage.Protocol) + cmd.PersistentFlags().String(config.Keys.LogLevel, values.LogLevel, usage.LogLevel) + cmd.PersistentFlags().String(config.Keys.ConfigPath, values.ConfigPath, usage.ConfigPath) + + // database stuff + cmd.PersistentFlags().String(config.Keys.DbType, values.DbType, usage.DbType) + cmd.PersistentFlags().String(config.Keys.DbAddress, values.DbAddress, usage.DbAddress) + cmd.PersistentFlags().Int(config.Keys.DbPort, values.DbPort, usage.DbPort) + cmd.PersistentFlags().String(config.Keys.DbUser, values.DbUser, usage.DbUser) + cmd.PersistentFlags().String(config.Keys.DbPassword, values.DbPassword, usage.DbPassword) + cmd.PersistentFlags().String(config.Keys.DbDatabase, values.DbDatabase, usage.DbDatabase) + cmd.PersistentFlags().String(config.Keys.DbTLSMode, values.DbTLSMode, usage.DbTLSMode) + cmd.PersistentFlags().String(config.Keys.DbTLSCACert, values.DbTLSCACert, usage.DbTLSCACert) +} diff --git a/cmd/gotosocial/flag/server.go b/cmd/gotosocial/flag/server.go new file mode 100644 index 000000000..3d3e946f3 --- /dev/null +++ b/cmd/gotosocial/flag/server.go @@ -0,0 +1,111 @@ +/* + 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 flag + +import ( + "github.com/spf13/cobra" + "github.com/superseriousbusiness/gotosocial/internal/config" +) + +// Server attaches all flags pertaining to running the GtS server or testrig. +func Server(cmd *cobra.Command, values config.Values) { + Template(cmd, values) + Accounts(cmd, values) + Media(cmd, values) + Storage(cmd, values) + Statuses(cmd, values) + LetsEncrypt(cmd, values) + OIDC(cmd, values) + SMTP(cmd, values) + Router(cmd, values) +} + +// Router attaches flags pertaining to the gin router. +func Router(cmd *cobra.Command, values config.Values) { + cmd.PersistentFlags().String(config.Keys.BindAddress, values.BindAddress, usage.BindAddress) + cmd.PersistentFlags().Int(config.Keys.Port, values.Port, usage.Port) + cmd.PersistentFlags().StringSlice(config.Keys.TrustedProxies, values.TrustedProxies, usage.TrustedProxies) +} + +// Template attaches flags pertaining to templating config. +func Template(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.WebTemplateBaseDir, values.WebTemplateBaseDir, usage.WebTemplateBaseDir) + cmd.Flags().String(config.Keys.WebAssetBaseDir, values.WebAssetBaseDir, usage.WebAssetBaseDir) +} + +// Accounts attaches flags pertaining to account config. +func Accounts(cmd *cobra.Command, values config.Values) { + cmd.Flags().Bool(config.Keys.AccountsRegistrationOpen, values.AccountsRegistrationOpen, usage.AccountsRegistrationOpen) + cmd.Flags().Bool(config.Keys.AccountsApprovalRequired, values.AccountsApprovalRequired, usage.AccountsApprovalRequired) + cmd.Flags().Bool(config.Keys.AccountsReasonRequired, values.AccountsReasonRequired, usage.AccountsReasonRequired) +} + +// Media attaches flags pertaining to media config. +func Media(cmd *cobra.Command, values config.Values) { + cmd.Flags().Int(config.Keys.MediaImageMaxSize, values.MediaImageMaxSize, usage.MediaImageMaxSize) + cmd.Flags().Int(config.Keys.MediaVideoMaxSize, values.MediaVideoMaxSize, usage.MediaVideoMaxSize) + cmd.Flags().Int(config.Keys.MediaDescriptionMinChars, values.MediaDescriptionMinChars, usage.MediaDescriptionMinChars) + cmd.Flags().Int(config.Keys.MediaDescriptionMaxChars, values.MediaDescriptionMaxChars, usage.MediaDescriptionMaxChars) +} + +// Storage attaches flags pertaining to storage config. +func Storage(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.StorageBackend, values.StorageBackend, usage.StorageBackend) + cmd.Flags().String(config.Keys.StorageBasePath, values.StorageBasePath, usage.StorageBasePath) + cmd.Flags().String(config.Keys.StorageServeProtocol, values.StorageServeProtocol, usage.StorageServeProtocol) + cmd.Flags().String(config.Keys.StorageServeHost, values.StorageServeHost, usage.StorageServeHost) + cmd.Flags().String(config.Keys.StorageServeBasePath, values.StorageServeBasePath, usage.StorageServeBasePath) +} + +// Statuses attaches flags pertaining to statuses config. +func Statuses(cmd *cobra.Command, values config.Values) { + cmd.Flags().Int(config.Keys.StatusesMaxChars, values.StatusesMaxChars, usage.StatusesMaxChars) + cmd.Flags().Int(config.Keys.StatusesCWMaxChars, values.StatusesCWMaxChars, usage.StatusesCWMaxChars) + cmd.Flags().Int(config.Keys.StatusesPollMaxOptions, values.StatusesPollMaxOptions, usage.StatusesPollMaxOptions) + cmd.Flags().Int(config.Keys.StatusesPollOptionMaxChars, values.StatusesPollOptionMaxChars, usage.StatusesPollOptionMaxChars) + cmd.Flags().Int(config.Keys.StatusesMediaMaxFiles, values.StatusesMediaMaxFiles, usage.StatusesMediaMaxFiles) +} + +// LetsEncrypt attaches flags pertaining to letsencrypt config. +func LetsEncrypt(cmd *cobra.Command, values config.Values) { + cmd.Flags().Bool(config.Keys.LetsEncryptEnabled, values.LetsEncryptEnabled, usage.LetsEncryptEnabled) + cmd.Flags().Int(config.Keys.LetsEncryptPort, values.LetsEncryptPort, usage.LetsEncryptPort) + cmd.Flags().String(config.Keys.LetsEncryptCertDir, values.LetsEncryptCertDir, usage.LetsEncryptCertDir) + cmd.Flags().String(config.Keys.LetsEncryptEmailAddress, values.LetsEncryptEmailAddress, usage.LetsEncryptEmailAddress) +} + +// OIDC attaches flags pertaining to oidc config. +func OIDC(cmd *cobra.Command, values config.Values) { + cmd.Flags().Bool(config.Keys.OIDCEnabled, values.OIDCEnabled, usage.OIDCEnabled) + cmd.Flags().String(config.Keys.OIDCIdpName, values.OIDCIdpName, usage.OIDCIdpName) + cmd.Flags().Bool(config.Keys.OIDCSkipVerification, values.OIDCSkipVerification, usage.OIDCSkipVerification) + cmd.Flags().String(config.Keys.OIDCIssuer, values.OIDCIssuer, usage.OIDCIssuer) + cmd.Flags().String(config.Keys.OIDCClientID, values.OIDCClientID, usage.OIDCClientID) + cmd.Flags().String(config.Keys.OIDCClientSecret, values.OIDCClientSecret, usage.OIDCClientSecret) + cmd.Flags().StringSlice(config.Keys.OIDCScopes, values.OIDCScopes, usage.OIDCScopes) +} + +// SMTP attaches flags pertaining to smtp/email config. +func SMTP(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.SMTPHost, values.SMTPHost, usage.SMTPHost) + cmd.Flags().Int(config.Keys.SMTPPort, values.SMTPPort, usage.SMTPPort) + cmd.Flags().String(config.Keys.SMTPUsername, values.SMTPUsername, usage.SMTPUsername) + cmd.Flags().String(config.Keys.SMTPPassword, values.SMTPPassword, usage.SMTPPassword) + cmd.Flags().String(config.Keys.SMTPFrom, values.SMTPFrom, usage.SMTPFrom) +} diff --git a/cmd/gotosocial/flag/usage.go b/cmd/gotosocial/flag/usage.go new file mode 100644 index 000000000..aa57048c1 --- /dev/null +++ b/cmd/gotosocial/flag/usage.go @@ -0,0 +1,80 @@ +/* + 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 flag + +import "github.com/superseriousbusiness/gotosocial/internal/config" + +var usage = config.KeyNames{ + LogLevel: "Log level to run at: [trace, debug, info, warn, fatal]", + ApplicationName: "Name of the application, used in various places internally", + ConfigPath: "Path to a file containing gotosocial configuration. Values set in this file will be overwritten by values set as env vars or arguments", + Host: "Hostname to use for the server (eg., example.org, gotosocial.whatever.com). DO NOT change this on a server that's already run!", + AccountDomain: "Domain to use in account names (eg., example.org, whatever.com). If not set, will default to the setting for host. DO NOT change this on a server that's already run!", + Protocol: "Protocol to use for the REST api of the server (only use http for debugging and tests!)", + BindAddress: "Bind address to use for the GoToSocial server (eg., 0.0.0.0, 172.138.0.9, [::], localhost). For ipv6, enclose the address in square brackets, eg [2001:db8::fed1]. Default binds to all interfaces.", + Port: "Port to use for GoToSocial. Change this to 443 if you're running the binary directly on the host machine.", + TrustedProxies: "Proxies to trust when parsing x-forwarded headers into real IPs.", + DbType: "Database type: eg., postgres", + DbAddress: "Database ipv4 address, hostname, or filename", + DbPort: "Database port", + DbUser: "Database username", + DbPassword: "Database password", + DbDatabase: "Database name", + DbTLSMode: "Database tls mode", + DbTLSCACert: "Path to CA cert for db tls connection", + WebTemplateBaseDir: "Basedir for html templating files for rendering pages and composing emails.", + WebAssetBaseDir: "Directory to serve static assets from, accessible at example.org/assets/", + AccountsRegistrationOpen: "Allow anyone to submit an account signup request. If false, server will be invite-only.", + AccountsApprovalRequired: "Do account signups require approval by an admin or moderator before user can log in? If false, new registrations will be automatically approved.", + AccountsReasonRequired: "Do new account signups require a reason to be submitted on registration?", + MediaImageMaxSize: "Max size of accepted images in bytes", + MediaVideoMaxSize: "Max size of accepted videos in bytes", + MediaDescriptionMinChars: "Min required chars for an image description", + MediaDescriptionMaxChars: "Max permitted chars for an image description", + StorageBackend: "Storage backend to use for media attachments", + StorageBasePath: "Full path to an already-created directory where gts should store/retrieve media files. Subfolders will be created within this dir.", + StorageServeProtocol: "Protocol to use for serving media attachments (use https if storage is local)", + StorageServeHost: "Hostname to serve media attachments from (use the same value as host if storage is local)", + StorageServeBasePath: "Path to append to protocol and hostname to create the base path from which media files will be served (default will mostly be fine)", + StatusesMaxChars: "Max permitted characters for posted statuses", + StatusesCWMaxChars: "Max permitted characters for content/spoiler warnings on statuses", + StatusesPollMaxOptions: "Max amount of options permitted on a poll", + StatusesPollOptionMaxChars: "Max amount of characters for a poll option", + StatusesMediaMaxFiles: "Maximum number of media files/attachments per status", + LetsEncryptEnabled: "Enable letsencrypt TLS certs for this server. If set to true, then cert dir also needs to be set (or take the default).", + LetsEncryptPort: "Port to listen on for letsencrypt certificate challenges. Must not be the same as the GtS webserver/API port.", + LetsEncryptCertDir: "Directory to store acquired letsencrypt certificates.", + LetsEncryptEmailAddress: "Email address to use when requesting letsencrypt certs. Will receive updates on cert expiry etc.", + OIDCEnabled: "Enabled OIDC authorization for this instance. If set to true, then the other OIDC flags must also be set.", + OIDCIdpName: "Name of the OIDC identity provider. Will be shown to the user when logging in.", + OIDCSkipVerification: "Skip verification of tokens returned by the OIDC provider. Should only be set to 'true' for testing purposes, never in a production environment!", + OIDCIssuer: "Address of the OIDC issuer. Should be the web address, including protocol, at which the issuer can be reached. Eg., 'https://example.org/auth'", + OIDCClientID: "ClientID of GoToSocial, as registered with the OIDC provider.", + OIDCClientSecret: "ClientSecret of GoToSocial, as registered with the OIDC provider.", + OIDCScopes: "OIDC scopes.", + SMTPHost: "Host of the smtp server. Eg., 'smtp.eu.mailgun.org'", + SMTPPort: "Port of the smtp server. Eg., 587", + SMTPUsername: "Username to authenticate with the smtp server as. Eg., 'postmaster@mail.example.org'", + SMTPPassword: "Password to pass to the smtp server.", + SMTPFrom: "Address to use as the 'from' field of the email. Eg., 'gotosocial@example.org'", + AdminAccountUsername: "the username to create/delete/etc", + AdminAccountEmail: "the email address of this account", + AdminAccountPassword: "the password to set for this account", + AdminTransPath: "the path of the file to import from/export to", +} |