-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
67 lines (55 loc) · 1.32 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'sinatra'
require 'sinatra/config_file'
require 'json'
require File.expand_path('helpers', File.dirname(__FILE__))
configure do
set :server, :puma
end
module Tory
class TaskServer < Sinatra::Base
register Sinatra::ConfigFile
config_file 'config/settings.yml'
before do
content_type :json
end
get '/' do
json_response(200, 'Hello world')
end
get '/check/?' do
json_response(404, 'missing required parameters', ['missing mac address'])
end
get '/check/:mac' do
@mac = params[:mac] || params[:mac_address]
unless @mac.nil?
affirm_task(normalize_mac(@mac))
end
end
post '/deploy/?' do
parse_params
unless @mac.nil?
deploy
affirm_task(@mac)
end
end
post '/upload/?' do
parse_params
unless @mac.nil?
upload
affirm_task(@mac)
end
end
delete '/finished/:mac' do
@mac = params[:mac] || params[:mac_address]
task_file = "#{settings.task_path}/#{pxe_mac(@mac)}"
if File.exists? task_file
File.delete task_file
json_response(200, 'task deleted')
else
json_response(404, 'no task file', [@mac])
end
end
helpers do
include Tory::TaskHelpers
end
end
end