Internal changes in gen-config.
Most data are now read from service files instead of the process’ environment. Some environment variables are still being used to identify the target service, however.
This commit is contained in:
parent
8d0708dee8
commit
1bc9181caa
@ -8,10 +8,16 @@ def sanitize_path(path)
|
||||
end
|
||||
|
||||
module GenConfig
|
||||
alias Variables =
|
||||
String |
|
||||
Array(String) | Array(Variables) |
|
||||
Hash(String, String) | Hash(String, Variables) |
|
||||
Crinja::Callable::Instance
|
||||
|
||||
def self.parse_options(unparsed : Array(String))
|
||||
options = ARGV.map(&.split '=')
|
||||
|
||||
hash = Hash(String, String | Array(String) | Crinja::Callable::Instance | Hash(String, String)).new
|
||||
hash = Hash(String, Variables).new
|
||||
|
||||
options.each do |entry|
|
||||
key, value = entry
|
||||
@ -41,7 +47,10 @@ class GenConfig::Context
|
||||
def initialize(@root)
|
||||
end
|
||||
|
||||
def generate(template, target : String, options : Hash(String, String | Array(String) | Crinja::Callable::Instance | Hash(String, String)))
|
||||
def generate(template, target : String, options : Hash(String, Variables))
|
||||
ServiceDefinition.load SERVICES_DIRECTORY
|
||||
Service.load RC_DIRECTORY
|
||||
|
||||
target_file = File.open target, "w"
|
||||
|
||||
sources = [
|
||||
@ -65,12 +74,37 @@ class GenConfig::Context
|
||||
raise Exception.new "Could not find template to generate file ('#{target}')."
|
||||
end
|
||||
|
||||
options["id"] = ENV["SERVICE_ID"]? || ""
|
||||
options["environment"] = ENV["ENVIRONMENT"]? || ""
|
||||
pp ENV["SERVICE_ID"]?
|
||||
if service_id = ENV["SERVICE_ID"]?
|
||||
if service = Service.get_by_id service_id
|
||||
environment = service.environment
|
||||
|
||||
options["id"] = service.full_id
|
||||
options["name"] = service.name
|
||||
|
||||
options["environment"] = environment.name
|
||||
|
||||
providers = Hash(String, Variables).new
|
||||
service.providers.each do |token, provider|
|
||||
provider = Service.get_by_id provider
|
||||
|
||||
next unless provider
|
||||
|
||||
providers[token] = Hash(String, String).new.tap do |entry|
|
||||
entry["name"] = provider.name
|
||||
entry["id"] = provider.full_id
|
||||
entry["environment"] = provider.environment.name
|
||||
end
|
||||
end
|
||||
options["providers"] = providers
|
||||
end
|
||||
end
|
||||
|
||||
options["port"] = Crinja.function do
|
||||
service = (arguments.varargs[0]? || "").to_s.gsub /\//, ':'
|
||||
`get-port #{service}`.chomp
|
||||
end
|
||||
|
||||
options["random_password"] = Crinja.function do
|
||||
id = (arguments.varargs[0]? || options["id"]).to_s
|
||||
password_id = arguments.varargs[1]? || "main"
|
||||
|
Loading…
Reference in New Issue
Block a user