From a842f4358c5bc5b1f1aea2236f47a7d03d0df495 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Mon, 3 Apr 2023 00:03:06 +0200 Subject: [PATCH] Config: Add scheme support to DBConfig --- src/invidious/config.cr | 13 +++---------- src/invidious/config/db.cr | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 src/invidious/config/db.cr diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 09c2168b..cd8b839c 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -1,12 +1,5 @@ -struct DBConfig - include YAML::Serializable - - property user : String - property password : String - property host : String - property port : Int32 - property dbname : String -end +require "yaml" +require "./config/*" struct ConfigPreferences include YAML::Serializable @@ -69,7 +62,7 @@ class Config # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr property log_level : LogLevel = LogLevel::Info # Database configuration with separate parameters (username, hostname, etc) - property db : DBConfig? = nil + property db : IV::Config::DBConfig? = nil # Database configuration using 12-Factor "Database URL" syntax @[YAML::Field(converter: Preferences::URIConverter)] diff --git a/src/invidious/config/db.cr b/src/invidious/config/db.cr new file mode 100644 index 00000000..7ee3b9c6 --- /dev/null +++ b/src/invidious/config/db.cr @@ -0,0 +1,23 @@ +module Invidious::Config + struct DBConfig + include YAML::Serializable + + property scheme : String + property user : String + property password : String + property host : String + property port : Int32 + property dbname : String + + def to_uri + return URI.new( + scheme: @scheme, + user: @user, + password: @password, + host: @host, + port: @port, + path: @dbname, + ) + end + end +end