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 ...@@ -58,14 +58,14 @@ module Noah
erb :'500' erb :'500'
end end
load File.join(File.dirname(__FILE__), 'tag_routes.rb') load File.join(File.dirname(__FILE__), 'routes/tags.rb')
load File.join(File.dirname(__FILE__), 'host_routes.rb') load File.join(File.dirname(__FILE__), 'routes/hosts.rb')
load File.join(File.dirname(__FILE__), 'service_routes.rb') load File.join(File.dirname(__FILE__), 'routes/services.rb')
load File.join(File.dirname(__FILE__), 'application_routes.rb') load File.join(File.dirname(__FILE__), 'routes/applications.rb')
load File.join(File.dirname(__FILE__), 'configuration_routes.rb') load File.join(File.dirname(__FILE__), 'routes/configurations.rb')
load File.join(File.dirname(__FILE__), 'watcher_routes.rb') load File.join(File.dirname(__FILE__), 'routes/watchers.rb')
load File.join(File.dirname(__FILE__), 'ephemeral_routes.rb') load File.join(File.dirname(__FILE__), 'routes/ephemerals.rb')
load File.join(File.dirname(__FILE__), 'link_routes.rb') load File.join(File.dirname(__FILE__), 'routes/links.rb')
end end
end end
...@@ -7,6 +7,7 @@ module Noah ...@@ -7,6 +7,7 @@ module Noah
set :configurations, Configuration set :configurations, Configuration
index :name index :name
index :configurations
def validate def validate
super super
......
...@@ -5,35 +5,26 @@ class Noah::App ...@@ -5,35 +5,26 @@ class Noah::App
:xml => "text/xml", :xml => "text/xml",
:string => "text/plain" :string => "text/plain"
} }
# Configuration URIs # GET the raw data of a configuration object
get '/configurations/:appname/:element/?' do |appname, element| get '/configurations/:configname/data/?' do |configname|
a = Noah::Application.find(:name => appname).first c = Noah::Configuration.find(:name => configname).first
if a.nil? (halt 404) if c.empty?
halt 404 content_type content_type_mapping[c.format.to_sym] if content_type_mapping[c.format.to_sym]
else c.body
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
end end
# GET the JSON representation of a configuration object
get '/configurations/:appname/?' do |appname| get '/configurations/:configname/?' do |configname|
config = [] c = Noah::Configuration.find(:name => configname).first
a = Noah::Application.find(:name => appname).first (halt 404) if c.empty?
if a.nil? c.to_json
halt 404
else
a.configurations.sort.each {|c| config << c.to_hash}
config.to_json
end
end end
# GET all configurations
get '/configurations/?' do get '/configurations/?' do
configs = Noah::Configurations.all.to_hash configs = Noah::Configurations.all.to_hash
(halt 404) if configs.size == 0 (halt 404) if configs.size == 0
configs.to_json configs.to_json
end end
# Add configuration object to a custom link hierarchy
put '/configurations/:configname/link' do |configname| put '/configurations/:configname/link' do |configname|
required_params = ["link_name"] required_params = ["link_name"]
data = JSON.parse(request.body.read) data = JSON.parse(request.body.read)
...@@ -41,7 +32,7 @@ class Noah::App ...@@ -41,7 +32,7 @@ class Noah::App
a.nil? ? (halt 404) : (a.link! data["link_name"]) a.nil? ? (halt 404) : (a.link! data["link_name"])
a.to_json a.to_json
end end
# Add a tag to a configuration object
put '/configurations/:configname/tag' do |configname| put '/configurations/:configname/tag' do |configname|
required_params = ["tags"] required_params = ["tags"]
data = JSON.parse(request.body.read) data = JSON.parse(request.body.read)
...@@ -50,6 +41,7 @@ class Noah::App ...@@ -50,6 +41,7 @@ class Noah::App
c.to_json c.to_json
end end
# Add a watch to a configuration object
put '/configurations/:configname/watch' do |configname| put '/configurations/:configname/watch' do |configname|
required_params = ["endpoint"] required_params = ["endpoint"]
data = JSON.parse(request.body.read) data = JSON.parse(request.body.read)
...@@ -57,11 +49,11 @@ class Noah::App ...@@ -57,11 +49,11 @@ class Noah::App
c.nil? ? (halt 404) : (w = c.watch!(:endpoint => data['endpoint'])) c.nil? ? (halt 404) : (w = c.watch!(:endpoint => data['endpoint']))
w.to_json w.to_json
end end
# Attach a configuration object to an application object
put '/configurations/:appname/:element?' do |appname, element| put '/configurations/:configname/:appname?' do |configname, appname|
app = Noah::Application.find_or_create(:name => appname) app = Noah::Application.find_or_create(:name => appname)
dependency_action = app.is_new? ? "created" : "updated" 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"] required_params = ["format", "body"]
data = JSON.parse(request.body.read) data = JSON.parse(request.body.read)
data.keys.sort == required_params.sort ? (config.format = data["format"]; config.body = data["body"]) : (raise "Missing Parameters") data.keys.sort == required_params.sort ? (config.format = data["format"]; config.body = data["body"]) : (raise "Missing Parameters")
...@@ -77,8 +69,12 @@ class Noah::App ...@@ -77,8 +69,12 @@ class Noah::App
end end
end end
delete '/configurations/:appname/:element?' do |appname, element| delete '/configurations/:configname/:appname?' do |configname, appname|
app = Noah::Application.find(:name => appname).first 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 if app
config = app.configurations.find(:name=> element).first config = app.configurations.find(:name=> element).first
if config 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