From e13718148d071b9f340098b61cbe714dc061d989 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sun, 30 Jan 2022 14:57:33 +0100 Subject: [feature] Make Let's Encrypt integration an opt-in feature (#368) --- docs/configuration/letsencrypt.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/configuration') diff --git a/docs/configuration/letsencrypt.md b/docs/configuration/letsencrypt.md index 4e3a6d59b..011ab4690 100644 --- a/docs/configuration/letsencrypt.md +++ b/docs/configuration/letsencrypt.md @@ -11,11 +11,11 @@ # Bool. Whether or not letsencrypt should be enabled for the server. # If false, the rest of the settings here will be ignored. -# You should only change this if you want to serve GoToSocial behind a reverse proxy -# like Traefik, HAProxy, or Nginx. +# If you serve GoToSocial behind a reverse proxy like nginx or traefik, leave this turned off. +# If you don't, then turn it on so that you can use https. # Options: [true, false] -# Default: true -letsencrypt-enabled: true +# Default: false +letsencrypt-enabled: false # Int. Port to listen for letsencrypt certificate challenges on. # If letsencrypt is enabled, this port must be reachable or you won't be able to obtain certs. -- cgit v1.2.3 From 959e38ac5c2c2bce82446ed6368f730b4dd01b4a Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sun, 30 Jan 2022 17:06:28 +0100 Subject: [bug] Fix sqlite empty address issue (#370) * error when empty address has been set for sqlite * better explain sqlite db-address setting --- docs/configuration/database.md | 14 ++++++++-- example/config.yaml | 12 ++++++++- internal/db/bundb/bundb.go | 4 +++ internal/db/bundb/bundbnew_test.go | 52 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 internal/db/bundb/bundbnew_test.go (limited to 'docs/configuration') diff --git a/docs/configuration/database.md b/docs/configuration/database.md index 5571843e8..a8d7645e2 100644 --- a/docs/configuration/database.md +++ b/docs/configuration/database.md @@ -8,7 +8,7 @@ By default, GoToSocial will use Postgres, but this is easy to change. SQLite, as the name implies, is the lightest database type that GoToSocial can use. It stores entries in a simple file format, usually in the same directory as the GoToSocial binary itself. SQLite is great for small instances and lower-powered machines like Raspberry Pi, where a dedicated database would be overkill. -To configure GoToSocial to use SQLite, change `db-type` to `sqlite`. The `address` setting will then be a filename instead of an address, so you might want to change it to `sqlite.db` or something similar. +To configure GoToSocial to use SQLite, change `db-type` to `sqlite`. The `address` setting will then be a filename instead of an address, so you will want to change it to `sqlite.db` or something similar. Note that the `:memory:` setting will use an *in-memory database* which will be wiped when your GoToSocial instance stops running. This is for testing only and is absolutely not suitable for running a proper instance, so *don't do this*. @@ -57,7 +57,17 @@ grant all privileges on database gotosocial to gotosocial; db-type: "postgres" # String. Database address or parameters. -# Examples: ["localhost","my.db.host","127.0.0.1","192.111.39.110",":memory:"] +# +# For Postgres, this should be the address or socket at which the database can be reached. +# +# For Sqlite, this should be the path to your sqlite database file. Eg., /opt/gotosocial/sqlite.db. +# If the file doesn't exist at the specified path, it will be created. +# If just a filename is provided (no directory) then the database will be created in the same directory +# as the GoToSocial binary. +# If address is set to :memory: then an in-memory database will be used (no file). +# WARNING: :memory: should NOT BE USED except for testing purposes. +# +# Examples: ["localhost","my.db.host","127.0.0.1","192.111.39.110",":memory:", "sqlite.db"] # Default: "" db-address: "" diff --git a/example/config.yaml b/example/config.yaml index ffc966863..cb84a028c 100644 --- a/example/config.yaml +++ b/example/config.yaml @@ -93,7 +93,17 @@ trusted-proxies: db-type: "postgres" # String. Database address or parameters. -# Examples: ["localhost","my.db.host","127.0.0.1","192.111.39.110",":memory:"] +# +# For Postgres, this should be the address or socket at which the database can be reached. +# +# For Sqlite, this should be the path to your sqlite database file. Eg., /opt/gotosocial/sqlite.db. +# If the file doesn't exist at the specified path, it will be created. +# If just a filename is provided (no directory) then the database will be created in the same directory +# as the GoToSocial binary. +# If address is set to :memory: then an in-memory database will be used (no file). +# WARNING: :memory: should NOT BE USED except for testing purposes. +# +# Examples: ["localhost","my.db.host","127.0.0.1","192.111.39.110",":memory:", "sqlite.db"] # Default: "" db-address: "" diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go index 47fe4fb47..ebdbc4ba2 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -204,7 +204,11 @@ func NewBunDBService(ctx context.Context) (db.DB, error) { } func sqliteConn(ctx context.Context) (*DBConn, error) { + // validate db address has actually been set dbAddress := viper.GetString(config.Keys.DbAddress) + if dbAddress == "" { + return nil, fmt.Errorf("'%s' was not set when attempting to start sqlite", config.Keys.DbAddress) + } // Drop anything fancy from DB address dbAddress = strings.Split(dbAddress, "?")[0] diff --git a/internal/db/bundb/bundbnew_test.go b/internal/db/bundb/bundbnew_test.go new file mode 100644 index 000000000..40a05cb50 --- /dev/null +++ b/internal/db/bundb/bundbnew_test.go @@ -0,0 +1,52 @@ +/* + GoToSocial + Copyright (C) 2021-2022 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 . +*/ + +package bundb_test + +import ( + "context" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/suite" + "github.com/superseriousbusiness/gotosocial/internal/config" + "github.com/superseriousbusiness/gotosocial/internal/db/bundb" +) + +type BundbNewTestSuite struct { + BunDBStandardTestSuite +} + +func (suite *BundbNewTestSuite) TestCreateNewDB() { + // create a new db with standard test settings + db, err := bundb.NewBunDBService(context.Background()) + suite.NoError(err) + suite.NotNil(db) +} + +func (suite *BundbNewTestSuite) TestCreateNewSqliteDBNoAddress() { + // create a new db with no address specified + viper.Set(config.Keys.DbAddress, "") + db, err := bundb.NewBunDBService(context.Background()) + suite.EqualError(err, "'db-address' was not set when attempting to start sqlite") + suite.Nil(db) +} + +func TestBundbNewTestSuite(t *testing.T) { + suite.Run(t, new(BundbNewTestSuite)) +} -- cgit v1.2.3 From 98341a1d4d18b27445f21c5c7aa51f26ac55b653 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Thu, 3 Feb 2022 03:30:06 -0800 Subject: [docs] Fix documentation to show --config-path in the right position. (#375) The current position gets rejected as an unknown argument. --- docs/admin/cli.md | 2 +- docs/configuration/index.md | 2 +- docs/installation_guide/binary.md | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/configuration') diff --git a/docs/admin/cli.md b/docs/admin/cli.md index a65282ceb..7a71f2fcd 100644 --- a/docs/admin/cli.md +++ b/docs/admin/cli.md @@ -31,7 +31,7 @@ Under `Available Commands`, you can see the standard `server` command. But there **Please note -- for all of these commands, you will still need to set the global options correctly so that the CLI tool knows how eg., how to connect to your database, which database to use, which host and account domain to use etc.** -You can set these options using environment variables, passing them as CLI flags (eg., `gotosocial [commands] --host example.org`), or by just pointing the CLI tool towards your config file (eg., `gotosocial [commands] --config-path ./config.yaml`). +You can set these options using environment variables, passing them as CLI flags (eg., `gotosocial [commands] --host example.org`), or by just pointing the CLI tool towards your config file (eg., `gotosocial --config-path ./config.yaml [commands]`). ## gotosocial admin diff --git a/docs/configuration/index.md b/docs/configuration/index.md index ed36505ec..5aa10df9a 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -13,7 +13,7 @@ There are three different methods for configuring a GoToSocial instance, which c The easiest way to configure GoToSocial is to pass a configuration file to to the `gotosocial server start` command, for example: ```bash -gotosocial server start --config-path ./config.yaml +gotosocial --config-path ./config.yaml server start ``` The command expects a file in [YAML](https://en.wikipedia.org/wiki/YAML) or [JSON](https://en.wikipedia.org/wiki/JSON) format. diff --git a/docs/installation_guide/binary.md b/docs/installation_guide/binary.md index 6faba1151..173237da0 100644 --- a/docs/installation_guide/binary.md +++ b/docs/installation_guide/binary.md @@ -77,7 +77,7 @@ You can use the GoToSocial binary to also create, confirm, and promote your user Run the following command to create a new account: ```bash -./gotosocial admin account create --config-path ./config.yaml --username some_username --email some_email@whatever.org --password SOME_PASSWORD +./gotosocial --config-path ./config.yaml admin account create --username some_username --email some_email@whatever.org --password SOME_PASSWORD ``` In the above command, replace `some_username` with your desired username, `some_email@whatever.org` with the email address you want to associate with your account, and `SOME_PASSWORD` with a secure password. @@ -85,7 +85,7 @@ In the above command, replace `some_username` with your desired username, `some_ Run the following command to confirm the account you just created: ```bash -./gotosocial admin account confirm --config-path ./config.yaml --username some_username +./gotosocial --config-path ./config.yaml admin account confirm --username some_username ``` Replace `some_username` with the username of the account you just created. @@ -93,7 +93,7 @@ Replace `some_username` with the username of the account you just created. If you want your user to have admin rights, you can promote them using a similar command: ```bash -./gotosocial admin account promote --config-path ./config.yaml --username some_username +./gotosocial --config-path ./config.yaml admin account promote --username some_username ``` Replace `some_username` with the username of the account you just created. -- cgit v1.2.3