summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/accounts.go29
-rw-r--r--internal/config/config.go146
-rw-r--r--internal/config/media.go27
-rw-r--r--internal/config/mock_KeyedFlags.go66
-rw-r--r--internal/config/storage.go36
5 files changed, 271 insertions, 33 deletions
diff --git a/internal/config/accounts.go b/internal/config/accounts.go
new file mode 100644
index 000000000..3fc9e900e
--- /dev/null
+++ b/internal/config/accounts.go
@@ -0,0 +1,29 @@
+/*
+ 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
+
+// AccountsConfig contains configuration to do with creating accounts, new registrations, and defaults.
+type AccountsConfig struct {
+ // Do we want people to be able to just submit sign up requests, or do we want invite only?
+ OpenRegistration bool `yaml:"openRegistration"`
+ // Do sign up requests require approval from an admin/moderator?
+ RequireApproval bool `yaml:"requireApproval"`
+ // Do we require a reason for a sign up or is an empty string OK?
+ ReasonRequired bool `yaml:"reasonRequired"`
+}
diff --git a/internal/config/config.go b/internal/config/config.go
index dca325cbf..811cf166d 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -33,26 +33,21 @@ type Config struct {
Protocol string `yaml:"protocol"`
DBConfig *DBConfig `yaml:"db"`
TemplateConfig *TemplateConfig `yaml:"template"`
+ AccountsConfig *AccountsConfig `yaml:"accounts"`
+ MediaConfig *MediaConfig `yaml:"media"`
+ StorageConfig *StorageConfig `yaml:"storage"`
}
// FromFile returns a new config from a file, or an error if something goes amiss.
func FromFile(path string) (*Config, error) {
- c, err := loadFromFile(path)
- if err != nil {
- return nil, fmt.Errorf("error creating config: %s", err)
- }
- return c, nil
-}
-
-// Default returns a new config with default values.
-// Not yet implemented.
-func Default() *Config {
- // TODO: find a way of doing this without code repetition, because having to
- // repeat all values here and elsewhere is annoying and gonna be prone to mistakes.
- return &Config{
- DBConfig: &DBConfig{},
- TemplateConfig: &TemplateConfig{},
+ if path != "" {
+ c, err := loadFromFile(path)
+ if err != nil {
+ return nil, fmt.Errorf("error creating config: %s", err)
+ }
+ return c, nil
}
+ return Empty(), nil
}
// Empty just returns an empty config
@@ -60,6 +55,9 @@ func Empty() *Config {
return &Config{
DBConfig: &DBConfig{},
TemplateConfig: &TemplateConfig{},
+ AccountsConfig: &AccountsConfig{},
+ MediaConfig: &MediaConfig{},
+ StorageConfig: &StorageConfig{},
}
}
@@ -136,11 +134,51 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) {
if c.TemplateConfig.BaseDir == "" || f.IsSet(fn.TemplateBaseDir) {
c.TemplateConfig.BaseDir = f.String(fn.TemplateBaseDir)
}
+
+ // accounts flags
+ if f.IsSet(fn.AccountsOpenRegistration) {
+ c.AccountsConfig.OpenRegistration = f.Bool(fn.AccountsOpenRegistration)
+ }
+
+ if f.IsSet(fn.AccountsRequireApproval) {
+ c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsRequireApproval)
+ }
+
+ // media flags
+ if c.MediaConfig.MaxImageSize == 0 || f.IsSet(fn.MediaMaxImageSize) {
+ c.MediaConfig.MaxImageSize = f.Int(fn.MediaMaxImageSize)
+ }
+
+ if c.MediaConfig.MaxVideoSize == 0 || f.IsSet(fn.MediaMaxVideoSize) {
+ c.MediaConfig.MaxVideoSize = f.Int(fn.MediaMaxVideoSize)
+ }
+
+ // storage flags
+ if c.StorageConfig.Backend == "" || f.IsSet(fn.StorageBackend) {
+ c.StorageConfig.Backend = f.String(fn.StorageBackend)
+ }
+
+ if c.StorageConfig.BasePath == "" || f.IsSet(fn.StorageBasePath) {
+ c.StorageConfig.BasePath = f.String(fn.StorageBasePath)
+ }
+
+ if c.StorageConfig.ServeProtocol == "" || f.IsSet(fn.StorageServeProtocol) {
+ c.StorageConfig.ServeProtocol = f.String(fn.StorageServeProtocol)
+ }
+
+ if c.StorageConfig.ServeHost == "" || f.IsSet(fn.StorageServeHost) {
+ c.StorageConfig.ServeHost = f.String(fn.StorageServeHost)
+ }
+
+ if c.StorageConfig.ServeBasePath == "" || f.IsSet(fn.StorageServeBasePath) {
+ c.StorageConfig.ServeBasePath = f.String(fn.StorageServeBasePath)
+ }
}
// 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 {
+ Bool(k string) bool
String(k string) string
Int(k string) int
IsSet(k string) bool
@@ -154,13 +192,27 @@ type Flags struct {
ConfigPath string
Host string
Protocol string
- DbType string
- DbAddress string
- DbPort string
- DbUser string
- DbPassword string
- DbDatabase string
+
+ DbType string
+ DbAddress string
+ DbPort string
+ DbUser string
+ DbPassword string
+ DbDatabase string
+
TemplateBaseDir string
+
+ AccountsOpenRegistration string
+ AccountsRequireApproval string
+
+ MediaMaxImageSize string
+ MediaMaxVideoSize string
+
+ StorageBackend string
+ StorageBasePath string
+ StorageServeProtocol string
+ StorageServeHost string
+ StorageServeBasePath string
}
// GetFlagNames returns a struct containing the names of the various flags used for
@@ -172,13 +224,27 @@ func GetFlagNames() Flags {
ConfigPath: "config-path",
Host: "host",
Protocol: "protocol",
- DbType: "db-type",
- DbAddress: "db-address",
- DbPort: "db-port",
- DbUser: "db-user",
- DbPassword: "db-password",
- DbDatabase: "db-database",
+
+ DbType: "db-type",
+ DbAddress: "db-address",
+ DbPort: "db-port",
+ DbUser: "db-user",
+ DbPassword: "db-password",
+ DbDatabase: "db-database",
+
TemplateBaseDir: "template-basedir",
+
+ AccountsOpenRegistration: "accounts-open-registration",
+ AccountsRequireApproval: "accounts-require-approval",
+
+ MediaMaxImageSize: "media-max-image-size",
+ MediaMaxVideoSize: "media-max-video-size",
+
+ StorageBackend: "storage-backend",
+ StorageBasePath: "storage-base-path",
+ StorageServeProtocol: "storage-serve-protocol",
+ StorageServeHost: "storage-serve-host",
+ StorageServeBasePath: "storage-serve-base-path",
}
}
@@ -191,12 +257,26 @@ func GetEnvNames() Flags {
ConfigPath: "GTS_CONFIG_PATH",
Host: "GTS_HOST",
Protocol: "GTS_PROTOCOL",
- DbType: "GTS_DB_TYPE",
- DbAddress: "GTS_DB_ADDRESS",
- DbPort: "GTS_DB_PORT",
- DbUser: "GTS_DB_USER",
- DbPassword: "GTS_DB_PASSWORD",
- DbDatabase: "GTS_DB_DATABASE",
+
+ DbType: "GTS_DB_TYPE",
+ DbAddress: "GTS_DB_ADDRESS",
+ DbPort: "GTS_DB_PORT",
+ DbUser: "GTS_DB_USER",
+ DbPassword: "GTS_DB_PASSWORD",
+ DbDatabase: "GTS_DB_DATABASE",
+
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
+
+ AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
+ AccountsRequireApproval: "GTS_ACCOUNTS_REQUIRE_APPROVAL",
+
+ MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
+ MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
+
+ 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",
}
}
diff --git a/internal/config/media.go b/internal/config/media.go
new file mode 100644
index 000000000..816e236b2
--- /dev/null
+++ b/internal/config/media.go
@@ -0,0 +1,27 @@
+/*
+ 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
+
+// MediaConfig contains configuration for receiving and parsing media files and attachments
+type MediaConfig struct {
+ // Max size of uploaded images in bytes
+ MaxImageSize int `yaml:"maxImageSize"`
+ // Max size of uploaded video in bytes
+ MaxVideoSize int `yaml:"maxVideoSize"`
+}
diff --git a/internal/config/mock_KeyedFlags.go b/internal/config/mock_KeyedFlags.go
new file mode 100644
index 000000000..95057d1d3
--- /dev/null
+++ b/internal/config/mock_KeyedFlags.go
@@ -0,0 +1,66 @@
+// Code generated by mockery v2.7.4. DO NOT EDIT.
+
+package config
+
+import mock "github.com/stretchr/testify/mock"
+
+// MockKeyedFlags is an autogenerated mock type for the KeyedFlags type
+type MockKeyedFlags struct {
+ mock.Mock
+}
+
+// Bool provides a mock function with given fields: k
+func (_m *MockKeyedFlags) Bool(k string) bool {
+ ret := _m.Called(k)
+
+ var r0 bool
+ if rf, ok := ret.Get(0).(func(string) bool); ok {
+ r0 = rf(k)
+ } else {
+ r0 = ret.Get(0).(bool)
+ }
+
+ return r0
+}
+
+// Int provides a mock function with given fields: k
+func (_m *MockKeyedFlags) Int(k string) int {
+ ret := _m.Called(k)
+
+ var r0 int
+ if rf, ok := ret.Get(0).(func(string) int); ok {
+ r0 = rf(k)
+ } else {
+ r0 = ret.Get(0).(int)
+ }
+
+ return r0
+}
+
+// IsSet provides a mock function with given fields: k
+func (_m *MockKeyedFlags) IsSet(k string) bool {
+ ret := _m.Called(k)
+
+ var r0 bool
+ if rf, ok := ret.Get(0).(func(string) bool); ok {
+ r0 = rf(k)
+ } else {
+ r0 = ret.Get(0).(bool)
+ }
+
+ return r0
+}
+
+// String provides a mock function with given fields: k
+func (_m *MockKeyedFlags) String(k string) string {
+ ret := _m.Called(k)
+
+ var r0 string
+ if rf, ok := ret.Get(0).(func(string) string); ok {
+ r0 = rf(k)
+ } else {
+ r0 = ret.Get(0).(string)
+ }
+
+ return r0
+}
diff --git a/internal/config/storage.go b/internal/config/storage.go
new file mode 100644
index 000000000..4a8ff79e4
--- /dev/null
+++ b/internal/config/storage.go
@@ -0,0 +1,36 @@
+/*
+ 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
+
+// StorageConfig contains configuration for storage and serving of media files and attachments
+type StorageConfig struct {
+ // Type of storage backend to use: currently only 'local' is supported.
+ // TODO: add S3 support here.
+ Backend string `yaml:"backend"`
+
+ // The base path for storing things. Should be an already-existing directory.
+ BasePath string `yaml:"basePath"`
+
+ // Protocol to use when *serving* media files from storage
+ ServeProtocol string `yaml:"serveProtocol"`
+ // Host to use when *serving* media files from storage
+ ServeHost string `yaml:"serveHost"`
+ // Base path to use when *serving* media files from storage
+ ServeBasePath string `yaml:"serveBasePath"`
+}