dockerapi 0.13.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,33 @@
1
- module Docker
2
- module API
3
- class Response < Excon::Response
4
- attr_reader(:json, :path)
1
+ ##
2
+ # Reponse class.
3
+ class Docker::API::Response < Excon::Response
4
+ attr_reader(:json, :path)
5
5
 
6
- def initialize data
7
- super data
8
- @json = parse_json @body
9
- @path = @data[:path]
10
- end
6
+ ##
7
+ # Initialize a new Response object.
8
+ #
9
+ # @params data [Object]: Reponse's data.
10
+ def initialize data
11
+ super data
12
+ @json = parse_json @body
13
+ @path = @data[:path]
14
+ end
11
15
 
12
- def success?
13
- (200..204).include? @status
14
- end
16
+ ##
17
+ # Return true if Response status is in 200..204 range.
18
+ def success?
19
+ (200..204).include? @status
20
+ end
15
21
 
16
- private
22
+ private
17
23
 
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
+ ##
25
+ # Create a json from Response data attribute.
26
+ #
27
+ # @params data [String]: String to be converted in json.
28
+ def parse_json data
29
+ return nil unless headers["Content-Type"] == "application/json"
30
+ return nil if data == ""
31
+ data.split("\r\n").size > 1 ? data.split("\r\n").map{ |e| eval(e) } : JSON.parse(data)
24
32
  end
25
33
  end
@@ -1,14 +1,12 @@
1
1
  # This class represents the Docker API endpoints regarding secrets.
2
2
  #
3
- # @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
4
- #
5
3
  # Secrets are sensitive data that can be used by services. Swarm mode must be enabled for these endpoints to work.
4
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
6
5
  class Docker::API::Secret < Docker::API::Base
7
6
 
8
7
  # List secrets
9
8
  #
10
9
  # Docker API: GET /secrets
11
- #
12
10
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretList
13
11
  #
14
12
  # @param params [Hash]: Parameters that are appended to the URL.
@@ -19,7 +17,6 @@ class Docker::API::Secret < Docker::API::Base
19
17
  # Create a secret
20
18
  #
21
19
  # Docker API: POST /secrets/create
22
- #
23
20
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretCreate
24
21
  #
25
22
  # @param body [Hash]: Request body to be sent as json.
@@ -30,7 +27,6 @@ class Docker::API::Secret < Docker::API::Base
30
27
  # Inspect a secret
31
28
  #
32
29
  # Docker API: GET /secrets/{id}
33
- #
34
30
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretInspect
35
31
  #
36
32
  # @param name [String]: The ID or name of the secret.
@@ -41,13 +37,10 @@ class Docker::API::Secret < Docker::API::Base
41
37
  # Update a secret
42
38
  #
43
39
  # Docker API: POST /secrets/{id}/update
44
- #
45
40
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretUpdate
46
41
  #
47
42
  # @param name [String]: The ID or name of the secret.
48
- #
49
43
  # @param params [Hash]: Parameters that are appended to the URL.
50
- #
51
44
  # @param body [Hash]: Request body to be sent as json.
52
45
  def update name, params = {}, body = {}
53
46
  @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
@@ -56,7 +49,6 @@ class Docker::API::Secret < Docker::API::Base
56
49
  # Delete a secret
57
50
  #
58
51
  # Docker API: DELETE /secrets/{id}
59
- #
60
52
  # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretDelete
61
53
  #
62
54
  # @param name [String]: The ID or name of the secret.
@@ -1,14 +1,12 @@
1
1
  # This class represents the Docker API endpoints regarding services.
2
2
  #
3
- # @see https://docs.docker.com/engine/api/v1.40/#tag/Service
4
- #
5
3
  # Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work.
4
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Service
6
5
  class Docker::API::Service < Docker::API::Base
7
6
 
8
7
  # List services
9
8
  #
10
9
  # Docker API: GET /services
11
- #
12
10
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
13
11
  #
14
12
  # @param params [Hash]: Parameters that are appended to the URL.
@@ -19,46 +17,38 @@ class Docker::API::Service < Docker::API::Base
19
17
  # Create a service
20
18
  #
21
19
  # Docker API: POST /services/create
22
- #
23
20
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceCreate
24
21
  #
25
22
  # @param body [Hash]: Request body to be sent as json.
26
- #
27
23
  # @param authentication [Hash]: Authentication parameters.
28
24
  def create body = {}, authentication = {}
29
25
  headers = {"Content-Type": "application/json"}
30
- headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
26
+ headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
31
27
  @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
32
28
  end
33
29
 
34
30
  # Update a service
35
31
  #
36
32
  # Docker API: POST /services/{id}/update
37
- #
38
33
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceUpdate
39
34
  #
40
35
  # @param name [String]: The ID or name of the service.
41
- #
42
36
  # @param params [Hash]: Parameters that are appended to the URL.
