mentorenwahl/backend/src/backend/config.cr

195 lines
4.4 KiB
Crystal
Raw Normal View History

2022-02-10 07:43:47 +00:00
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
# Copyright (C) 2022 Dominic Grimm
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# 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 General Public License for more details.
2022-03-07 13:06:02 +00:00
#
2022-02-10 07:43:47 +00:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2022-02-03 16:28:32 +00:00
require "env_config"
module Backend
extend self
@@config = Config.new(ENV, prefix: "BACKEND")
2022-02-07 17:52:17 +00:00
# Global configuration
2022-02-03 16:28:32 +00:00
def config : Config
@@config
end
2022-02-07 17:52:17 +00:00
# Environment based configuration class
2022-02-03 16:28:32 +00:00
class Config
include EnvConfig
2022-02-07 17:52:17 +00:00
# Types of environments program can compiled for / with
enum BuildEnv
2022-10-31 08:47:26 +00:00
Release
2022-02-07 17:52:17 +00:00
Development
end
2022-02-07 17:52:17 +00:00
# Type of environment program is running in
def build_env : BuildEnv
2022-10-31 08:47:26 +00:00
{{ flag?(:release) }} ? BuildEnv::Release : BuildEnv::Development
end
2022-10-31 08:47:26 +00:00
# Release mode
2022-02-07 17:52:17 +00:00
#
2022-10-31 08:47:26 +00:00
# `true` if the build environment is `BuildEnv::Release`
def release? : Bool
2022-02-07 17:52:17 +00:00
build_env.production?
end
2022-02-07 17:52:17 +00:00
# Development mode
#
2022-10-31 08:47:26 +00:00
# `true` if the build environment is `BuildEnv::Development`
2022-02-07 17:52:17 +00:00
def development? : Bool
build_env.development?
end
2022-02-07 17:52:17 +00:00
# Base URL of application
2022-02-03 16:28:32 +00:00
getter url : String
# Minimum teacher selection count
2022-03-13 10:54:42 +00:00
getter minimum_teacher_selection_count : Int32
2022-07-28 12:05:10 +00:00
# Assignment possibility count
2022-12-29 21:24:29 +00:00
getter assignment_possibility_count : UInt32
2022-07-28 12:05:10 +00:00
2022-02-03 16:28:32 +00:00
@[EnvConfig::Setting(key: "api")]
2022-02-07 17:52:17 +00:00
# Configuration for `Api`
getter api : ApiConfig
2022-02-03 16:28:32 +00:00
@[EnvConfig::Setting(key: "smtp")]
2022-02-07 17:52:17 +00:00
# Configuration for `Mailers`
getter smtp : SmtpConfig
2022-02-03 16:28:32 +00:00
@[EnvConfig::Setting(key: "db")]
2022-02-07 17:52:17 +00:00
# Configuration for `Db`
2022-02-03 16:28:32 +00:00
getter db : DbConfig
2022-03-07 08:34:18 +00:00
@[EnvConfig::Setting(key: "redis")]
getter redis : RedisConfig
@[EnvConfig::Setting(key: "ldap")]
2022-02-07 17:52:17 +00:00
# Configuration for `Ldap`
getter ldap : LdapConfig
2023-01-29 10:49:13 +00:00
@[EnvConfig::Setting(key: "auth")]
# Configuration for authorization provider
getter auth : AuthConfig
2022-02-07 17:52:17 +00:00
# Configuration for `Api`
class ApiConfig
2022-02-03 16:28:32 +00:00
include EnvConfig
2022-02-07 17:52:17 +00:00
# JWT signing key
2022-02-03 16:28:32 +00:00
getter jwt_secret : String
# JWT expiration time in minutes
getter jwt_expiration : Int32
2022-10-31 08:47:26 +00:00
# Returns true of `playground` flag was set on compile time
def graphql_playground? : Bool
flag?(:playground)
end
2022-02-03 16:28:32 +00:00
end
2022-02-07 17:52:17 +00:00
# Configuration for `Mailers`
class SmtpConfig
2022-02-03 16:28:32 +00:00
include EnvConfig
2022-02-07 17:52:17 +00:00
# SMTP host HELO
#
# NOTE: HELOs are [FQDNs](https://en.wikipedia.org/wiki/Fully_qualified_domain_name), so this should be a domain name
2022-02-03 16:28:32 +00:00
getter helo : String
2022-02-07 17:52:17 +00:00
# SMTP hostname
getter host : String
2022-02-07 17:52:17 +00:00
# SMTP port
2022-02-03 16:28:32 +00:00
getter port : Int32
2022-02-07 17:52:17 +00:00
# Name to send from
2022-02-03 16:28:32 +00:00
getter name : String
2022-02-07 17:52:17 +00:00
# SMTP username
2022-02-03 16:28:32 +00:00
getter username : String
2022-02-07 17:52:17 +00:00
# SMTP password
2022-02-03 16:28:32 +00:00
getter password : String
end
2022-02-07 17:52:17 +00:00
# Configuration for `Db`
2022-02-03 16:28:32 +00:00
class DbConfig
include EnvConfig
2022-02-07 17:52:17 +00:00
# Database URL
2022-02-03 16:28:32 +00:00
getter url : String
# Allow old database migrations to be used
getter allow_old_schema : Bool
2022-02-03 16:28:32 +00:00
end
2022-03-07 08:34:18 +00:00
# Configuration for `REDIS`
class RedisConfig
include EnvConfig
# Redis host
getter host : String
# Redis port
getter port : Int32
# Redis URL
def url : String
"redis://#{host}:#{port}"
end
end
2022-02-07 17:52:17 +00:00
# Configuration for `Ldap`
class LdapConfig
include EnvConfig
2022-02-07 17:52:17 +00:00
# LDAP hostname
getter host : String
2022-02-07 17:52:17 +00:00
# LDAP port
getter port : Int32
2022-02-07 17:52:17 +00:00
# LDAP base DN
getter base_dn : String
2022-02-07 17:52:17 +00:00
# LDAP user base DN
getter base_user_dn : String
# LDAP bind DN
#
# NOTE: This is the DN to search with
2022-02-06 15:42:08 +00:00
getter bind_dn : String
2022-02-07 17:52:17 +00:00
# LDAP bind password
2022-02-06 15:42:08 +00:00
getter bind_password : String
2022-03-07 08:34:18 +00:00
# Periodical cache refresh interval
getter cache_refresh_interval : Int32
end
2023-01-29 10:49:13 +00:00
# Configuration for authoriuation API
class AuthConfig
include EnvConfig
# Auth API URL
getter url : String
end
2022-02-03 16:28:32 +00:00
end
end