torrust-index icon indicating copy to clipboard operation
torrust-index copied to clipboard

Config overhaul: version 2 for the configuration (breaking changes)

Open josecelano opened this issue 1 year ago • 1 comments

Parent issue: https://github.com/torrust/torrust-index/issues/586

Changes

  1. Use TrackerMode from torrust-tracker-primitives crate.

Enum variants (Index -> Tracker):

  • Public -> Public
  • Private -> Private
  • Whitelisted -> Listed
  • PrivateWhitelisted -> PrivateListed

Enum serialized values (Index -> Tracker):

  • Public -> public
  • Private -> private
  • Whitelisted -> listed
  • PrivateWhitelisted -> private_listed
  1. Include log_level in a new section [loggging].

Current toml version

log_level = "info"

[website]
name = "Torrust"

[tracker]
api_url = "http://localhost:1212"
mode = "Public"
token = "MyAccessToken"
token_valid_seconds = 7257600
url = "udp://localhost:6969"

[net]
port = 3001

# Uncomment if you want to enable TSL for development
#[net.tsl]
#ssl_cert_path = "./storage/index/lib/tls/localhost.crt"
#ssl_key_path = "./storage/index/lib/tls/localhost.key"

[auth]
email_on_signup = "Optional"
max_password_length = 64
min_password_length = 6
secret_key = "MaxVerstappenWC2021"

[database]
connect_url = "sqlite://data.db?mode=rwc"

[mail]
email_verification_enabled = false
from = "[email protected]"
password = ""
port = 25
reply_to = "[email protected]"
server = ""
username = ""

[image_cache]
capacity = 128000000
entry_size_limit = 4000000
max_request_timeout_ms = 1000
user_quota_bytes = 64000000
user_quota_period_seconds = 3600

[api]
default_torrent_page_size = 10
max_torrent_page_size = 30

[tracker_statistics_importer]
port = 3002
torrent_info_update_interval = 3600

New toml version

[logging]
log_level = "info"

[website]
name = "Torrust"

[tracker]
api_url = "http://localhost:1212"
mode = "public"
token = "MyAccessToken"
token_valid_seconds = 7257600
url = "udp://localhost:6969"

[net]
ip = "0.0.0.0"
port = 3001
base_url = "http://localhost"

# Uncomment if you want to enable TSL for development
#[net.tsl]
#ssl_cert_path = "./storage/index/lib/tls/localhost.crt"
#ssl_key_path = "./storage/index/lib/tls/localhost.key"

[auth]
email_on_signup = "Optional"
max_password_length = 64
min_password_length = 6
secret_key = "MaxVerstappenWC2021"

[database]
connect_url = "sqlite://data.db?mode=rwc"

[mail]
email_verification_enabled = false
from = "[email protected]"
password = ""
port = 25
reply_to = "[email protected]"
server = ""
username = ""

[image_cache]
capacity = 128000000
entry_size_limit = 4000000
max_request_timeout_ms = 1000
user_quota_bytes = 64000000
user_quota_period_seconds = 3600

[api]
default_torrent_page_size = 10
max_torrent_page_size = 30

[tracker_statistics_importer]
port = 3002
torrent_info_update_interval = 3600

Notice: the new value mode = "public" instead of mode = "Public".

cc @da2ce7

josecelano avatar May 17 '24 15:05 josecelano

Should we serialize all enums in lowercase? @da2ce7 . For example: email_on_signup.

josecelano avatar May 17 '24 15:05 josecelano

The conenct_url field in [database] section is actually defined in the sqlx crate

  • Sqlite: sqlite://data.db?mode=rwc.
  • Mysql: mysql://root:root_secret_password@mysql:3306/torrust_index_e2e_testing.
  • PostgreSQL: postgres://postgres:password@localhost/database

It's a URL. We should decide if we want to stick to that representation. I think URL is a generic and standard enough format. So it's not a problem to be coupled to that format.

josecelano avatar May 23 '24 12:05 josecelano

Another question @da2ce7 is: should the default configuration be the development configuration?

pub const DEFAULT_PATH_CONFIG: &str = "./share/default/config/index.development.sqlite3.toml";

./share/default/config/index.development.sqlite3.toml:

log_level = "info"

Default values:

[website]
name = "Torrust"

[tracker]
url = "udp://localhost:6969"
mode = "Public"
api_url = "http://localhost:1212/"
token = "MyAccessToken"
token_valid_seconds = 7257600

[net]
port = 3001

[auth]
email_on_signup = "Optional"
min_password_length = 6
max_password_length = 64
secret_key = "MaxVerstappenWC2021"

[database]
connect_url = "sqlite://data.db?mode=rwc"

[mail]
email_verification_enabled = false
from = "[email protected]"
reply_to = "[email protected]"
username = ""
password = ""
server = ""
port = 25

[image_cache]
max_request_timeout_ms = 1000
capacity = 128000000
entry_size_limit = 4000000
user_quota_period_seconds = 3600
user_quota_bytes = 64000000