43
- #
44
37
  # @param body [Hash]: Request body to be sent as json.
45
- #
46
38
  # @param authentication [Hash]: Authentication parameters.
47
39
  def update name, params = {}, body = {}, authentication = {}
48
40
  # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
49
41
  headers = {"Content-Type": "application/json"}
50
- headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
42
+ headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
51
43
  @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
52
44
  end
53
45
 
54
46
  # Inspect a service
55
47
  #
56
48
  # Docker API: GET /services/{id}
57
- #
58
49
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceInspect
59
50
  #
60
51
  # @param name [String]: The ID or name of the service.
61
- #
62
52
  # @param params [Hash]: Parameters that are appended to the URL.
63
53
  def details name, params = {}
64
54
  @connection.get(build_path("/services/#{name}", params))
@@ -66,14 +56,10 @@ class Docker::API::Service < Docker::API::Base
66
56
 
67
57
  # Get stdout and stderr logs from a service.
68
58
  #
69
- # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
70
- #
71
59
  # Docker API: GET /services/{id}/logs
72
- #
73
60
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceLogs
74
61
  #
75
62
  # @param name [String]: The ID or name of the service.
76
- #
77
63
  # @param params [Hash]: Parameters that are appended to the URL.
78
64
  def logs name, params = {}
79
65
  @connection.get(build_path("/services/#{name}/logs", params))
@@ -82,7 +68,6 @@ class Docker::API::Service < Docker::API::Base
82
68
  # Delete a service
83
69
  #
84
70
  # Docker API: DELETE /services/{id}
85
- #
86
71
  # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceDelete
87
72
  #
88
73
  # @param name [String]: The ID or name of the service.
@@ -1,45 +1,79 @@
1
- module Docker
2
- module API
3
- class Swarm < Docker::API::Base
1
+ ##
2
+ # This class represents the Docker API endpoints regarding swamrs.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Swarm
4
+ class Docker::API::Swarm < Docker::API::Base
4
5
 
5
- def init body = {}
6
- @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
7
- end
8
-
9
- def update params = {}, body = {}
10
- @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
11
- end
6
+ ##
7
+ # Initialize a new swarm.
8
+ #
9
+ # Docker API: POST /swarm/init
10
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInit
11
+ #
12
+ # @param body [Hash]: Request body to be sent as json.
13
+ def init body = {}
14
+ @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
15
+ end
12
16
 
13
- def details
14
- @connection.get("/swarm")
15
- end
17
+ ##
18
+ # Update a swarm.
19
+ #
20
+ # Docker API: POST /swarm/update
21
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUpdate
22
+ #
23
+ # @param params [Hash]: Parameters that are appended to the URL.
24
+ # @param body [Hash]: Request body to be sent as json.
25
+ def update params = {}, body = {}
26
+ @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
27
+ end
16
28
 
17
- def unlock_key
18
- @connection.get(build_path("/swarm/unlockkey"))
19
- end
29
+ ##
30
+ # Inspect swarm.
31
+ #
32
+ # Docker API: GET /swarm
33
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInspect
34
+ def details
35
+ @connection.get("/swarm")
36
+ end
20
37
 
21
- def unlock body = {}
22
- @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type": "application/json"}, body: body.to_json)
23
- end
38
+ ##
39
+ # Get the unlock key.
40
+ #
41
+ # Docker API: GET /swarm/unlockkey
42
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlockkey
43
+ def unlock_key
44
+ @connection.get("/swarm/unlockkey")
45
+ end
24
46
 
25
- def join body = {}
26
- @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type": "application/json"}, body: body.to_json)
27
- end
47
+ ##
48
+ # Unlock a locked manager.
49
+ #
50
+ # Docker API: POST /swarm/unlock
51
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlock
52
+ #
53
+ # @param body [Hash]: Request body to be sent as json.
54
+ def unlock body = {}
55
+ @connection.request(method: :post, path: "/swarm/unlock", headers: {"Content-Type": "application/json"}, body: body.to_json)
56
+ end
28
57
 
29
- def leave params = {}
30
- @connection.post(build_path("/swarm/leave", params))
31
- end
58
+ ##
59
+ # Join an existing swarm.
60
+ #
61
+ # Docker API: POST /swarm/join
62
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmJoin
63
+ #
64
+ # @param body [Hash]: Request body to be sent as json.
65
+ def join body = {}
66
+ @connection.request(method: :post, path: "/swarm/join", headers: {"Content-Type": "application/json"}, body: body.to_json)
67
+ end
32
68
 
