dockerapi 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a32e488d06a0afd653bb04ab0ad5131fa8e898973128d7a6661f3d3fa4eae53d
4
- data.tar.gz: 641ffcc096f798fbfff057fb1eecc7ce97ad9191c2acf49f5e97c90bf5ceddc5
3
+ metadata.gz: 0dac991f7f237b1df6314bae40e54a5f44175186bbbb6756184c65862bb9f652
4
+ data.tar.gz: 604ea213a309219a91b6923e89e8003eb030fff51d22104e8c689872264ebd59
5
5
  SHA512:
6
- metadata.gz: 6cda72170483e133b467a399d77fbcc7668793726b8f67beb4235c5eaf74e2d91977c9544f93ee7d3f3c4b681004d9415f939d2d521aa70151d3a580fc15fc86
7
- data.tar.gz: d45997041c9d706d2c2d0e2c5e3f5ccaedad51d71cb27ba8538898565e6259e30d7ff11ffa60a5dee9ffca3611ed51ddc96ca68af2a5aff490715b4645297c0d
6
+ metadata.gz: d5f2eb58e059da1f60de416b07902e538ad707ec1a95a4efb665073d3b54a3ab74ea101144f9cea51effd50610ece9e0011061c653d848855885399bcb6b1cdd
7
+ data.tar.gz: 98e253a61bd7c2ff36df30f9e3557d4c502e10e206c7b5a32d2969e9ec996151741a5bda5a46ef32426905236228caaba57485250a7f7561fb98cd2181052b86
@@ -1,3 +1,16 @@
1
+ # 0.13.0
2
+
3
+ Add default behavior for file read, write and output to stdout. Whenever a method can receive a block, this default behavior can be replaced.
4
+
5
+ The following `Docker::API::Image` methods that can now receive a block:
6
+ * export (write file)
7
+ * create (output to stdout)
8
+ * build (output to stdout)
9
+
10
+ Default output to stdout can be supressed by setting `Docker::API::PRINT_TO_STDOUT` to `false`
11
+
12
+ Method parameters `params` and `body` will be automatically evaluated whenever they are present in the method's signature.
13
+
1
14
  # 0.12.0
2
15
 
3
16
  Add `Docker::API::Plugin` methods:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerapi (0.12.0)
4
+ dockerapi (0.13.0)
5
5
  excon (~> 0.74.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -75,13 +75,16 @@ image.prune(filters: {dangling: {"false": true}})
75
75
  image.commit(container: container, repo: "my/image", tag: "latest", comment: "Comment from commit", author: "dockerapi", pause: false )
76
76
 
77
77
  # Build image from a local tar file
78
- image.build("/path/to/file.tar")
78
+ image.build("/path/to/file.tar", {t: "tag"})
79
+
80
+ # Build image using private repository
81
+ image.build("/path/to/file.tar", {t: "tag"}, {"https://index.docker.io/v1/" => {username: "janedoe", password: "janedoe"}})
79
82
 
80
83
  # Build image from a remote tar file
81
- image.build(nil, remote: "https://url.to/file.tar")
84
+ image.build(nil, {remote: "https://url.to/file.tar", t: "tag"})
82
85
 
83
86
  # Build image from a remote Dockerfile
84
- image.build(nil, remote: "https://url.to/Dockerfile")
87
+ image.build(nil, {remote: "https://url.to/Dockerfile", t: "tag"})
85
88
 
86
89
  # Delete builder cache
87
90
  image.delete_cache
@@ -506,7 +509,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
506
509
 
507
510
  | Class | Tests | Implementation | Refactoring |
508
511
  |---|---|---|---|
509
- | Image | Ok | Ok | 8/7 |
512
+ | Image | Ok | Ok | Ok |
510
513
  | Container | Ok | Ok | 8/14 |
511
514
  | Volume | Ok | Ok | 8/21 |
512
515
  | Network | Ok | Ok | 8/21 |
@@ -519,7 +522,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
519
522
  | Secret | Ok | Ok | 9/4 |
520
523
  | Config | Ok | Ok | 9/4 |
521
524
  | Distribution | Ok | Ok | 9/4 |
522
- | Plugin | Ok | 7/24 | 9/4 |
525
+ | Plugin | Ok | Ok | 9/4 |
526
+
527
+ Add doc in these files: `base`, `connection`, `error`, `response`, `dockerapi`
523
528
 
524
529
  ## Contributing
525
530
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
21
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|resources)/}) }
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|resources)/}) }.append("doc")
23
23
  end
24
24
  spec.bindir = "exe"
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -1,38 +1,66 @@
1
- module Docker
2
- module API
3
- class Base
1
+ class Docker::API::Base
2
+
4
3
 
