Some services now require a domain name to be provided.
parent
e336abdee5
commit
55dbfa7999
|
@ -1,5 +1,6 @@
|
||||||
command: echo "coucou"
|
command: echo "coucou"
|
||||||
consumes: www
|
consumes: www
|
||||||
|
requires-domain: true
|
||||||
|
|
||||||
%directory ${SERVICE_ROOT}/
|
%directory ${SERVICE_ROOT}/
|
||||||
name: data directory
|
name: data directory
|
||||||
|
|
|
@ -44,6 +44,7 @@ commands = CommandsList.new
|
||||||
|
|
||||||
commands.push "add", "Adds a service to an environment." do |args|
|
commands.push "add", "Adds a service to an environment." do |args|
|
||||||
providers = Hash(String, String).new
|
providers = Hash(String, String).new
|
||||||
|
domain = nil
|
||||||
|
|
||||||
environment, service = Service.parse_id args[0]
|
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 /(.*)=(.*)/
|
match = arg.match /(.*)=(.*)/
|
||||||
|
|
||||||
if match.nil?
|
if match.nil? || match.size < 2
|
||||||
raise ::Service::Exception.new "usage: service add <service> <token=provider>"
|
raise ::Service::Exception.new "usage: service add <service> <token=provider>"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
providers[match[1]] = match[2]
|
_, key, value = match
|
||||||
|
|
||||||
|
if key == "domain"
|
||||||
|
domain = value
|
||||||
|
else
|
||||||
|
providers[key] = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Service.new(service, environment).tap do |service|
|
Service.new(service, environment).tap do |service|
|
||||||
|
if domain
|
||||||
|
service.domain = domain
|
||||||
|
end
|
||||||
|
|
||||||
service.consumes.each do |token|
|
service.consumes.each do |token|
|
||||||
provider = providers[token.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
|
service.providers[token.token] = provider
|
||||||
end
|
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.write RC_DIRECTORY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Service
|
||||||
getter environment : Environment
|
getter environment : Environment
|
||||||
getter providers = ProvidersList.new
|
getter providers = ProvidersList.new
|
||||||
|
|
||||||
getter domain : String?
|
property domain : String?
|
||||||
|
|
||||||
# The place we’ll store configuration and data.
|
# The place we’ll store configuration and data.
|
||||||
@root : String?
|
@root : String?
|
||||||
|
@ -81,6 +81,10 @@ class Service
|
||||||
file << "root: #{@root}"
|
file << "root: #{@root}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @domain
|
||||||
|
file << "domain: #{@domain}"
|
||||||
|
end
|
||||||
|
|
||||||
@providers.each do |token, provider|
|
@providers.each do |token, provider|
|
||||||
file << "%consumes #{token}"
|
file << "%consumes #{token}"
|
||||||
file << " from: #{provider}"
|
file << " from: #{provider}"
|
||||||
|
@ -120,6 +124,9 @@ class Service
|
||||||
def consumes
|
def consumes
|
||||||
@reference.consumes
|
@reference.consumes
|
||||||
end
|
end
|
||||||
|
def requires_domain
|
||||||
|
@reference.requires_domain
|
||||||
|
end
|
||||||
|
|
||||||
def root
|
def root
|
||||||
@root || "#{@environment.root}/#{name}"
|
@root || "#{@environment.root}/#{name}"
|
||||||
|
|
|
@ -49,6 +49,8 @@ class ServiceDefinition
|
||||||
getter pre_start_hooks : Array(Hook)
|
getter pre_start_hooks : Array(Hook)
|
||||||
getter provides : Array(Provides)
|
getter provides : Array(Provides)
|
||||||
|
|
||||||
|
getter requires_domain = false
|
||||||
|
|
||||||
def initialize(@name, specs : SpecParser)
|
def initialize(@name, specs : SpecParser)
|
||||||
sections = specs.sections
|
sections = specs.sections
|
||||||
specs = specs.assignments
|
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
|
@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
|
@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
|
@pre_start_hooks = Array(Hook).new
|
||||||
|
|
||||||
sections.each do |section|
|
sections.each do |section|
|
||||||
|
|
Loading…
Reference in New Issue