-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_plugin_middleware.rb
46 lines (34 loc) · 1.07 KB
/
docker_plugin_middleware.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
require 'sinatra'
require 'json'
module DockerPlugins
VOLUME_CMDS = Set['Create','Remove','Mount','Path','Unmount','Get','List']
def self.new_app
Sinatra.new do
# EXERCISE: Validate that Accept: header contains something we understand.
post '/Plugin.Activate' do
implements = []
implements << "VolumeDriver" if settings.volumedriver
implements << "NetworkDriver" if settings.networkdriver
{ "Implements" => implements }.to_json
end
post '/VolumeDriver.:cmd' do |cmd|
puts cmd
cmd = cmd.to_s.downcase.to_sym
args = JSON.parse(request.body.read)
puts args.inspect
if settings.volumedriver && settings.volumedriver.respond_to?(cmd)
settings.volumedriver.send(cmd,args["Name"]).to_json
else
{ "Err" => "Not implemented: #{cmd.to_s}"}.to_json
end
end
# EXERCISE:
# Implement NetworkDriver API
# For debugging only.
not_found do
p params
p request
end
end
end
end