5
- def initialize connection = nil
6
- raise Docker::API::Error.new("Expect connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection)
7
- @connection = connection || Docker::API::Connection.new
8
- end
9
-
10
- private
4
+ def initialize connection = nil
5
+ raise Docker::API::Error.new("Expected connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection)
6
+ @connection = connection || Docker::API::Connection.new
7
+
8
+ (self.methods - Object.methods).each do |method|
9
+ params_index = method(method).parameters.map{|ar| ar[1]}.index(:params)
10
+ body_index = method(method).parameters.map{|ar| ar[1]}.index(:body)
11
11
 
12
- def base_path # TODO: this method to be removed?
13
- "/"
12
+ define_singleton_method(method) do |*args, &block|
13
+ validate Docker::API::InvalidParameter, Docker::API::VALID_PARAMS["#{self.class.name}"]["#{method}"], (args[params_index] || {}) if params_index
14
+ validate Docker::API::InvalidRequestBody, Docker::API::VALID_BODY["#{self.class.name}"]["#{method}"], (args[body_index] || {}) if body_index
15
+ super(*args,&block)
14
16
  end
17
+ end
18
+ end
19
+
20
+ private
15
21
 
16
- def validate error, permitted, params
17
- return if params[:skip_validation]
18
- unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s)
19
- raise error.new(permitted, unpermitted) if unpermitted.size > 0
20
- end
22
+ def default_streamer
23
+ streamer = lambda do |chunk, remaining_bytes, total_bytes|
24
+ p chunk.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') if Docker::API::PRINT_TO_STDOUT
25
+ end
26
+ streamer
27
+ end
21
28
 
22
- ## Converts Ruby Hash into query parameters
23
- ## In general, the format is key=value
24
- ## If value is another Hash, it should keep a json syntax {key:value}
25
- def hash_to_params h
26
- p = []
27
- h.delete_if{ | k, v | k.to_s == "skip_validation" }.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
28
- p.join("&").gsub(" ","")
29
- end
29
+ def default_writer path
30
+ streamer = lambda do |chunk, remaining_bytes, total_bytes|
31
+ return if "#{chunk}".match(/(No such image)/)
32
+ file = File.open(File.expand_path(path), "wb+")
33
+ file.write(chunk)
34
+ file.close
35
+ end
36
+ streamer
37
+ end
30
38
 
31
- def build_path path, params = {}
32
- p = path.is_a?(Array) ? ([base_path] << path).join("/") : path # TODO: this line to be removed?
33
- params.size > 0 ? [p, hash_to_params(params)].join("?") : p
34
- end
39
+ def default_reader path, url, header = {"Content-Type" => "application/x-tar"}, &block
40
+ file = File.open(File.expand_path(path), "r")
41
+ response = @connection.request(method: :post, path: url , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block.call : default_streamer )
42
+ file.close
43
+ response
44
+ end
35
45
 
36
- end
46
+ def validate error, permitted, params
47
+ return if params[:skip_validation]
48
+ unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s)
49
+ raise error.new(permitted, unpermitted) if unpermitted.size > 0
50
+ end
51
+
52
+ ## Converts Ruby Hash into query parameters
53
+ ## In general, the format is key=value
54
+ ## If value is another Hash, it should keep a json syntax {key:value}
55
+ def hash_to_params h
56
+ p = []
57
+ h.delete_if{ | k, v | k.to_s == "skip_validation" }.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
58
+ p.join("&").gsub(" ","")
59
+ end
60
+
61
+ def build_path path, params = {}
62
+ p = path.is_a?(Array) ? ([base_path] << path).join("/") : path # TODO: this line to be removed?
63
+ params.size > 0 ? [p, hash_to_params(params)].join("?") : p
37
64
  end
65
+
38
66
  end
@@ -13,7 +13,6 @@ class Docker::API::Config < Docker::API::Base
13
13
  #
14
14
  # @param params [Hash]: Parameters that are appended to the URL.
15
15
  def list params = {}
16
- validate Docker::API::InvalidParameter, [:filters], params
17
16
  @connection.get(build_path("/configs",params))
18
17
  end
19
18
 
@@ -25,7 +24,6 @@ class Docker::API::Config < Docker::API::Base
25
24
  #
26
25
  # @param body [Hash]: Request body to be sent as json.
27
26
  def create body = {}
