# 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 . 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 # Minimum teacher selection count getter minimum_teacher_selection_count : Int32 # Assignment max run time for algorithm getter assignment_run_time : UInt32 @[EnvConfig::Setting(key: "api")] # Configuration for `Api` getter api : ApiConfig @[EnvConfig::Setting(key: "db")] # Configuration for `Db` getter db : DbConfig @[EnvConfig::Setting(key: "redis")] getter redis : RedisConfig @[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 `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 authoriuation API class AuthConfig include EnvConfig # Auth API URL getter url : String end end end