Commit 25e96169 authored by John E. Vincent's avatar John E. Vincent

Moving tags out of primitive routes into helper

parent 17cacf42
...@@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), 'models') ...@@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), 'models')
module Noah module Noah
class App < Sinatra::Base class App < Sinatra::Base
helpers Noah::SinatraBaseHelpers helpers Noah::SinatraBaseHelpers
helpers Noah::SinatraTagHelpers
configure do configure do
set :app_file, __FILE__ set :app_file, __FILE__
......
...@@ -13,22 +13,6 @@ class Noah::App ...@@ -13,22 +13,6 @@ class Noah::App
app.to_json app.to_json
end end
put '/applications/:appname/tag' do |appname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (a=Noah::Application.find(:name=>appname).first) : (raise "Missing Parameters")
a.nil? ? (halt 404) : (a.tag!(data['tags']))
a.to_json
end
delete '/applications/:appname/tag' do |appname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (a=Noah::Application.find(:name=>appname).first) : (raise "Missing Parameters")
a.nil? ? (halt 404) : (a.untag!(data['tags']))
a.to_json
end
put '/applications/:appname/watch' do |appname| put '/applications/:appname/watch' do |appname|
required_params = ["endpoint"] required_params = ["endpoint"]
data = JSON.parse(request.body.read) data = JSON.parse(request.body.read)
......
...@@ -31,22 +31,7 @@ class Noah::App ...@@ -31,22 +31,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|
required_params = ["tags"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (c=Noah::Configuration.find(:name=>configname).first) : (raise "Missing Parameters")
c.nil? ? (halt 404) : (c.tag!(data['tags']))
c.to_json
end
# Delete a tag[s] from a configuration object
delete '/configurations/:configname/tag' do |configname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (c=Noah::Configuration.find(:name=>configname).first) : (raise "Missing Parameters")
c.nil? ? (halt 404) : (c.untag!(data['tags']))
c.to_json
end
# Add a watch to a configuration object # 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"]
......
...@@ -32,24 +32,6 @@ class Noah::App ...@@ -32,24 +32,6 @@ class Noah::App
end end
end end
put '/hosts/:hostname/tag' do |hostname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
raise "Missing parameters" if data.nil?
(data.keys.sort == required_params.sort) ? (a=Noah::Host.find(:name=>hostname).first) : (raise "Missing Parameters")
a.nil? ? (halt 404) : (a.tag!(data['tags']))
a.to_json
end
delete '/hosts/:hostname/tag' do |hostname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
raise "Missing parameters" if data.nil?
(data.keys.sort == required_params.sort) ? (a=Noah::Host.find(:name=>hostname).first) : (raise "Missing Parameters")
a.nil? ? (halt 404) : (a.untag!(data['tags']))
a.to_json
end
put '/hosts/:hostname/watch' do |hostname| put '/hosts/:hostname/watch' do |hostname|
required_params = ["endpoint"] required_params = ["endpoint"]
data = JSON.parse(request.body.read) data = JSON.parse(request.body.read)
......
...@@ -38,22 +38,6 @@ class Noah::App ...@@ -38,22 +38,6 @@ class Noah::App
a.to_json a.to_json
end end
put '/services/:servicename/:hostname/tag' do |servicename, hostname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (a=host_service(hostname, servicename)) : (raise "Missing Parameters")
a.nil? ? (halt 404) : (a.tag!(data['tags']))
a.to_json
end
delete '/services/:servicename/:hostname/tag' do |servicename, hostname|
required_params = ["tags"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (a=host_service(hostname, servicename)) : (raise "Missing Parameters")
a.nil? ? (halt 404) : (a.untag!(data['tags']))
a.to_json
end
put '/services/:servicename/watch' do |servicename| put '/services/:servicename/watch' do |servicename|
required_params = ["endpoint"] required_params = ["endpoint"]
data = JSON.parse(request.body.read) data = JSON.parse(request.body.read)
......
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