28
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Templating], body
29
27
  @connection.request(method: :post, path: "/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
30
28
  end
31
29
 
@@ -52,8 +50,6 @@ class Docker::API::Config < Docker::API::Base
52
50
  #
53
51
  # @param body [Hash]: Request body to be sent as json.
54
52
  def update name, params = {}, body = {}
55
- validate Docker::API::InvalidParameter, [:version], params
56
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
57
53
  @connection.request(method: :post, path: build_path("/configs/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
58
54
  end
59
55
 
@@ -1,22 +1,16 @@
1
1
  module Docker
2
2
  module API
3
- CreateBody = [:Hostname,:Domainname,:User,:AttachStdin,:AttachStdout,:AttachStderr,:ExposedPorts,:Tty,:OpenStdin,:StdinOnce,:Env,:Cmd,:HealthCheck,:ArgsEscaped,:Image,:Volumes,:WorkingDir,:Entrypoint,:NetworkDisabled,:MacAddress,:OnBuild,:Labels,:StopSignal,:StopTimeout,:Shell,:HostConfig,:NetworkingConfig]
4
- UpdateBody = [:CpuShares, :Memory, :CgroupParent, :BlkioWeight, :BlkioWeightDevice, :BlkioWeightReadBps, :BlkioWeightWriteBps, :BlkioWeightReadOps, :BlkioWeightWriteOps, :CpuPeriod, :CpuQuota, :CpuRealtimePeriod, :CpuRealtimeRuntime, :CpusetCpus, :CpusetMems, :Devices, :DeviceCgroupRules, :DeviceRequest, :Kernel, :Memory, :KernelMemoryTCP, :MemoryReservation, :MemorySwap, :MemorySwappiness, :NanoCPUs, :OomKillDisable, :Init, :PidsLimit, :ULimits, :CpuCount, :CpuPercent, :IOMaximumIOps, :IOMaximumBandwidth, :RestartPolicy]
5
-
6
3
  class Container < Docker::API::Base
7
4
 
8
5
  def list params = {}
9
- validate Docker::API::InvalidParameter, [:all, :limit, :size, :filters], params
10
6
  @connection.get(build_path(["json"], params))
11
7
  end
12
8
 
13
9
  def details name, params = {}
14
- validate Docker::API::InvalidParameter, [:size], params
15
10
  @connection.get(build_path([name, "json"], params))
16
11
  end
17
12
 
18
13
  def top name, params = {}
19
- validate Docker::API::InvalidParameter, [:ps_args], params
20
14
  @connection.get(build_path([name, "top"], params))
21
15
  end
22
16
 
@@ -25,47 +19,38 @@ module Docker
25
19
  end
26
20
 
27
21
  def start name, params = {}
28
- validate Docker::API::InvalidParameter, [:detachKeys], params
29
22
  @connection.post(build_path([name, "start"], params))
30
23
  end
31
24
 
32
25
  def stop name, params = {}
33
- validate Docker::API::InvalidParameter, [:t], params
34
26
  @connection.post(build_path([name, "stop"], params))
35
27
  end
36
28
 
37
29
  def restart name, params = {}
38
- validate Docker::API::InvalidParameter, [:t], params
39
30
  @connection.post(build_path([name, "restart"], params))
40
31
  end
41
32
 
42
33
  def kill name, params = {}
43
- validate Docker::API::InvalidParameter, [:signal], params
44
34
  @connection.post(build_path([name, "kill"], params))
45
35
  end
46
36
 
47
37
  def wait name, params = {}
48
- validate Docker::API::InvalidParameter, [:condition], params
49
38
  @connection.post(build_path([name, "wait"], params))
50
39
  end
51
40
 
52
41
  def update name, body = {}
53
- validate Docker::API::InvalidRequestBody, Docker::API::UpdateBody, body
54
42
  @connection.request(method: :post, path: build_path([name, "update"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
55
43
  end
56
44
 
57
45
  def rename name, params = {}
58
- validate Docker::API::InvalidParameter, [:name], params
59
46
  @connection.post(build_path([name, "rename"], params))
60
47
  end
61
48
 
62
49
  def resize name, params = {}
63
- validate Docker::API::InvalidParameter, [:w, :h], params
64
50
  @connection.post(build_path([name, "resize"], params))
65
51
  end
66
52
 
67
53
  def prune params = {}
68
- validate Docker::API::InvalidParameter, [:filters], params
69
54
  @connection.post(build_path(["prune"], params))
70
55
  end
71
56
 
@@ -78,12 +63,10 @@ module Docker
78
63
  end
79
64
 
80
65
  def remove name, params = {}
81
- validate Docker::API::InvalidParameter, [:v, :force, :link], params
82
66
  @connection.delete(build_path([name]))
83
67
  end
84
68
 
85
69
  def logs name, params = {}
86
- validate Docker::API::InvalidParameter, [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail], params
87
70
 
88
71
  path = build_path([name, "logs"], params)
89
72
 
@@ -95,18 +78,14 @@ module Docker
95
78
  end
96
79
 
97
80
  def attach name, params = {}
98
- validate Docker::API::InvalidParameter, [:detachKeys, :logs, :stream, :stdin, :stdout, :stderr], params
99
81
  @connection.request(method: :post, path: build_path([name, "attach"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
100
82
  end
101
83
 
102
84
  def create params = {}, body = {}
103
- validate Docker::API::InvalidParameter, [:name], params
104
- validate Docker::API::InvalidRequestBody, Docker::API::CreateBody, body
105
85
  @connection.request(method: :post, path: build_path(["create"], params), headers: {"Content-Type": "application/json"}, body: body.to_json)
106
86
  end
107
87
 
108
88
  def stats name, params = {}
109
- validate Docker::API::InvalidParameter, [:stream], params
110
89
  path = build_path([name, "stats"], params)
111
90
 
112
91
  if params[:stream] == true || params[:stream] == 1
@@ -133,7 +112,6 @@ module Docker
133
112
  end
134
113
 
135
114
  def archive name, file, params = {}
136
- validate Docker::API::InvalidParameter, [:path, :noOverwriteDirNonDir, :copyUIDGID], params
137
115
 
138
116
  begin # File exists on disk, send it to container
139
117
  file = File.open( File.expand_path( file ) , "r")
@@ -3,13 +3,10 @@ module Docker
3
3
  class Exec < Docker::API::Base
4
4
 
5
5
  def create name, body = {}
6
- validate Docker::API::InvalidRequestBody, [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir], body
7
6
  @connection.request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
8
7
  end
9
8
 
10
9
  def start name, body = {}
11
- validate Docker::API::InvalidRequestBody, [:Detach, :Tty], body
12
-
13
10
  stream = ""
14
11
  response = @connection.request(method: :post,
15
12
  path: "/exec/#{name}/start",
@@ -22,7 +19,6 @@ module Docker
22
19
  end
23
20
 
24
21
  def resize name, params = {}
25
- validate Docker::API::InvalidParameter, [:w, :h], params
26
22
  @connection.post(build_path("/exec/#{name}/resize", params))
27
23
  end
28
24
 
@@ -1,152 +1,190 @@
1
- require "base64"
2
- require "json"
3
- require 'fileutils'
4
- module Docker
5
- module API
6
- CommitBody = [:Hostname, :Domainname, :User, :AttachStdin, :AttachStdout, :AttachStderr, :ExposedPorts, :Tty, :OpenStdin, :StdinOnce, :Env, :Cmd, :HealthCheck, :ArgsEscaped, :Image, :Volumes, :WorkingDir, :Entrypoint, :NetworkDisabled, :MacAddress, :OnBuild, :Labels, :StopSignal, :StopTimeout, :Shell]
7
- BuildParams = [:dockerfile, :t, :extrahosts, :remote, :q, :nocache, :cachefrom, :pull, :rm, :forcerm, :memory, :memswap, :cpushares, :cpusetcpus, :cpuperiod, :cpuquota, :buildargs, :shmsize, :squash, :labels, :networkmode, :platform, :target, :outputs]
8
- class Image < Docker::API::Base
9
-
10
- def details name
11
- @connection.get(build_path([name, "json"]))
12
- end
13
-
14
- def distribution name
15
- @connection.get("/distribution/#{name}/json")
16
- end
17
-
18
- def history name
19
- @connection.get(build_path([name, "history"]))
20
- end
21
-
22
- def list params = {}
23
- validate Docker::API::InvalidParameter, [:all, :filters, :digests], params
24
- @connection.get(build_path(["json"], params))
25
- end
26
-
27
- def search params = {}
28
- validate Docker::API::InvalidParameter, [:term, :limit, :filters], params
29
- @connection.get(build_path(["search"], params))
30
- end
31
-
32
- def tag name, params = {}
33
- validate Docker::API::InvalidParameter, [:repo, :tag], params
34
- @connection.post(build_path([name, "tag"], params))
35
- end
36
-
37
- def prune params = {}
38
- validate Docker::API::InvalidParameter, [:filters], params
39
- @connection.post(build_path(["prune"], params))
40
- end
41
-
42
- def remove name, params = {}
43
- validate Docker::API::InvalidParameter, [:force, :noprune], params
44
- @connection.delete(build_path([name], params))
45
- end
46
-
47
- def export name, path = "exported_image"
48
- file = File.open("/tmp/exported-image", "wb")
49
- streamer = lambda do |chunk, remaining_bytes, total_bytes|
50
- file.write(chunk)
51
- end
52
- response = @connection.request(method: :get, path: build_path([name, "get"]) , response_block: streamer)
53
- file.close
54
- response.status == 200 ? FileUtils.mv("/tmp/exported-image", File.expand_path(path)) : FileUtils.rm("/tmp/exported-image")
55
- response
56
- end
57
-
58
- def import path, params = {}
59
- validate Docker::API::InvalidParameter, [:quiet], params
60
- file = File.open(File.expand_path(path), "r")
61
- response = @connection.request(method: :post, path: build_path(["load"], params) , headers: {"Content-Type" => "application/x-tar"}, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
62
- file.close
63
- response
64
- end
65
-
66
- def push name, params = {}, authentication = {}
67
- validate Docker::API::InvalidParameter, [:tag], params
68
-
69
- if authentication.keys.size > 0
70
- @connection.request(method: :post, path: build_path([name, "push"], params), headers: { "X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s).chomp } )
71
- else
72
- raise Docker::API::Error.new("Provide authentication parameters to push an image")
73
- end
74
- end
75
-
76
- def commit params = {}, body = {}
77
- validate Docker::API::InvalidParameter, [:container, :repo, :tag, :comment, :author, :pause, :changes], params
78
- validate Docker::API::InvalidRequestBody, Docker::API::CommitBody, body
79
- container = Docker::API::Container.new.details(params[:container])
80
- return container if [404, 301].include? container.status
81
- body = JSON.parse(container.body)["Config"].merge(body)
82
- @connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
83
- end
84
-
85
- def create params = {}, authentication = {}
86
- validate Docker::API::InvalidParameter, [:fromImage, :fromSrc, :repo, :tag, :message, :platform], params
87
-
88
- if authentication.keys.size > 0
89
- auth = Docker::API::System.new.auth(authentication)
90
- return auth unless [200, 204].include? auth.status
91
- @connection.request(method: :post, path: build_path(["create"], params), headers: { "X-Registry-Auth" => Base64.encode64(authentication.to_json.to_s).chomp } )
92
- elsif params.has_key? :fromSrc
93
- if params[:fromSrc].match(/^(http|https)/)
94
- @connection.request(method: :post, path: build_path(["create"], params))
95
- else
96
- file = File.open(File.expand_path(params[:fromSrc]), "r")
97
- params[:fromSrc] = "-"
98
- response = @connection.request(method: :post, path: build_path(["create"], params) , headers: {"Content-Type" => "application/x-tar"}, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
99
- file.close
100
- response
101
- end
102
- else
103
- @connection.post(build_path(["create"], params))
104
- end
105
- end
106
-
107
- def build path, params = {}, authentication = {}
108
- raise Docker::API::Error.new("Expected path or params[:remote]") unless path || params[:remote]
109
- validate Docker::API::InvalidParameter, Docker::API::BuildParams, params
110
-
111
- header = {"Content-type": "application/x-tar"}
112
- if authentication.keys.size > 0
113
- authentication.each_key do |server|
114
- auth = Docker::API::System.new.auth({username: authentication[server][:username] ,password:authentication[server][:password], serveraddress: server})
115
- return auth unless [200, 204].include? auth.status
116
- end
117
- header.merge!({"X-Registry-Config": Base64.urlsafe_encode64(authentication.to_json.to_s).chomp})
118
- end
119
-
120
- begin
121
- file = File.open( File.expand_path( path ) , "r")
122
- response = @connection.request(method: :post, path: build_path("/build", params), headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s})
123
- file.close
124
- rescue
125
- response = @connection.request(method: :post, path: build_path("/build", params), headers: header)
126
- end
127
- response
128
- end
129
-
130
- def delete_cache params = {}
131
- validate Docker::API::InvalidParameter, [:all, "keep-storage", :filters], params
132
- @connection.post(build_path("/build/prune", params))
133
- end
134
-
135
- #################################################
136
- # Items in this area to be removed before 1.0.0 #
137
- #################################################
138
- def base_path
139
- "/images"
140
- end
141
-
142
- def inspect *args
143
- return super.inspect if args.size == 0
144
- warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
145
- name = args[0]
146
- details(name)
147
- end
148
- #################################################
1
+ ##
2
+ # This class represents the Docker API endpoints regarding images.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Image
4
+ class Docker::API::Image < Docker::API::Base
5
+
6
+ ##
7
+ # Return low-level information about an image.
8
+ # Docker API: GET /images/{name}/json
9
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageInspect
10
+ #
11
+ # @param name [String]: The ID or name of the image.
12
+ def details name
13
+ @connection.get("/images/#{name}/json")
14
+ end
15
+
16
+ ##
17
+ # Return image digest and platform information by contacting the registry.
18
+ # Docker API: GET /distribution/{name}/json
19
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Distribution
20
+ #
21
+ # @param name [String]: The ID or name of the image.
22
+ def distribution name
23
+ @connection.get("/distribution/#{name}/json")
24
+ end
25
+
26
+ ##
27
+ # Return parent layers of an image.
28
+ # Docker API: GET /images/{name}/history
29
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageHistory
30
+ #
31
+ # @param name [String]: The ID or name of the image.
32
+ def history name
33
+ @connection.get("/images/#{name}/history")
34
+ end
35
+
36
+ ##
37
+ # Returns a list of images on the server. Note that it uses a different, smaller representation of an image than inspecting a single image.
38
+ # Docker API: GET /images/json
39
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageList
40
+ #
41
+ # @param params [Hash]: Parameters that are appended to the URL.
42
+ def list params = {}
43
+ @connection.get(build_path("/images/json", params))
44
+ end
45
+
46
+ ##
47
+ # Search for an image on Docker Hub.
48
+ # Docker API: GET /images/search
49
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageSearch
50
+ #
51
+ # @param params [Hash]: Parameters that are appended to the URL.
52
+ def search params = {}
53
+ @connection.get(build_path("/images/search", params))
54
+ end
55
+
56
+ ##
57
+ # Tag an image so that it becomes part of a repository.
58
+ # Docker API: POST /images/{name}/tag
59
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageTag
60
+ #
61
+ # @param name [String]: The ID or name of the image.
62
+ # @param params [Hash]: Parameters that are appended to the URL.
63
+ def tag name, params = {}
64
+ @connection.post(build_path("/images/#{name}/tag", params))
65
+ end
66
+
67
+ ##
68
+ # Delete unused images.
69
+ # Docker API: POST /images/prune
70
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImagePrune
71
+ #
72
+ # @param params [Hash]: Parameters that are appended to the URL.
73
+ def prune params = {}
74
+ @connection.post(build_path("/images/prune", params))
75
+ end
76
+
77
+ ##
78
+ # Remove an image, along with any untagged parent images that were referenced by that image.
79
+ # Images can't be removed if they have descendant images, are being used by a running container or are being used by a build.
80
+ # Docker API: DELETE /images/{name}
81
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageDelete
82
+ #
83
+ # @param name [String]: The ID or name of the image.
84
+ # @param params [Hash]: Parameters that are appended to the URL.
85
+ def remove name, params = {}
86
+ @connection.delete(build_path("/images/#{name}", params))
87
+ end
88
+
89
+ ##
90
+ # Export an image.
91
+ # Docker API: GET /images/{name}/get
92
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageGet
93
+ #
94
+ # @param name [String]: The ID or name of the image.
95
+ # @param path [Hash]: Parameters that are appended to the URL.
96
+ # @param block [Hash]: Request body to be sent as json.
97
+ # @block: Replace the default file writing method.
98
+ def export name, path = "exported_image", &block
99
+ @connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block.call : default_writer(path))
100
+ end
101
+
102
+ ##
103
+ # Import images.
104
+ # Docker API: POST /images/load
105
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageLoad
106
+ #
107
+ # @param name [String]: The ID or name of the image.
108
+ # @param params [Hash]: Parameters that are appended to the URL.
109
+ def import path, params = {}
110
+ default_reader(path, build_path("/images/load", params))
111
+ end
112
+
113
+ ##
114
+ # Push an image to a registry.
115
+ # Docker API: POST /images/{name}/push
116
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImagePush
117
+ #
118
+ # @param name [String]: The ID or name of the image.
119
+ # @param params [Hash]: Parameters that are appended to the URL.
120
+ # @param authentication [Hash]: Authentication parameters.
121
+ def push name, params = {}, authentication = {}
122
+ raise Docker::API::Error.new("Provide authentication parameters to push an image") unless authentication.keys.size > 0
123
+ @connection.request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s).chomp } )
124
+ end
149
125
 
126
+ ##
127
+ # Create a new image from a container.
128
+ # Docker API: POST /commit
129
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageCommit
130
+ #
131
+ # @param params [Hash]: Parameters that are appended to the URL.
132
+ # @param body [Hash]: Request body to be sent as json.
133
+ def commit params = {}, body = {}
134
+ container = Docker::API::Container.new.details(params[:container])
135
+ return container if [404, 301].include? container.status
136
+ @connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json)
137
+ end
138
+
139
+ ##
140
+ # Create an image by either pulling it from a registry or importing it.
141
+ # Docker API: POST /images/create
142
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageCreate
143
+ #
144
+ # @param params [Hash]: Parameters that are appended to the URL.
145
+ # @param authentication [Hash]: Authentication parameters.
146
+ # @param &block: Replace the default output to stdout behavior.
147
+ def create params = {}, authentication = {}, &block
148
+ request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block.call : default_streamer }
149
+ if params.has_key? :fromSrc and !params[:fromSrc].match(/^(http|https)/) # then it's using a tar file
150
+ path = params[:fromSrc]
151
+ params[:fromSrc] = "-"
152
+ default_reader(path, build_path("/images/create", params))
153
+ else
154
+ request[:headers] = { "X-Registry-Auth" => Base64.encode64(authentication.to_json.to_s).chomp } if authentication.keys.size > 0
155
+ @connection.request(request)
150
156
  end
151
157
  end
158
+
159
+ ##
160
+ # Build an image from a tar archive with a Dockerfile in it.
161
+ # Docker API: POST /build
162
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageBuild
163
+ #
164
+ # @param path [String]: Path to the tar file.
165
+ # @param params [Hash]: Parameters that are appended to the URL.
166
+ # @param authentication [Hash]: Authentication parameters.
167
+ # @param &block: Replace the default output to stdout behavior.
168
+ def build path, params = {}, authentication = {}, &block
169
+ raise Docker::API::Error.new("Expected path or params[:remote]") unless path || params[:remote]
170
+
171
+ headers = {"Content-type": "application/x-tar"}
172
+ headers.merge!({"X-Registry-Config": Base64.urlsafe_encode64(authentication.to_json.to_s).chomp}) if authentication.keys.size > 0
173
+
174
+ if path == nil and params.has_key? :remote
175
+ response = @connection.request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block.call : default_streamer)
176
+ else
177
+ default_reader(path, build_path("/build", params), headers)
178
+ end
179
+ end
180
+
181
+ ##
182
+ # Delete builder cache.
183
+ # Docker API: POST /build/prune
184
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/BuildPrune
185
+ #
186
+ # @param params [Hash]: Parameters that are appended to the URL.
187
+ def delete_cache params = {}
188
+ @connection.post(build_path("/build/prune", params))
189
+ end
152
190
  end
@@ -3,17 +3,14 @@ module Docker
3
3
  class Network < Docker::API::Base
4
4
 
5
5
  def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
6
  @connection.get(build_path("/networks", params))
8
7
  end
9
8
 
10
9
  def details name, params = {}
11
- validate Docker::API::InvalidParameter, [:verbose, :scope], params
12
10
  @connection.get(build_path([name], params))
13
11
  end
14
12
 
15
13
  def create body = {}
16
- validate Docker::API::InvalidRequestBody, [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels], body
17
14
  @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
18
15
  end
19
16
 
@@ -22,17 +19,14 @@ module Docker
22
19
  end
23
20
 
24
21
  def prune params = {}
25
- validate Docker::API::InvalidParameter, [:filters], params
26
22
  @connection.post(build_path(["prune"], params))
27
23
  end
28
24
 
29
25
  def connect name, body = {}
30
- validate Docker::API::InvalidRequestBody, [:Container, :EndpointConfig], body
31
26
  @connection.request(method: :post, path: build_path([name, "connect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
32
27
  end
33
28
 
34
29
  def disconnect name, body = {}
35
- validate Docker::API::InvalidRequestBody, [:Container, :Force], body
36
30
  @connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
37
31
  end
38
32
 
@@ -3,18 +3,14 @@ module Docker
3
3
  class Node < Docker::API::Base
4
4
 
5
5
  def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
6
  @connection.get(build_path("/nodes", params))
8
7
  end
9
8
 
10
9
  def update name, params = {}, body = {}
11
- validate Docker::API::InvalidParameter, [:version], params
12
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Role, :Availability], body
13
10
  @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
11
  end
15
12
 
16
13
  def delete name, params = {}
17
- validate Docker::API::InvalidParameter, [:force], params
18
14
  @connection.delete(build_path("/nodes/#{name}", params))
19
15
  end
20
16
 
@@ -11,7 +11,6 @@ class Docker::API::Plugin < Docker::API::Base
11
11
  #
12
12
  # @param params [Hash]: Parameters that are appended to the URL.
13
13
  def list params = {}
14
- validate Docker::API::InvalidParameter, [:filters], params
15
14
  @connection.get(build_path("/plugins", params))
16
15
  end
17
16
 
@@ -23,7 +22,6 @@ class Docker::API::Plugin < Docker::API::Base
23
22
  #
24
23
  # @param params [Hash]: Parameters that are appended to the URL.
25
24
  def privileges params = {}
26
- validate Docker::API::InvalidParameter, [:remote], params
27
25
  @connection.get(build_path("/plugins/privileges", params))
28
26
  end
29
27
 
@@ -41,7 +39,6 @@ class Docker::API::Plugin < Docker::API::Base
41
39
  #
42
40
  # @param authentication [Hash]: Authentication parameters.
43
41
  def install params = {}, privileges = [], authentication = {}
44
- validate Docker::API::InvalidParameter, [:remote, :name], params
45
42
  headers = {"Content-Type": "application/json"}
46
43
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
47
44
  @connection.request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json )
@@ -68,7 +65,6 @@ class Docker::API::Plugin < Docker::API::Base
68
65
  #
69
66
  # @param params [Hash]: Parameters that are appended to the URL.
70
67
  def remove name, params = {}
71
- validate Docker::API::InvalidParameter, [:force], params
72
68
  @connection.delete(build_path("/plugins/#{name}",params))
73
69
  end
74
70
 
@@ -82,7 +78,6 @@ class Docker::API::Plugin < Docker::API::Base
82
78
  #
83
79
  # @param params [Hash]: Parameters that are appended to the URL.
84
80
  def enable name, params = {}
85
- validate Docker::API::InvalidParameter, [:timeout], params
86
81
  @connection.post(build_path("/plugins/#{name}/enable", params))
87
82
  end
88
83
 
@@ -111,7 +106,6 @@ class Docker::API::Plugin < Docker::API::Base
111
106
  #
112
107
  # @param authentication [Hash]: Authentication parameters.
113
108
  def upgrade name, params = {}, privileges = [], authentication = {}
114
- validate Docker::API::InvalidParameter, [:remote], params
115
109
  headers = {"Content-Type": "application/json"}
116
110
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
117
111
  @connection.request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json )
@@ -13,7 +13,6 @@ class Docker::API::Secret < Docker::API::Base
13
13
  #
14
14
  # @param params [Hash]: Parameters that are appended to the URL.
15
15
  def list params = {}
16
- validate Docker::API::InvalidParameter, [:filters], params
17
16
  @connection.get(build_path("/secrets",params))
18
17
  end
19
18
 
@@ -25,7 +24,6 @@ class Docker::API::Secret < Docker::API::Base
25
24
  #
26
25
  # @param body [Hash]: Request body to be sent as json.
27
26
  def create body = {}
28
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
29
27
  @connection.request(method: :post, path: "/secrets/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
30
28
  end
31
29
 
@@ -52,8 +50,6 @@ class Docker::API::Secret < Docker::API::Base
52
50
  #
53
51
  # @param body [Hash]: Request body to be sent as json.
54
52
  def update name, params = {}, body = {}
55
- validate Docker::API::InvalidParameter, [:version], params
56
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
57
53
  @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
58
54
  end
59
55
 
@@ -13,7 +13,6 @@ class Docker::API::Service < Docker::API::Base
13
13
  #
14
14
  # @param params [Hash]: Parameters that are appended to the URL.
15
15
  def list params = {}
16
- validate Docker::API::InvalidParameter, [:filters], params
17
16
  @connection.get(build_path("/services", params))
18
17
  end
19
18
 
@@ -27,7 +26,6 @@ class Docker::API::Service < Docker::API::Base
27
26
  #
28
27
  # @param authentication [Hash]: Authentication parameters.
29
28
  def create body = {}, authentication = {}
30
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
31
29
  headers = {"Content-Type": "application/json"}
32
30
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
33
31
  @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
@@ -48,8 +46,6 @@ class Docker::API::Service < Docker::API::Base
48
46
  # @param authentication [Hash]: Authentication parameters.
49
47
  def update name, params = {}, body = {}, authentication = {}
50
48
  # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
51
- validate Docker::API::InvalidParameter, [:version, :registryAuthFrom, :rollback], params
52
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
53
49
  headers = {"Content-Type": "application/json"}
54
50
  headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
55
51
  @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
@@ -65,7 +61,6 @@ class Docker::API::Service < Docker::API::Base
65
61
  #
66
62
  # @param params [Hash]: Parameters that are appended to the URL.
67
63
  def details name, params = {}
68
- validate Docker::API::InvalidParameter, [:insertDefaults], params
69
64
  @connection.get(build_path("/services/#{name}", params))
70
65
  end
71
66
 
@@ -81,7 +76,6 @@ class Docker::API::Service < Docker::API::Base
81
76
  #
82
77
  # @param params [Hash]: Parameters that are appended to the URL.
83
78
  def logs name, params = {}
84
- validate Docker::API::InvalidParameter, [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail], params
85
79
  @connection.get(build_path("/services/#{name}/logs", params))
86
80
  end
87
81
 
@@ -3,13 +3,10 @@ module Docker
3
3
  class Swarm < Docker::API::Base
4
4
 
5
5
  def init body = {}
6
- validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec], body
7
6
  @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
8
7
  end
9
8
 
10
9
  def update params = {}, body = {}
11
- validate Docker::API::InvalidParameter, [:version, :rotateWorkerToken, :rotateManagerToken, :rotateManagerUnlockKey], params
12
- validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Orchestration, :Raft, :Dispatcher, :CAConfig, :EncryptionConfig, :TaskDefaults], body
13
10
  @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
11
  end
15
12
 
@@ -22,17 +19,14 @@ module Docker
22
19
  end
23
20
 
24
21
  def unlock body = {}
25
- validate Docker::API::InvalidRequestBody, [:UnlockKey], body
26
22
  @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type": "application/json"}, body: body.to_json)
27
23
  end
28
24
 
29
25
  def join body = {}
30
- validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken], body
31
26
  @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type": "application/json"}, body: body.to_json)
32
27
  end
33
28
 
34
29
  def leave params = {}
35
- validate Docker::API::InvalidParameter, [:force], params
36
30
  @connection.post(build_path("/swarm/leave", params))
37
31
  end
38
32
 
@@ -4,12 +4,10 @@ module Docker
4
4
  class System < Docker::API::Base
5
5
 
6
6
  def auth body = {}
7
- validate Docker::API::InvalidRequestBody, [:username, :password, :email, :serveraddress, :identitytoken], body
8
7
  @connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
9
8
  end
10
9
 
11
10
  def events params = {}
12
- validate Docker::API::InvalidParameter, [:since, :until, :filters], params
13
11
  @connection.request(method: :get, path: build_path("/events", params), response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect } )
14
12
  end
15
13
 
@@ -13,7 +13,6 @@ class Docker::API::Task < Docker::API::Base
13
13
  #
14
14
  # @param params [Hash]: Parameters that are appended to the URL.
15
15
  def list params = {}
16
- validate Docker::API::InvalidParameter, [:filters], params
17
16
  @connection.get(build_path("/tasks",params))
18
17
  end
19
18
 
@@ -40,7 +39,6 @@ class Docker::API::Task < Docker::API::Base
40
39
  #
41
40
  # @param params (Hash) : Parameters that are appended to the URL.
42
41
  def logs name, params = {}
43
- validate Docker::API::InvalidParameter, [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail], params
44
42
  @connection.get(build_path("/tasks/#{name}/logs", params))
45
43
  end
46
44
  end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.12.0"
3
+ GEM_VERSION = "0.13.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
@@ -3,7 +3,6 @@ module Docker
3
3
  class Volume < Docker::API::Base
4
4
 
5
5
  def list params = {}
6
- validate Docker::API::InvalidParameter, [:filters], params
7
6
  @connection.get(build_path("/volumes", params))
8
7
  end
9
8
 
@@ -12,17 +11,14 @@ module Docker
12
11
  end
13
12
 
14
13
  def create body = {}
15
- validate Docker::API::InvalidRequestBody, [:Name, :Driver, :DriverOpts, :Labels], body
16
14
  @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
17
15
  end
18
16
 
19
17
  def remove name, params = {}
20
- validate Docker::API::InvalidParameter, [:force], params
21
18
  @connection.delete(build_path([name]))
22
19
  end
23
20
 
24
21
  def prune params = {}
25
- validate Docker::API::InvalidParameter, [:filters], params
26
22
  @connection.post(build_path(["prune"], params))
27
23
  end
28
24
 
@@ -1,5 +1,7 @@
1
1
  require "excon"
2
2
  require "json"
3
+ require "base64"
4
+ require "fileutils"
3
5
 
4
6
  require "docker/api/version"
5
7
  require "docker/api/error"
@@ -22,6 +24,140 @@ require "docker/api/plugin"
22
24
 
23
25
  module Docker
24
26
  module API
27
+
28
+ PRINT_TO_STDOUT = true
29
+
30
+ VALID_PARAMS = {
31
+ "Docker::API::Image" => {
32
+ "build" => [:dockerfile, :t, :extrahosts, :remote, :q, :nocache, :cachefrom, :pull, :rm, :forcerm, :memory, :memswap, :cpushares, :cpusetcpus, :cpuperiod, :cpuquota, :buildargs, :shmsize, :squash, :labels, :networkmode, :platform, :target, :outputs],
33
+ "prune" => [:filters],
34
+ "list" => [:all, :filters, :digests],
35
+ "search" => [:term, :limit, :filters],
36
+ "tag" => [:repo, :tag],
37
+ "remove" => [:force, :noprune],
38
+ "import" => [:quiet],
39
+ "push" => [:tag],
40
+ "commit" => [:container, :repo, :tag, :comment, :author, :pause, :changes],
41
+ "create" => [:fromImage, :fromSrc, :repo, :tag, :message, :platform],
42
+ "delete_cache" => [:all, "keep-storage", :filters]
43
+ },
44
+ "Docker::API::Container" => {
45
+ "list" => [:all, :limit, :size, :filters],
46
+ "details" => [:size],
47
+ "top" => [:ps_args],
48
+ "start" => [:detachKeys],
49
+ "stop" => [:t],
50
+ "restart" => [:t],
51
+ "kill" => [:signal],
52
+ "wait" => [:condition],
53
+ "rename" => [:name],
54
+ "resize" => [:w, :h],
55
+ "prune" => [:filters],
56
+ "remove" => [:v, :force, :link],
57
+ "logs" => [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail],
58
+ "attach" => [:detachKeys, :logs, :stream, :stdin, :stdout, :stderr],
59
+ "stats" => [:stream],
60
+ "archive" => [:path, :noOverwriteDirNonDir, :copyUIDGID],
61
+ "create" => [:name]
62
+ },
63
+ "Docker::API::Volume" => {
64
+ "list" => [:filters],
65
+ "remove" => [:force],
66
+ "prune" => [:filters]
67
+ },
68
+ "Docker::API::Network" => {
69
+ "list" => [:filters],
70
+ "details" => [:verbose, :scope],
71
+ "prune" => [:filters]
72
+ },
73
+ "Docker::API::System" => {
74
+ "events" => [:since, :until, :filters]
75
+ },
76
+ "Docker::API::Exec" => {
77
+ "resize" => [:w, :h]
78
+ },
79
+ "Docker::API::Swarm" => {
80
+ "leave" => [:force],
81
+ "update" => [:version, :rotateWorkerToken, :rotateManagerToken, :rotateManagerUnlockKey]
82
+ },
83
+ "Docker::API::Node" => {
84
+ "list" => [:filters],
85
+ "update" => [:version],
86
+ "delete" => [:force]
87
+ },
88
+ "Docker::API::Service" => {
89
+ "list" => [:filters],
90
+ "update" => [:version, :registryAuthFrom, :rollback],
91
+ "details" => [:insertDefaults],
92
+ "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail]
93
+ },
94
+ "Docker::API::Secret" => {
95
+ "list" => [:filters],
96
+ "update" => [:version]
97
+ },
98
+ "Docker::API::Task" => {
99
+ "list" => [:filters],
100
+ "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail]
101
+ },
102
+ "Docker::API::Plugin" => {
103
+ "list" => [:filters],
104
+ "privileges" => [:remote],
105
+ "install" => [:remote, :name],
106
+ "remove" => [:force],
107
+ "enable" => [:timeout],
108
+ "upgrade" => [:remote]
109
+ },
110
+ "Docker::API::Config" => {
111
+ "list" => [:filters],
112
+ "update" => [:version]
113
+ }
114
+ }
115
+
116
+ VALID_BODY = {
117
+ "Docker::API::Image" => {
118
+ "commit" => [:Hostname, :Domainname, :User, :AttachStdin, :AttachStdout, :AttachStderr, :ExposedPorts, :Tty, :OpenStdin, :StdinOnce, :Env, :Cmd, :HealthCheck, :ArgsEscaped, :Image, :Volumes, :WorkingDir, :Entrypoint, :NetworkDisabled, :MacAddress, :OnBuild, :Labels, :StopSignal, :StopTimeout, :Shell]
119
+ },
120
+ "Docker::API::Container" => {
121
+ "create" => [:Hostname,:Domainname,:User,:AttachStdin,:AttachStdout,:AttachStderr,:ExposedPorts,:Tty,:OpenStdin,:StdinOnce,:Env,:Cmd,:HealthCheck,:ArgsEscaped,:Image,:Volumes,:WorkingDir,:Entrypoint,:NetworkDisabled,:MacAddress,:OnBuild,:Labels,:StopSignal,:StopTimeout,:Shell,:HostConfig,:NetworkingConfig],
122
+ "update" => [:CpuShares, :Memory, :CgroupParent, :BlkioWeight, :BlkioWeightDevice, :BlkioWeightReadBps, :BlkioWeightWriteBps, :BlkioWeightReadOps, :BlkioWeightWriteOps, :CpuPeriod, :CpuQuota, :CpuRealtimePeriod, :CpuRealtimeRuntime, :CpusetCpus, :CpusetMems, :Devices, :DeviceCgroupRules, :DeviceRequest, :Kernel, :Memory, :KernelMemoryTCP, :MemoryReservation, :MemorySwap, :MemorySwappiness, :NanoCPUs, :OomKillDisable, :Init, :PidsLimit, :ULimits, :CpuCount, :CpuPercent, :IOMaximumIOps, :IOMaximumBandwidth, :RestartPolicy]
123
+ },
124
+ "Docker::API::Volume" => {
125
+ "create" => [:Name, :Driver, :DriverOpts, :Labels]
126
+ },
127
+ "Docker::API::Network" => {
128
+ "create" => [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels],
129
+ "connect" => [:Container, :EndpointConfig],
130
+ "disconnect" => [:Container, :Force]
131
+ },
132
+ "Docker::API::System" => {
133
+ "auth" => [:username, :password, :email, :serveraddress, :identitytoken]
134
+ },
135
+ "Docker::API::Exec" => {
136
+ "create" => [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir],
137
+ "start" => [:Detach, :Tty]
138
+ },
139
+ "Docker::API::Swarm" => {
140
+ "init" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec],
141
+ "update" => [:Name, :Labels, :Orchestration, :Raft, :Dispatcher, :CAConfig, :EncryptionConfig, :TaskDefaults],
142
+ "unlock" => [:UnlockKey],
143
+ "join" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken]
144
+ },
145
+ "Docker::API::Node" => {
146
+ "update" => [:Name, :Labels, :Role, :Availability]
147
+ },
148
+ "Docker::API::Service" => {
149
+ "create" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec],
150
+ "update" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec]
151
+ },
152
+ "Docker::API::Secret" => {
153
+ "create" => [:Name, :Labels, :Data, :Driver, :Templating],
154
+ "update" => [:Name, :Labels, :Data, :Driver, :Templating]
155
+ },
156
+ "Docker::API::Config" => {
157
+ "create" => [:Name, :Labels, :Data, :Templating],
158
+ "update" => [:Name, :Labels, :Data, :Driver, :Templating]
159
+ }
160
+ }
25
161
 
26
162
  end
27
163
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alysson A. Costa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon