dockerapi 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/README.md +55 -4
- data/lib/docker/api/base.rb +3 -3
- data/lib/docker/api/connection.rb +1 -3
- data/lib/docker/api/error.rb +13 -2
- data/lib/docker/api/image.rb +1 -1
- data/lib/docker/api/response.rb +25 -0
- data/lib/docker/api/system.rb +21 -0
- data/lib/docker/api/version.rb +1 -1
- data/lib/dockerapi.rb +4 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f647538a729eaa623b009a4e97713761bc80579073ebfb8b9ab7bfa26b6b6d98
|
4
|
+
data.tar.gz: ce3b40c357d635a47ab8c921b59254ef734c2ec1173da60e58ba1b6f7d325ecf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f845ea3e89761d9ab726f098d4ef4ca1586c92320616359b182d6f9dc24e7769b53c88a6d17d8257514303226b16fd08a841ced1645be68c19b4d4b31a8a9b4f
|
7
|
+
data.tar.gz: 409819921a1135b593377d8c561d0d5f81013f519e98a547976b1563b4038bff91f5948a5cd00b9f7513026821811b9baa476306915b7b644768232238daf0f4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# 0.5.0
|
2
|
+
|
3
|
+
Add Docker::API::System methods:
|
4
|
+
* auth
|
5
|
+
* ping
|
6
|
+
* info
|
7
|
+
* version
|
8
|
+
* events
|
9
|
+
* df
|
10
|
+
|
11
|
+
Add new response class Docker::API::Response with the following methods:
|
12
|
+
* json
|
13
|
+
* path
|
14
|
+
* success?
|
15
|
+
|
16
|
+
Error classes output better error messages.
|
17
|
+
|
1
18
|
# 0.4.0
|
2
19
|
|
3
20
|
Add Docker::API::Network methods:
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -196,13 +196,64 @@ Docker::API::Network.connect( "my-network", Container: "my-container" )
|
|
196
196
|
Docker::API::Network.disconnect( "my-network", Container: "my-container" )
|
197
197
|
```
|
198
198
|
|
199
|
+
### System
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
# Ping docker api
|
203
|
+
Docker::API::System.ping
|
204
|
+
|
205
|
+
# Docker components versions
|
206
|
+
Docker::API::System.version
|
207
|
+
|
208
|
+
# System info
|
209
|
+
Docker::API::System.info
|
210
|
+
|
211
|
+
# System events (stream)
|
212
|
+
Docker::API::System.events(until: Time.now.to_i)
|
213
|
+
|
214
|
+
# Data usage information
|
215
|
+
Docker::API::System.df
|
216
|
+
```
|
217
|
+
|
199
218
|
### Requests
|
200
219
|
|
201
220
|
Requests should work as described in [Docker API documentation](https://docs.docker.com/engine/api/v1.40). Check it out to customize your requests.
|
202
221
|
|
203
222
|
### Response
|
204
223
|
|
205
|
-
All requests return a Excon::Response
|
224
|
+
All requests return a response class that inherits from Excon::Response. Available attribute readers and methods include: `status`, `data`, `body`, `headers`, `json`, `path`, `success?`.
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
response = Docker::API::Image.create(fromImage: "busybox:latest")
|
228
|
+
|
229
|
+
response
|
230
|
+
=> #<Docker::API::Response:0x000055bb390b35c0 ... >
|
231
|
+
|
232
|
+
response.status
|
233
|
+
=> 200
|
234
|
+
|
235
|
+
response.data
|
236
|
+
=> {:body=>"...", :cookies=>[], :host=>nil, :headers=>{ ... }, :path=>"/images/create?fromImage=busybox:latest", :port=>nil, :status=>200, :status_line=>"HTTP/1.1 200 OK\r\n", :reason_phrase=>"OK"}
|
237
|
+
|
238
|
+
response.headers
|
239
|
+
=> {"Api-Version"=>"1.40", "Content-Type"=>"application/json", "Docker-Experimental"=>"false", "Ostype"=>"linux", "Server"=>"Docker/19.03.11 (linux)", "Date"=>"Mon, 29 Jun 2020 16:10:06 GMT"}
|
240
|
+
|
241
|
+
response.body
|
242
|
+
=> "{\"status\":\"Pulling from library/busybox\" ... "
|
243
|
+
|
244
|
+
response.json
|
245
|
+
=> [{:status=>"Pulling from library/busybox", :id=>"latest"}, {:status=>"Pulling fs layer", :progressDetail=>{}, :id=>"76df9210b28c"}, ... , {:status=>"Status: Downloaded newer image for busybox:latest"}]
|
246
|
+
|
247
|
+
response.path
|
248
|
+
=> "/images/create?fromImage=busybox:latest"
|
249
|
+
|
250
|
+
response.success?
|
251
|
+
=> true
|
252
|
+
```
|
253
|
+
|
254
|
+
### Error handling
|
255
|
+
|
256
|
+
`Docker::API::InvalidParameter` and `Docker::API::InvalidRequestBody` may be raised when an invalid option is passed as argument (ie: an option not described in Docker API documentation for request query parameters nor request body (json) parameters). Even if no errors were raised, consider validating the status code and/or message of the response to check if the Docker daemon has fulfilled the operation properly.
|
206
257
|
|
207
258
|
## Development
|
208
259
|
|
@@ -223,7 +274,7 @@ WIP: Work In Progress
|
|
223
274
|
| Image | Ok | Ok | NS |
|
224
275
|
| Volume | Ok | Ok | NS |
|
225
276
|
| Network | Ok | Ok | NS |
|
226
|
-
| System |
|
277
|
+
| System | Ok | Ok | NS |
|
227
278
|
| Exec | NS | NS | NS |
|
228
279
|
| Swarm | NS | NS | NS |
|
229
280
|
| Node | NS | NS | NS |
|
@@ -232,8 +283,8 @@ WIP: Work In Progress
|
|
232
283
|
| Secret | NS | NS | NS |
|
233
284
|
|
234
285
|
Misc:
|
235
|
-
* Improve response object
|
236
|
-
* Improve error objects
|
286
|
+
* ~~Improve response object~~
|
287
|
+
* ~~Improve error objects~~
|
237
288
|
|
238
289
|
## Contributing
|
239
290
|
|
data/lib/docker/api/base.rb
CHANGED
@@ -12,9 +12,9 @@ module Docker
|
|
12
12
|
Docker::API::Connection.instance
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.validate error,
|
16
|
-
|
17
|
-
raise error if
|
15
|
+
def self.validate error, permitted, params
|
16
|
+
unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s)
|
17
|
+
raise error.new(permitted, unpermitted) if unpermitted.size > 0
|
18
18
|
end
|
19
19
|
|
20
20
|
## Converts Ruby Hash into query parameters
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require "excon"
|
2
1
|
require "singleton"
|
3
|
-
require "json"
|
4
2
|
module Docker
|
5
3
|
module API
|
6
4
|
class Connection
|
@@ -15,7 +13,7 @@ module Docker
|
|
15
13
|
end
|
16
14
|
|
17
15
|
def request params
|
18
|
-
@connection.request(params)
|
16
|
+
Docker::API::Response.new(@connection.request(params).data)
|
19
17
|
end
|
20
18
|
|
21
19
|
private
|
data/lib/docker/api/error.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
module Docker
|
2
2
|
module API
|
3
|
-
class
|
4
|
-
|
3
|
+
class ValidationError < StandardError
|
4
|
+
def initialize permitted, unpermitted
|
5
|
+
super("Unpermitted options found: #{unpermitted.to_s}. Permitted are #{permitted.to_s}")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
class Error < StandardError
|
9
|
+
def initialize msg = "Error without specific message"
|
10
|
+
super(msg)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class InvalidParameter < Docker::API::ValidationError; end
|
15
|
+
class InvalidRequestBody < Docker::API::ValidationError; end
|
5
16
|
end
|
6
17
|
end
|
data/lib/docker/api/image.rb
CHANGED
@@ -107,7 +107,7 @@ module Docker
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def self.build path, params = {}, authentication = {}
|
110
|
-
raise Docker::API::
|
110
|
+
raise Docker::API::Error.new("Expected path or params[:remote]") unless path || params[:remote]
|
111
111
|
validate Docker::API::InvalidParameter, Docker::API::BuildParams, params
|
112
112
|
|
113
113
|
header = {"Content-type": "application/x-tar"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Docker
|
2
|
+
module API
|
3
|
+
class Response < Excon::Response
|
4
|
+
attr_reader(:json, :path)
|
5
|
+
|
6
|
+
def initialize data
|
7
|
+
super data
|
8
|
+
@json = parse_json @body
|
9
|
+
@path = @data[:path]
|
10
|
+
end
|
11
|
+
|
12
|
+
def success?
|
13
|
+
(200..204).include? @status
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def parse_json data
|
19
|
+
return nil unless headers["Content-Type"] == "application/json"
|
20
|
+
return nil if data == ""
|
21
|
+
data.split("\r\n").size > 1 ? data.split("\r\n").map{ |e| eval(e) } : JSON.parse(data)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/docker/api/system.rb
CHANGED
@@ -7,6 +7,27 @@ module Docker
|
|
7
7
|
validate Docker::API::InvalidRequestBody, [:username, :password, :email, :serveraddress, :identitytoken], body
|
8
8
|
connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
|
9
9
|
end
|
10
|
+
|
11
|
+
def self.events params = {}
|
12
|
+
validate Docker::API::InvalidParameter, [:since, :until, :filters], params
|
13
|
+
connection.request(method: :get, path: build_path("/events", params), response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect } )
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ping
|
17
|
+
connection.get("/_ping")
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.info
|
21
|
+
connection.get("/info")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.version
|
25
|
+
connection.get("/version")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.df
|
29
|
+
connection.get("/system/df")
|
30
|
+
end
|
10
31
|
end
|
11
32
|
end
|
12
33
|
end
|
data/lib/docker/api/version.rb
CHANGED
data/lib/dockerapi.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
require "
|
1
|
+
require "excon"
|
2
|
+
require "json"
|
2
3
|
|
4
|
+
require "docker/api/version"
|
3
5
|
require "docker/api/error"
|
4
6
|
require "docker/api/connection"
|
7
|
+
require "docker/api/response"
|
5
8
|
require "docker/api/base"
|
6
9
|
require "docker/api/container"
|
7
10
|
require "docker/api/image"
|
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.
|
4
|
+
version: 0.5.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-06-
|
11
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/docker/api/error.rb
|
50
50
|
- lib/docker/api/image.rb
|
51
51
|
- lib/docker/api/network.rb
|
52
|
+
- lib/docker/api/response.rb
|
52
53
|
- lib/docker/api/system.rb
|
53
54
|
- lib/docker/api/version.rb
|
54
55
|
- lib/docker/api/volume.rb
|