[api]
default_torrent_page_size = 10
max_torrent_page_size = 30

[tracker_statistics_importer]
torrent_info_update_interval = 3600
port = 3002

I think it makes more sense if the default configuration is the production default configuration. That leads to another question: What should be the default production configuration? I think It could be the same. Maybe we just need to remove the ./share/default/config/index.development.sqlite3.toml file and just use the default config when the user doesn't provide a config file path.

josecelano avatar May 27 '24 09:05 josecelano

I've also starting using this struct:

struct PasswordConstraints {
    pub min_password_length: usize,
    pub max_password_length: usize,
}

For the auth section in the toml file:

[auth]
email_on_signup = "Optional"
min_password_length = 6
max_password_length = 64
secret_key = "MaxVerstappenWC2021"

So maybe we could change it to:

[auth]
email_on_signup = "Optional"
secret_key = "MaxVerstappenWC2021"

[auth.password_constraints]
min_password_length = 6
max_password_length = 64

josecelano avatar Jun 04 '24 10:06 josecelano

Maybe we canb also refactor the [mail] section, from

[mail]
email_verification_enabled = false
from = "[email protected]"
reply_to = "[email protected]"
username = ""
password = ""
server = ""
port = 25

to:

[mail]
email_verification_enabled = false
from = "[email protected]"
reply_to = "[email protected]"

[mail.smtp]
server = ""
port = 25

[mail.smtp.credentials]
username = ""
password = ""

In JSON:

{
  "mail": {
    "email_verification_enabled": false,
    "from": "[email protected]",
    "reply_to": "[email protected]",
    "smtp": {
      "server": "",
      "port": 25,
      "credentials": {
        "username": "",
        "password": ""
      }
    }
  }
}

josecelano avatar Jun 12 '24 16:06 josecelano

These breaking changes affect other repos:

  • [x] https://github.com/torrust/torrust-index-gui/issues/574
  • [x] https://github.com/torrust/torrust-compose/issues/18
  • [x] https://github.com/torrust/torrust-demo/issues/6
  • [x] https://github.com/torrust/torrust-index-types-lib/issues/18

josecelano avatar Jun 13 '24 15:06 josecelano

I'm reopening just to track changes in the affected repos ☝🏼.

josecelano avatar Jun 13 '24 17:06 josecelano

It seems these changes do not affect tutorials on the website. However, I've opened an issue to check tutorials for setting up a local demo and the dev env.

josecelano avatar Jun 14 '24 10:06 josecelano

Today, we had a meeting, and we decided to include some more changes.

Some of them have already been described in the tracker. See here.

I'm going to to describe here only the extra changes which are specific for this repo.

Improve naming and reorganize fields

Some changes we have discussed to improve the naming and fields have been reorganized:

The current values affected:

[auth]
email_on_signup = "Optional"
secret_key = "MaxVerstappenWC2021"

[mail]
email_verification_enabled = false

The new proposal:

[auth]
# Deprecated.
#secret_key = "MaxVerstappenWC2021"
# Rename secret_key to this. It's only used for this purpose for the time being.
password_database_pepper = "MaxVerstappenWC2021"

[registration]
# Whether we should include the email field in the registration form or not
email_on_profile = "optional" 
# Whether we require email verification or not. This requires [mail] service to be enabled. The app should panic when it starts if it's enabled but there is no mail server config provided.
verification_email = true 

# Optional mail configuration
[mail]
from = "[email protected]"
reply_to = "[email protected]"

# ...

Hey @da2ce7 I think you proposed the name welcome_email but I think you misunderstood the config value. THe email_on_signup does not mean the app sends a welcome email after the registration. It's used to collect the email for the user's profile.

  • Required: the user must provide a valid email even if email verification is disabled.
  • Optional: the app shows the email field in the registration form, but the user can omit it. It can be empty. Some user's profiles may have it and others may not.
  • Ignored: the frontend app does not show the email field at all. However, the API accepts that param in the POST request but, it ignores it.

josecelano avatar Jun 20 '24 16:06 josecelano

Then we could call it:

[registration.email]
required = true
verified = true

If this section is missing, emails addresses are not collected.

da2ce7 avatar Jun 20 '24 16:06 da2ce7

The tracker mode was removed from the tracker. See https://github.com/torrust/torrust-index/issues/648.

We could keep the TrackerModeenum in this repo as an internal Index enum representing all tracker modes that affect the Index. Alternatively, we could remove it and use the new two flags: private and `listed. '

I would also change it here to follow changes in the tracker.

cc @da2ce7

josecelano avatar Jul 02 '24 10:07 josecelano

New subtasks

  • Configuration overhaul: add version to the configuration
  • Configuration overhaul: rename log_level to threshold
  • Configuration overhaul: rename auth::secret_key to auth::password_database_pepper
  • Configuration overhaul: make mail-related configuration clearer
  • Configuration overhaul: split TrackerModeinto two flags private and listed

Make some fields mandatory? @da2ce7

josecelano avatar Jul 02 '24 10:07 josecelano