195 lines
4.4 KiB
Crystal
195 lines
4.4 KiB
Crystal
# Mentorenwahl: A fullstack application for assigning mentors to students based on their whishes.
|
|
# Copyright (C) 2022 Dominic Grimm
|
|
#
|
|
# 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.
|
|
#
|
|
# 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.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
require "env_config"
|
|
|
|
module Backend
|
|
extend self
|
|
|
|
@@config = Config.new(ENV, prefix: "BACKEND")
|
|
|
|
# Global configuration
|
|
def config : Config
|
|
@@config
|
|
end
|
|
|
|
# Environment based configuration class
|
|
class Config
|
|
include EnvConfig
|
|
|
|
# Types of environments program can compiled for / with
|
|
enum BuildEnv
|
|
Release
|
|
Development
|
|
end
|
|
|
|
# Type of environment program is running in
|
|
def build_env : BuildEnv
|
|
{{ flag?(:release) }} ? BuildEnv::Release : BuildEnv::Development
|
|
end
|
|
|
|
# Release mode
|
|
#
|
|
# `true` if the build environment is `BuildEnv::Release`
|
|
def release? : Bool
|
|
build_env.production?
|
|
end
|
|
|
|
# Development mode
|
|
#
|
|
# `true` if the build environment is `BuildEnv::Development`
|
|
def development? : Bool
|
|
build_env.development?
|
|
end
|
|
|
|
# Base URL of application
|
|
getter url : String
|
|
|
|
# Minimum teacher selection count
|
|
getter minimum_teacher_selection_count : Int32
|
|
|
|
# Assignment possibility count
|
|
getter assignment_possibility_count : UInt32
|
|
|
|
@[EnvConfig::Setting(key: "api")]
|
|
# Configuration for `Api`
|
|
getter api : ApiConfig
|
|
|
|
@[EnvConfig::Setting(key: "smtp")]
|
|
# Configuration for `Mailers`
|
|
getter smtp : SmtpConfig
|
|
|
|
@[EnvConfig::Setting(key: "db")]
|
|
# Configuration for `Db`
|
|
getter db : DbConfig
|
|
|
|
@[EnvConfig::Setting(key: "redis")]
|
|
getter redis : RedisConfig
|
|
|
|
@[EnvConfig::Setting(key: "ldap")]
|
|
# Configuration for `Ldap`
|
|
getter ldap : LdapConfig
|
|
|
|
@[EnvConfig::Setting(key: "auth")]
|
|
# Configuration for authorization provider
|
|
getter auth : AuthConfig
|
|
|
|
# Configuration for `Api`
|
|
class ApiConfig
|
|
include EnvConfig
|
|
|
|
# JWT signing key
|
|
getter jwt_secret : String
|
|
|
|
# JWT expiration time in minutes
|
|
getter jwt_expiration : Int32
|
|
|
|
# Returns true of `playground` flag was set on compile time
|
|
def graphql_playground? : Bool
|
|
flag?(:playground)
|
|
end
|
|
end
|
|
|
|
# Configuration for `Mailers`
|
|
class SmtpConfig
|
|
include EnvConfig
|
|
|
|
# SMTP host HELO
|
|
#
|
|
# NOTE: HELOs are [FQDNs](https://en.wikipedia.org/wiki/Fully_qualified_domain_name), so this should be a domain name
|
|
getter helo : String
|
|
|
|
# SMTP hostname
|
|
getter host : String
|
|
|
|
# SMTP port
|
|
getter port : Int32
|
|
|
|
# Name to send from
|
|
getter name : String
|
|
|
|
# SMTP username
|
|
getter username : String
|
|
|
|
# SMTP password
|
|
getter password : String
|
|
end
|
|
|
|
# Configuration for `Db`
|
|
class DbConfig
|
|
include EnvConfig
|
|
|
|
# Database URL
|
|
getter url : String
|
|
|
|
# Allow old database migrations to be used
|
|
getter allow_old_schema : Bool
|
|
end
|
|
|
|
# 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
|
|
|
|
# Configuration for `Ldap`
|
|
class LdapConfig
|
|
include EnvConfig
|
|
|
|
# LDAP hostname
|
|
getter host : String
|
|
|
|
# LDAP port
|
|
getter port : Int32
|
|
|
|
# LDAP base DN
|
|
getter base_dn : String
|
|
|
|
# LDAP user base DN
|
|
getter base_user_dn : String
|
|
|
|
# LDAP bind DN
|
|
#
|
|
# NOTE: This is the DN to search with
|
|
getter bind_dn : String
|
|
|
|
# LDAP bind password
|
|
getter bind_password : String
|
|
|
|
# Periodical cache refresh interval
|
|
getter cache_refresh_interval : Int32
|
|
end
|
|
|
|
# Configuration for authoriuation API
|
|
class AuthConfig
|
|
include EnvConfig
|
|
|
|
# Auth API URL
|
|
getter url : String
|
|
end
|
|
end
|
|
end
|