33
- #################################################
34
- # Items in this area to be removed before 1.0.0 #
35
- #################################################
36
- def inspect
37
- caller.each { | el | return super.inspect if el.match(/inspector/) }
38
- warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
39
- details
40
- end
41
- #################################################
42
-
43
- end
69
+ ##
70
+ # Leave a swarm.
71
+ #
72
+ # Docker API: POST /swarm/leave
73
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmLeave
74
+ #
75
+ # @param params [Hash]: Parameters that are appended to the URL.
76
+ def leave params = {}
77
+ @connection.post(build_path("/swarm/leave", params))
44
78
  end
45
79
  end
@@ -1,32 +1,65 @@
1
- require "json"
2
- module Docker
3
- module API
4
- class System < Docker::API::Base
1
+ ##
2
+ # This class represents the Docker API system related endpoints.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/System
4
+ class Docker::API::System < Docker::API::Base
5
5
 
6
- def auth body = {}
7
- @connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
8
- end
6
+ ##
7
+ # Validate credentials for a registry and, if available, get an identity token for accessing the registry without password.
8
+ #
9
+ # Docker API: POST /auth
10
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemAuth
11
+ #
12
+ # @param body [Hash]: Request body to be sent as json.
13
+ def auth body = {}
14
+ @connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
15
+ end
9
16
 
10
- def events params = {}
11
- @connection.request(method: :get, path: build_path("/events", params), response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect } )
12
- end
17
+ ##
18
+ # Stream real-time events from the server.
19
+ #
20
+ # Docker API: GET /events
21
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemEvents
22
+ #
23
+ # @param params [Hash]: Parameters that are appended to the URL.
24
+ # @param &block: Replace the default output to stdout behavior.
25
+ def events params = {}, &block
26
+ @connection.request(method: :get, path: build_path("/events", params), response_block: block_given? ? block : default_streamer )
27
+ end
13
28
 
14
- def ping
15
- @connection.get("/_ping")
16
- end
29
+ ##
30
+ # This is a dummy endpoint you can use to test if the server is accessible.
31
+ #
32
+ # Docker API: GET /_ping
33
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemPing
34
+ def ping
35
+ @connection.get("/_ping")
36
+ end
17
37
 
18
- def info
19
- @connection.get("/info")
20
- end
38
+ ##
39
+ # Get system information.
40
+ #
41
+ # Docker API: GET /info
42
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemInfo
43
+ def info
44
+ @connection.get("/info")
45
+ end
21
46
 
22
- def version
23
- @connection.get("/version")
24
- end
47
+ ##
48
+ # Return the version of Docker that is running and various information about the system that Docker is running on.
49
+ #
50
+ # Docker API: GET /version
51
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemVersion
52
+ def version
53
+ @connection.get("/version")
54
+ end
25
55
 
26
- def df
27
- @connection.get("/system/df")
28
- end
29
-
30
- end
56
+ ##
57
+ # Get data usage information.
58
+ #
59
+ # Docker API: GET /system/df
60
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemDataUsage
61
+ def df
62
+ @connection.get("/system/df")
31
63
  end
64
+
32
65
  end
@@ -1,14 +1,12 @@
1
1
  # This class represents the Docker API endpoints regarding tasks.
2
2
  #
3
- # @see https://docs.docker.com/engine/api/v1.40/#tag/Task
4
- #
5
3
  # A task is a container running on a swarm. It is the atomic scheduling unit of swarm. Swarm mode must be enabled for these endpoints to work.
4
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Task
6
5
  class Docker::API::Task < Docker::API::Base
7
6
 
8
7
  # List tasks
9
8
  #
10
9
  # Docker API: GET /tasks
11
- #
12
10
  # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskList
13
11
  #
14
12
  # @param params [Hash]: Parameters that are appended to the URL.
@@ -19,7 +17,6 @@ class Docker::API::Task < Docker::API::Base
19
17
  # Inspect a task
20
18
  #
21
19
  # Docker API: GET /tasks/{id}
22
- #
23
20
  # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskInspect
24
21
  #
25
22
  # @param name [String]: The ID or name of the task.
@@ -29,16 +26,19 @@ class Docker::API::Task < Docker::API::Base
29
26
 
30
27
  # Get stdout and stderr logs from a task.
31
28
  #
32
- # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
33
- #
34
29
  # Docker API: GET /tasks/{id}/logs
35
- #
36
30
  # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskLogs
37
31
  #
38
32
  # @param name (String) : The ID or name of the task.
39
- #
40
33
  # @param params (Hash) : Parameters that are appended to the URL.
41
- def logs name, params = {}
42
- @connection.get(build_path("/tasks/#{name}/logs", params))
34
+ # @param &block: Replace the default output to stdout behavior.
35
+ def logs name, params = {}, &block
36
+ path = build_path("/tasks/#{name}/logs", params)
37
+
38
+ if [true, 1 ].include? params[:follow]
39
+ @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
40
+ else
41
+ @connection.get(path)
42
+ end
43
43
  end
44
44
  end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.13.0"
3
+ GEM_VERSION = "0.18.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6