config.go (19013B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package config 19 20 import ( 21 "reflect" 22 "time" 23 24 "codeberg.org/gruf/go-bytesize" 25 "github.com/mitchellh/mapstructure" 26 ) 27 28 // cfgtype is the reflected type information of Configuration{}. 29 var cfgtype = reflect.TypeOf(Configuration{}) 30 31 // fieldtag will fetch the string value for the given tag name 32 // on the given field name in the Configuration{} struct. 33 func fieldtag(field, tag string) string { 34 sfield, ok := cfgtype.FieldByName(field) 35 if !ok { 36 panic("unknown struct field") 37 } 38 return sfield.Tag.Get(tag) 39 } 40 41 // Configuration represents global GTS server runtime configuration. 42 // 43 // Please note that if you update this struct's fields or tags, you 44 // will need to regenerate the global Getter/Setter helpers by running: 45 // `go run ./internal/config/gen/ -out ./internal/config/helpers.gen.go` 46 type Configuration struct { 47 LogLevel string `name:"log-level" usage:"Log level to run at: [trace, debug, info, warn, fatal]"` 48 LogDbQueries bool `name:"log-db-queries" usage:"Log database queries verbosely when log-level is trace or debug"` 49 LogClientIP bool `name:"log-client-ip" usage:"Include the client IP in logs"` 50 ApplicationName string `name:"application-name" usage:"Name of the application, used in various places internally"` 51 LandingPageUser string `name:"landing-page-user" usage:"the user that should be shown on the instance's landing page"` 52 ConfigPath string `name:"config-path" usage:"Path to a file containing gotosocial configuration. Values set in this file will be overwritten by values set as env vars or arguments"` 53 Host string `name:"host" usage:"Hostname to use for the server (eg., example.org, gotosocial.whatever.com). DO NOT change this on a server that's already run!"` 54 AccountDomain string `name:"account-domain" usage:"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!"` 55 Protocol string `name:"protocol" usage:"Protocol to use for the REST api of the server (only use http if you are debugging or behind a reverse proxy!)"` 56 BindAddress string `name:"bind-address" usage:"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."` 57 Port int `name:"port" usage:"Port to use for GoToSocial. Change this to 443 if you're running the binary directly on the host machine."` 58 TrustedProxies []string `name:"trusted-proxies" usage:"Proxies to trust when parsing x-forwarded headers into real IPs."` 59 SoftwareVersion string `name:"software-version" usage:""` 60 61 DbType string `name:"db-type" usage:"Database type: eg., postgres"` 62 DbAddress string `name:"db-address" usage:"Database ipv4 address, hostname, or filename"` 63 DbPort int `name:"db-port" usage:"Database port"` 64 DbUser string `name:"db-user" usage:"Database username"` 65 DbPassword string `name:"db-password" usage:"Database password"` 66 DbDatabase string `name:"db-database" usage:"Database name"` 67 DbTLSMode string `name:"db-tls-mode" usage:"Database tls mode"` 68 DbTLSCACert string `name:"db-tls-ca-cert" usage:"Path to CA cert for db tls connection"` 69 DbMaxOpenConnsMultiplier int `name:"db-max-open-conns-multiplier" usage:"Multiplier to use per cpu for max open database connections. 0 or less is normalized to 1."` 70 DbSqliteJournalMode string `name:"db-sqlite-journal-mode" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_journal_mode"` 71 DbSqliteSynchronous string `name:"db-sqlite-synchronous" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_synchronous"` 72 DbSqliteCacheSize bytesize.Size `name:"db-sqlite-cache-size" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_cache_size"` 73 DbSqliteBusyTimeout time.Duration `name:"db-sqlite-busy-timeout" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_busy_timeout"` 74 75 WebTemplateBaseDir string `name:"web-template-base-dir" usage:"Basedir for html templating files for rendering pages and composing emails."` 76 WebAssetBaseDir string `name:"web-asset-base-dir" usage:"Directory to serve static assets from, accessible at example.org/assets/"` 77 78 InstanceExposePeers bool `name:"instance-expose-peers" usage:"Allow unauthenticated users to query /api/v1/instance/peers?filter=open"` 79 InstanceExposeSuspended bool `name:"instance-expose-suspended" usage:"Expose suspended instances via web UI, and allow unauthenticated users to query /api/v1/instance/peers?filter=suspended"` 80 InstanceExposeSuspendedWeb bool `name:"instance-expose-suspended-web" usage:"Expose list of suspended instances as webpage on /about/suspended"` 81 InstanceExposePublicTimeline bool `name:"instance-expose-public-timeline" usage:"Allow unauthenticated users to query /api/v1/timelines/public"` 82 InstanceDeliverToSharedInboxes bool `name:"instance-deliver-to-shared-inboxes" usage:"Deliver federated messages to shared inboxes, if they're available."` 83 84 AccountsRegistrationOpen bool `name:"accounts-registration-open" usage:"Allow anyone to submit an account signup request. If false, server will be invite-only."` 85 AccountsApprovalRequired bool `name:"accounts-approval-required" usage:"Do account signups require approval by an admin or moderator before user can log in? If false, new registrations will be automatically approved."` 86 AccountsReasonRequired bool `name:"accounts-reason-required" usage:"Do new account signups require a reason to be submitted on registration?"` 87 AccountsAllowCustomCSS bool `name:"accounts-allow-custom-css" usage:"Allow accounts to enable custom CSS for their profile pages and statuses."` 88 AccountsCustomCSSLength int `name:"accounts-custom-css-length" usage:"Maximum permitted length (characters) of custom CSS for accounts."` 89 90 MediaImageMaxSize bytesize.Size `name:"media-image-max-size" usage:"Max size of accepted images in bytes"` 91 MediaVideoMaxSize bytesize.Size `name:"media-video-max-size" usage:"Max size of accepted videos in bytes"` 92 MediaDescriptionMinChars int `name:"media-description-min-chars" usage:"Min required chars for an image description"` 93 MediaDescriptionMaxChars int `name:"media-description-max-chars" usage:"Max permitted chars for an image description"` 94 MediaRemoteCacheDays int `name:"media-remote-cache-days" usage:"Number of days to locally cache media from remote instances. If set to 0, remote media will be kept indefinitely."` 95 MediaEmojiLocalMaxSize bytesize.Size `name:"media-emoji-local-max-size" usage:"Max size in bytes of emojis uploaded to this instance via the admin API."` 96 MediaEmojiRemoteMaxSize bytesize.Size `name:"media-emoji-remote-max-size" usage:"Max size in bytes of emojis to download from other instances."` 97 98 StorageBackend string `name:"storage-backend" usage:"Storage backend to use for media attachments"` 99 StorageLocalBasePath string `name:"storage-local-base-path" usage:"Full path to an already-created directory where gts should store/retrieve media files. Subfolders will be created within this dir."` 100 StorageS3Endpoint string `name:"storage-s3-endpoint" usage:"S3 Endpoint URL (e.g 'minio.example.org:9000')"` 101 StorageS3AccessKey string `name:"storage-s3-access-key" usage:"S3 Access Key"` 102 StorageS3SecretKey string `name:"storage-s3-secret-key" usage:"S3 Secret Key"` 103 StorageS3UseSSL bool `name:"storage-s3-use-ssl" usage:"Use SSL for S3 connections. Only set this to 'false' when testing locally"` 104 StorageS3BucketName string `name:"storage-s3-bucket" usage:"Place blobs in this bucket"` 105 StorageS3Proxy bool `name:"storage-s3-proxy" usage:"Proxy S3 contents through GoToSocial instead of redirecting to a presigned URL"` 106 107 StatusesMaxChars int `name:"statuses-max-chars" usage:"Max permitted characters for posted statuses"` 108 StatusesCWMaxChars int `name:"statuses-cw-max-chars" usage:"Max permitted characters for content/spoiler warnings on statuses"` 109 StatusesPollMaxOptions int `name:"statuses-poll-max-options" usage:"Max amount of options permitted on a poll"` 110 StatusesPollOptionMaxChars int `name:"statuses-poll-option-max-chars" usage:"Max amount of characters for a poll option"` 111 StatusesMediaMaxFiles int `name:"statuses-media-max-files" usage:"Maximum number of media files/attachments per status"` 112 113 LetsEncryptEnabled bool `name:"letsencrypt-enabled" usage:"Enable letsencrypt TLS certs for this server. If set to true, then cert dir also needs to be set (or take the default)."` 114 LetsEncryptPort int `name:"letsencrypt-port" usage:"Port to listen on for letsencrypt certificate challenges. Must not be the same as the GtS webserver/API port."` 115 LetsEncryptCertDir string `name:"letsencrypt-cert-dir" usage:"Directory to store acquired letsencrypt certificates."` 116 LetsEncryptEmailAddress string `name:"letsencrypt-email-address" usage:"Email address to use when requesting letsencrypt certs. Will receive updates on cert expiry etc."` 117 118 TLSCertificateChain string `name:"tls-certificate-chain" usage:"Filesystem path to the certificate chain including any intermediate CAs and the TLS public key"` 119 TLSCertificateKey string `name:"tls-certificate-key" usage:"Filesystem path to the TLS private key"` 120 121 OIDCEnabled bool `name:"oidc-enabled" usage:"Enabled OIDC authorization for this instance. If set to true, then the other OIDC flags must also be set."` 122 OIDCIdpName string `name:"oidc-idp-name" usage:"Name of the OIDC identity provider. Will be shown to the user when logging in."` 123 OIDCSkipVerification bool `name:"oidc-skip-verification" usage:"Skip verification of tokens returned by the OIDC provider. Should only be set to 'true' for testing purposes, never in a production environment!"` 124 OIDCIssuer string `name:"oidc-issuer" usage:"Address of the OIDC issuer. Should be the web address, including protocol, at which the issuer can be reached. Eg., 'https://example.org/auth'"` 125 OIDCClientID string `name:"oidc-client-id" usage:"ClientID of GoToSocial, as registered with the OIDC provider."` 126 OIDCClientSecret string `name:"oidc-client-secret" usage:"ClientSecret of GoToSocial, as registered with the OIDC provider."` 127 OIDCScopes []string `name:"oidc-scopes" usage:"OIDC scopes."` 128 OIDCLinkExisting bool `name:"oidc-link-existing" usage:"link existing user accounts to OIDC logins based on the stored email value"` 129 OIDCAdminGroups []string `name:"oidc-admin-groups" usage:"Membership of one of the listed groups makes someone a GtS admin"` 130 131 TracingEnabled bool `name:"tracing-enabled" usage:"Enable OTLP Tracing"` 132 TracingTransport string `name:"tracing-transport" usage:"grpc or jaeger"` 133 TracingEndpoint string `name:"tracing-endpoint" usage:"Endpoint of your trace collector. Eg., 'localhost:4317' for gRPC, 'http://localhost:14268/api/traces' for jaeger"` 134 TracingInsecureTransport bool `name:"tracing-insecure" usage:"Disable HTTPS for the gRPC transport protocol"` 135 136 SMTPHost string `name:"smtp-host" usage:"Host of the smtp server. Eg., 'smtp.eu.mailgun.org'"` 137 SMTPPort int `name:"smtp-port" usage:"Port of the smtp server. Eg., 587"` 138 SMTPUsername string `name:"smtp-username" usage:"Username to authenticate with the smtp server as. Eg., 'postmaster@mail.example.org'"` 139 SMTPPassword string `name:"smtp-password" usage:"Password to pass to the smtp server."` 140 SMTPFrom string `name:"smtp-from" usage:"Address to use as the 'from' field of the email. Eg., 'gotosocial@example.org'"` 141 SMTPDiscloseRecipients bool `name:"smtp-disclose-recipients" usage:"If true, email notifications sent to multiple recipients will be To'd to every recipient at once. If false, recipients will not be disclosed"` 142 143 SyslogEnabled bool `name:"syslog-enabled" usage:"Enable the syslog logging hook. Logs will be mirrored to the configured destination."` 144 SyslogProtocol string `name:"syslog-protocol" usage:"Protocol to use when directing logs to syslog. Leave empty to connect to local syslog."` 145 SyslogAddress string `name:"syslog-address" usage:"Address:port to send syslog logs to. Leave empty to connect to local syslog."` 146 147 AdvancedCookiesSamesite string `name:"advanced-cookies-samesite" usage:"'strict' or 'lax', see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite"` 148 AdvancedRateLimitRequests int `name:"advanced-rate-limit-requests" usage:"Amount of HTTP requests to permit within a 5 minute window. 0 or less turns rate limiting off."` 149 AdvancedThrottlingMultiplier int `name:"advanced-throttling-multiplier" usage:"Multiplier to use per cpu for http request throttling. 0 or less turns throttling off."` 150 AdvancedThrottlingRetryAfter time.Duration `name:"advanced-throttling-retry-after" usage:"Retry-After duration response to send for throttled requests."` 151 AdvancedSenderMultiplier int `name:"advanced-sender-multiplier" usage:"Multiplier to use per cpu for batching outgoing fedi messages. 0 or less turns batching off (not recommended)."` 152 153 // Cache configuration vars. 154 Cache CacheConfiguration `name:"cache"` 155 156 // TODO: move these elsewhere, these are more ephemeral vs long-running flags like above 157 AdminAccountUsername string `name:"username" usage:"the username to create/delete/etc"` 158 AdminAccountEmail string `name:"email" usage:"the email address of this account"` 159 AdminAccountPassword string `name:"password" usage:"the password to set for this account"` 160 AdminTransPath string `name:"path" usage:"the path of the file to import from/export to"` 161 AdminMediaPruneDryRun bool `name:"dry-run" usage:"perform a dry run and only log number of items eligible for pruning"` 162 163 RequestIDHeader string `name:"request-id-header" usage:"Header to extract the Request ID from. Eg.,'X-Request-Id'."` 164 } 165 166 type CacheConfiguration struct { 167 GTS GTSCacheConfiguration `name:"gts"` 168 169 VisibilityMaxSize int `name:"visibility-max-size"` 170 VisibilityTTL time.Duration `name:"visibility-ttl"` 171 VisibilitySweepFreq time.Duration `name:"visibility-sweep-freq"` 172 } 173 174 type GTSCacheConfiguration struct { 175 AccountMaxSize int `name:"account-max-size"` 176 AccountTTL time.Duration `name:"account-ttl"` 177 AccountSweepFreq time.Duration `name:"account-sweep-freq"` 178 179 BlockMaxSize int `name:"block-max-size"` 180 BlockTTL time.Duration `name:"block-ttl"` 181 BlockSweepFreq time.Duration `name:"block-sweep-freq"` 182 183 DomainBlockMaxSize int `name:"domain-block-max-size"` 184 DomainBlockTTL time.Duration `name:"domain-block-ttl"` 185 DomainBlockSweepFreq time.Duration `name:"domain-block-sweep-freq"` 186 187 EmojiMaxSize int `name:"emoji-max-size"` 188 EmojiTTL time.Duration `name:"emoji-ttl"` 189 EmojiSweepFreq time.Duration `name:"emoji-sweep-freq"` 190 191 EmojiCategoryMaxSize int `name:"emoji-category-max-size"` 192 EmojiCategoryTTL time.Duration `name:"emoji-category-ttl"` 193 EmojiCategorySweepFreq time.Duration `name:"emoji-category-sweep-freq"` 194 195 FollowMaxSize int `name:"follow-max-size"` 196 FollowTTL time.Duration `name:"follow-ttl"` 197 FollowSweepFreq time.Duration `name:"follow-sweep-freq"` 198 199 FollowRequestMaxSize int `name:"follow-request-max-size"` 200 FollowRequestTTL time.Duration `name:"follow-request-ttl"` 201 FollowRequestSweepFreq time.Duration `name:"follow-request-sweep-freq"` 202 203 ListMaxSize int `name:"list-max-size"` 204 ListTTL time.Duration `name:"list-ttl"` 205 ListSweepFreq time.Duration `name:"list-sweep-freq"` 206 207 ListEntryMaxSize int `name:"list-entry-max-size"` 208 ListEntryTTL time.Duration `name:"list-entry-ttl"` 209 ListEntrySweepFreq time.Duration `name:"list-entry-sweep-freq"` 210 211 MediaMaxSize int `name:"media-max-size"` 212 MediaTTL time.Duration `name:"media-ttl"` 213 MediaSweepFreq time.Duration `name:"media-sweep-freq"` 214 215 MentionMaxSize int `name:"mention-max-size"` 216 MentionTTL time.Duration `name:"mention-ttl"` 217 MentionSweepFreq time.Duration `name:"mention-sweep-freq"` 218 219 NotificationMaxSize int `name:"notification-max-size"` 220 NotificationTTL time.Duration `name:"notification-ttl"` 221 NotificationSweepFreq time.Duration `name:"notification-sweep-freq"` 222 223 ReportMaxSize int `name:"report-max-size"` 224 ReportTTL time.Duration `name:"report-ttl"` 225 ReportSweepFreq time.Duration `name:"report-sweep-freq"` 226 227 StatusMaxSize int `name:"status-max-size"` 228 StatusTTL time.Duration `name:"status-ttl"` 229 StatusSweepFreq time.Duration `name:"status-sweep-freq"` 230 231 StatusFaveMaxSize int `name:"status-fave-max-size"` 232 StatusFaveTTL time.Duration `name:"status-fave-ttl"` 233 StatusFaveSweepFreq time.Duration `name:"status-fave-sweep-freq"` 234 235 TombstoneMaxSize int `name:"tombstone-max-size"` 236 TombstoneTTL time.Duration `name:"tombstone-ttl"` 237 TombstoneSweepFreq time.Duration `name:"tombstone-sweep-freq"` 238 239 UserMaxSize int `name:"user-max-size"` 240 UserTTL time.Duration `name:"user-ttl"` 241 UserSweepFreq time.Duration `name:"user-sweep-freq"` 242 243 WebfingerMaxSize int `name:"webfinger-max-size"` 244 WebfingerTTL time.Duration `name:"webfinger-ttl"` 245 WebfingerSweepFreq time.Duration `name:"webfinger-sweep-freq"` 246 } 247 248 // MarshalMap will marshal current Configuration into a map structure (useful for JSON/TOML/YAML). 249 func (cfg *Configuration) MarshalMap() (map[string]interface{}, error) { 250 var dst map[string]interface{} 251 dec, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ 252 TagName: "name", 253 Result: &dst, 254 }) 255 if err := dec.Decode(cfg); err != nil { 256 return nil, err 257 } 258 return dst, nil 259 }