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
|
2022-02-04 16:01:15 +00:00
|
|
|
enum BuildEnv
|
2022-10-31 08:47:26 +00:00
|
|
|
Release
|
2022-02-07 17:52:17 +00:00
|
|
|
Development
|
2022-02-04 16:01:15 +00:00
|
|
|
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
|
2022-02-04 16:01:15 +00:00
|
|
|
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?
|
2022-02-04 16:01:15 +00:00
|
|
|
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?
|
2022-02-04 16:01:15 +00:00
|
|
|
end
|
|
|
|
|
2022-03-13 09:39:08 +00:00
|
|
|
# Minimum teacher selection count
|
2022-03-13 10:54:42 +00:00
|
|
|
getter minimum_teacher_selection_count : Int32
|
2022-03-13 09:39:08 +00:00
|
|
|
|
2023-03-05 12:52:30 +00:00
|
|
|
# Assignment max run time for algorithm
|
|
|
|
getter assignment_run_time : 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`
|
2022-02-05 13:31:35 +00:00
|
|
|
getter api : ApiConfig
|
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
|
|
|
|
|
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`
|
2022-02-05 13:31:35 +00:00
|
|
|
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
|
2022-02-04 16:01:15 +00:00
|
|
|
|
2022-03-07 12:50:28 +00:00
|
|
|
# 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)
|
2022-02-04 16:01:15 +00:00
|
|
|
end
|
2022-02-03 16:28:32 +00:00
|
|
|
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
|
2022-04-05 18:26:22 +00:00
|
|
|
|
|
|
|
# Allow old database migrations to be used
|
|
|
|
getter allow_old_schema : Bool
|
2022-02-03 16:28:32 +00:00
|
|
|
end
|
2022-02-05 13:31:35 +00:00
|
|
|
|
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
|
|
|
|
|
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
|