mentorenwahl/docker/api/src/api/env_requester.cr
Dominic Grimm a9fc6a43b1
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Renamed backend to api
2022-01-20 21:17:24 +01:00

44 lines
789 B
Crystal

module API
class EnvRequester
private property keys
def initialize(@keys = {} of String => String?)
end
def initialize(keys : Array(String))
@keys = {} of String => String?
keys.each { |k| self.<< k }
end
def <<(key : String) : self
@keys[key] = ENV[key]?
self
end
def []?(key : String) : String?
if @keys.has_key?(key)
@keys[key]?
end
end
def [](key : String) : String
if @keys.has_key?(key)
val = @keys[key]?
raise "ENV[#{key}] is nil" unless val
val
else
raise "No such key: #{key}"
end
end
end
ENV_REQUESTER = EnvRequester.new([
"API_DATABASE_URL",
"API_ADMIN_EMAIL",
"API_ADMIN_PASSWORD",
"API_JWT_SECRET",
])
end