dockerapi 0.14.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,8 +1,8 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.14.0"
3
+ GEM_VERSION = "0.19.0"
4
4
 
5
- API_VERSION = "1.40"
5
+ API_VERSION = "1.41"
6
6
 
7
7
  VERSION = "Gem: #{Docker::API::GEM_VERSION} | API: #{Docker::API::API_VERSION}"
8
8
  end
@@ -1,42 +1,61 @@
1
- module Docker
2
- module API
3
- class Volume < Docker::API::Base
4
-
5
- def list params = {}
6
- @connection.get(build_path("/volumes", params))
7
- end
8
-
9
- def details name
10
- @connection.get(build_path([name]))
11
- end
12
-
13
- def create body = {}
14
- @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
15
- end
16
-
17
- def remove name, params = {}
18
- @connection.delete(build_path([name]))
19
- end
1
+ ##
2
+ # This class represents the Docker API endpoints regarding volumes.
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Volume
4
+ class Docker::API::Volume < Docker::API::Base
5
+
6
+ ##
7
+ # List volumes.
8
+ #
9
+ # Docker API: GET
10
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeList
11
+ #
12
+ # @param params [Hash]: Parameters that are appended to the URL.
13
+ def list params = {}
14
+ @connection.get(build_path("/volumes", params))
15
+ end
20
16
 
21
- def prune params = {}
22
- @connection.post(build_path(["prune"], params))
23
- end
17
+ ##
18
+ # Inspect a volume.
19
+ #
20
+ # Docker API: GET /volumes/{name}
21
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeInspect
22
+ #
23
+ # @param name [String]: The ID or name of the volume.
24
+ def details name
25
+ @connection.get("/volumes/#{name}")
26
+ end
24
27
 
25
- #################################################
26
- # Items in this area to be removed before 1.0.0 #
27
- #################################################
28
- def base_path
29
- "/volumes"
30
- end
28
+ ##
29
+ # Create a volume.
30
+ #
31
+ # Docker API: POST /volumes/create
32
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeCreate
33
+ #
34
+ # @param body [Hash]: Request body to be sent as json.
35
+ def create body = {}
36
+ @connection.request(method: :post, path: "/volumes/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
37
+ end
31
38
 
32
- def inspect *args
33
- return super.inspect if args.size == 0
34
- warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
35
- name = args[0]
36
- @connection.get(build_path([name]))
37
- end
38
- #################################################
39
+ ##
40
+ # Remove a volume.
41
+ #
42
+ # Docker API: DELETE /volumes/{name}
43
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumeDelete
44
+ #
45
+ # @param name [String]: The ID or name of the volume.
46
+ # @param params [Hash]: Parameters that are appended to the URL.
47
+ def remove name, params = {}
48
+ @connection.delete(build_path("/volumes/#{name}",params))
49
+ end
39
50
 
40
- end
51
+ ##
52
+ # Delete unused volumes.
53
+ #
54
+ # Docker API: POST /volumes/prune
55
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/VolumePrune
56
+ #
57
+ # @param params [Hash]: Parameters that are appended to the URL.
58
+ def prune params = {}
59
+ @connection.post(build_path("/volumes/prune", params))
41
60
  end
42
- end
61
+ end