Some services now require a domain name to be provided.
parent
e336abdee5
commit
55dbfa7999
|
@ -1,5 +1,6 @@
|
|||
command: echo "coucou"
|
||||
consumes: www
|
||||
requires-domain: true
|
||||
|
||||
%directory ${SERVICE_ROOT}/
|
||||
name: data directory
|
||||
|
|
|
@ -44,6 +44,7 @@ commands = CommandsList.new
|
|||
|
||||
commands.push "add", "Adds a service to an environment." do |args|
|
||||
providers = Hash(String, String).new
|
||||
domain = nil
|
||||
|
||||
environment, service = Service.parse_id args[0]
|
||||
|
||||
|
@ -52,15 +53,25 @@ commands.push "add", "Adds a service to an environment." do |args|
|
|||
|
||||
match = arg.match /(.*)=(.*)/
|
||||
|
||||
if match.nil?
|
||||
if match.nil? || match.size < 2
|
||||
raise ::Service::Exception.new "usage: service add <service> <token=provider>"
|
||||
next
|
||||
end
|
||||
|
||||
providers[match[1]] = match[2]
|
||||
_, key, value = match
|
||||
|
||||
if key == "domain"
|
||||
domain = value
|
||||
else
|
||||
providers[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
Service.new(service, environment).tap do |service|
|
||||
if domain
|
||||
service.domain = domain
|
||||
end
|
||||
|
||||
service.consumes.each do |token|
|
||||
provider = providers[token.token]?
|
||||
|
||||
|
@ -76,7 +87,10 @@ commands.push "add", "Adds a service to an environment." do |args|
|
|||
|
||||
service.providers[token.token] = provider
|
||||
end
|
||||
pp! service.providers
|
||||
|
||||
if service.requires_domain && !service.domain
|
||||
raise Service::Exception.new "'#{service.name}' requires a domain= parameter to be provided!"
|
||||
end
|
||||
end.write RC_DIRECTORY
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class Service
|
|||
getter environment : Environment
|
||||
getter providers = ProvidersList.new
|
||||
|
||||
getter domain : String?
|
||||
property domain : String?
|
||||
|
||||
# The place we’ll store configuration and data.
|
||||
@root : String?
|
||||
|
@ -81,6 +81,10 @@ class Service
|
|||
file << "root: #{@root}"
|
||||
end
|
||||
|
||||
if @domain
|
||||
file << "domain: #{@domain}"
|
||||
end
|
||||
|
||||
@providers.each do |token, provider|
|
||||
file << "%consumes #{token}"
|
||||
file << " from: #{provider}"
|
||||
|
@ -120,6 +124,9 @@ class Service
|
|||
def consumes
|
||||
@reference.consumes
|
||||
end
|
||||
def requires_domain
|
||||
@reference.requires_domain
|
||||
end
|
||||
|
||||
def root
|
||||
@root || "#{@environment.root}/#{name}"
|
||||
|
|
|
@ -49,6 +49,8 @@ class ServiceDefinition
|
|||
getter pre_start_hooks : Array(Hook)
|
||||
getter provides : Array(Provides)
|
||||
|
||||
getter requires_domain = false
|
||||
|
||||
def initialize(@name, specs : SpecParser)
|
||||
sections = specs.sections
|
||||
specs = specs.assignments
|
||||
|
@ -60,6 +62,18 @@ class ServiceDefinition
|
|||
@consumes = specs["consumes"]?.try &.as_a_or_s.map { |x| Consumes.new x } || Array(Consumes).new
|
||||
@environment_variables = specs["environment-variables"]?.try &.as_a_or_s || Array(String).new
|
||||
|
||||
# FIXME: as_b?
|
||||
requires_domain = specs["requires-domain"]?.try &.as_s
|
||||
case requires_domain
|
||||
when nil
|
||||
when "true", "yes"
|
||||
@requires_domain = true
|
||||
when "false", "no"
|
||||
@requires_domain = false
|
||||
else
|
||||
STDERR.puts "warning: definition '#{@name}' has a 'requires-domain' entry with an invalid value"
|
||||
end
|
||||
|
||||
@pre_start_hooks = Array(Hook).new
|
||||
|
||||
sections.each do |section|
|
||||
|
|
Loading…
Reference in New Issue