2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
module Devops
|
|
|
|
|
module Version2_0
|
2014-12-22 14:22:04 +03:00
|
|
|
module Routes
|
2014-12-15 14:26:54 +03:00
|
|
|
module ScriptRoutes
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
def self.registered(app)
|
|
|
|
|
app.before "/script/:script_name" do
|
|
|
|
|
check_headers :accept
|
|
|
|
|
check_privileges("script", "w")
|
|
|
|
|
file_name = params[:script_name]
|
|
|
|
|
@file = File.join(DevopsService.config[:scripts_dir], check_filename(file_name, "Parameter 'script_name' must be a not empty string"))
|
|
|
|
|
if request.put?
|
|
|
|
|
halt_response("File '#{file_name}' already exist") if File.exists?(@file)
|
|
|
|
|
elsif request.delete?
|
|
|
|
|
halt_response("File '#{file_name}' does not exist", 404) unless File.exists?(@file)
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
app.after %r{\A/script/((command|run)/)?[\w]+\z} do
|
|
|
|
|
statistic
|
|
|
|
|
end
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
# Get scripts names
|
|
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : GET
|
|
|
|
|
# - headers :
|
|
|
|
|
# - Accept: application/json
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* :
|
|
|
|
|
# [
|
|
|
|
|
# "script_1"
|
|
|
|
|
# ]
|
2014-12-22 14:22:04 +03:00
|
|
|
app.before "/scripts" do
|
2014-12-15 14:26:54 +03:00
|
|
|
check_headers :accept
|
|
|
|
|
check_privileges("script", "r")
|
|
|
|
|
end
|
2014-12-22 14:22:04 +03:00
|
|
|
app.get "/scripts", &Devops::Version2_0::Handler::Script.get_scripts
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
# Run command on node :node_name
|
|
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : POST
|
|
|
|
|
# - body :
|
|
|
|
|
# command to run
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* : text stream
|
2014-12-22 14:22:04 +03:00
|
|
|
app.before "/script/command/:node_name" do
|
2014-12-15 14:26:54 +03:00
|
|
|
check_privileges("script", "x")
|
2014-05-08 15:34:26 +04:00
|
|
|
end
|
2014-12-22 14:22:04 +03:00
|
|
|
app.post "/script/command/:node_name", &Devops::Version2_0::Handler::Script.execute_command
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
# Run script :script_name on nodes
|
|
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : POST
|
|
|
|
|
# - headers :
|
|
|
|
|
# - Content-Type: application/json
|
|
|
|
|
# - body :
|
|
|
|
|
# {
|
|
|
|
|
# "nodes": [], -> array of nodes names
|
|
|
|
|
# "params": [] -> array of script arguments
|
|
|
|
|
# }
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* : text stream
|
2014-12-22 14:22:04 +03:00
|
|
|
app.before "/script/run/:script_name" do
|
2014-12-15 14:26:54 +03:00
|
|
|
check_headers :content_type
|
|
|
|
|
check_privileges("script", "x")
|
2014-05-08 15:34:26 +04:00
|
|
|
end
|
2014-12-22 14:22:04 +03:00
|
|
|
app.post "/script/run/:script_name", &Devops::Version2_0::Handler::Script.run_script
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
# Create script :script_name
|
|
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : PUT
|
|
|
|
|
# - headers :
|
|
|
|
|
# - Accept: application/json
|
|
|
|
|
# - body : script content
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* :
|
|
|
|
|
# 201 - Created
|
2014-12-22 14:22:04 +03:00
|
|
|
app.put "/script/:script_name", &Devops::Version2_0::Handler::Script.create_script
|
2014-12-15 14:26:54 +03:00
|
|
|
|
|
|
|
|
# Delete script :script_name
|
|
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : Delete
|
|
|
|
|
# - headers :
|
|
|
|
|
# - Accept: application/json
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* :
|
|
|
|
|
# 200 - Deleted
|
2014-12-22 14:22:04 +03:00
|
|
|
app.delete "/script/:script_name", &Devops::Version2_0::Handler::Script.delete_script
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-15 14:26:54 +03:00
|
|
|
puts "Script routes initialized"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
2014-05-08 15:34:26 +04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|