Commit dd40590f authored by John E. Vincent's avatar John E. Vincent

quick reorg of route files

parent f11cdec6
......@@ -58,14 +58,14 @@ module Noah
erb :'500'
end
load File.join(File.dirname(__FILE__), 'tag_routes.rb')
load File.join(File.dirname(__FILE__), 'host_routes.rb')
load File.join(File.dirname(__FILE__), 'service_routes.rb')
load File.join(File.dirname(__FILE__), 'application_routes.rb')
load File.join(File.dirname(__FILE__), 'configuration_routes.rb')
load File.join(File.dirname(__FILE__), 'watcher_routes.rb')
load File.join(File.dirname(__FILE__), 'ephemeral_routes.rb')
load File.join(File.dirname(__FILE__), 'link_routes.rb')
load File.join(File.dirname(__FILE__), 'routes/tags.rb')
load File.join(File.dirname(__FILE__), 'routes/hosts.rb')
load File.join(File.dirname(__FILE__), 'routes/services.rb')
load File.join(File.dirname(__FILE__), 'routes/applications.rb')
load File.join(File.dirname(__FILE__), 'routes/configurations.rb')
load File.join(File.dirname(__FILE__), 'routes/watchers.rb')
load File.join(File.dirname(__FILE__), 'routes/ephemerals.rb')
load File.join(File.dirname(__FILE__), 'routes/links.rb')
end
end
......@@ -7,6 +7,7 @@ module Noah
set :configurations, Configuration
index :name
index :configurations
def validate
super
......
......@@ -5,35 +5,26 @@ class Noah::App
:xml => "text/xml",
:string => "text/plain"
}
# Configuration URIs
get '/configurations/:appname/:element/?' do |appname, element|
a = Noah::Application.find(:name => appname).first
if a.nil?
halt 404
else
c = a.configurations.find(:name => element).first
content_type content_type_mapping[c.format.to_sym] if content_type_mapping[c.format.to_sym]
c.body
end
# GET the raw data of a configuration object
get '/configurations/:configname/data/?' do |configname|
c = Noah::Configuration.find(:name => configname).first
(halt 404) if c.empty?
content_type content_type_mapping[c.format.to_sym] if content_type_mapping[c.format.to_sym]
c.body
end
get '/configurations/:appname/?' do |appname|
config = []
a = Noah::Application.find(:name => appname).first
if a.nil?
halt 404
else
a.configurations.sort.each {|c| config << c.to_hash}
config.to_json
end
# GET the JSON representation of a configuration object
get '/configurations/:configname/?' do |configname|
c = Noah::Configuration.find(:name => configname).first
(halt 404) if c.empty?
c.to_json
end
# GET all configurations
get '/configurations/?' do
configs = Noah::Configurations.all.to_hash
(halt 404) if configs.size == 0
configs.to_json
end
# Add configuration object to a custom link hierarchy
put '/configurations/:configname/link' do |configname|
required_params = ["link_name"]
data = JSON.parse(request.body.read)
......@@ -41,7 +32,7 @@ class Noah::App
a.nil? ? (halt 404) : (a.link! data["link_name"])
a.to_json
end
# Add a tag to a configuration object
put '/configurations/:configname/tag' do |configname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
......@@ -50,6 +41,7 @@ class Noah::App
c.to_json
end
# Add a watch to a configuration object
put '/configurations/:configname/watch' do |configname|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
......@@ -57,11 +49,11 @@ class Noah::App
c.nil? ? (halt 404) : (w = c.watch!(:endpoint => data['endpoint']))
w.to_json
end
put '/configurations/:appname/:element?' do |appname, element|
# Attach a configuration object to an application object
put '/configurations/:configname/:appname?' do |configname, appname|
app = Noah::Application.find_or_create(:name => appname)
dependency_action = app.is_new? ? "created" : "updated"
config = Noah::Configuration.find_or_create(:name => element)
config = Noah::Configuration.find_or_create(:name => configname)
required_params = ["format", "body"]
data = JSON.parse(request.body.read)
data.keys.sort == required_params.sort ? (config.format = data["format"]; config.body = data["body"]) : (raise "Missing Parameters")
......@@ -77,8 +69,12 @@ class Noah::App
end
end
delete '/configurations/:appname/:element?' do |appname, element|
delete '/configurations/:configname/:appname?' do |configname, appname|
app = Noah::Application.find(:name => appname).first
cfg = app.configurations.find(:name => configname).first
# Check with soveran. If we delete the member from the set using .delete, it removes the object. That would break any other users of that object.
(halt 404) if app.empty?
(halt 404) if config.empty?
if app
config = app.configurations.find(:name=> element).first
if config
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment