dockerapi 0.9.0 → 0.14.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.
@@ -0,0 +1,66 @@
1
+ # This class represents the Docker API endpoints regarding secrets.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
4
+ #
5
+ # Secrets are sensitive data that can be used by services. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Secret < Docker::API::Base
7
+
8
+ # List secrets
9
+ #
10
+ # Docker API: GET /secrets
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ @connection.get(build_path("/secrets",params))
17
+ end
18
+
19
+ # Create a secret
20
+ #
21
+ # Docker API: POST /secrets/create
22
+ #
23
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretCreate
24
+ #
25
+ # @param body [Hash]: Request body to be sent as json.
26
+ def create body = {}
27
+ @connection.request(method: :post, path: "/secrets/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
28
+ end
29
+
30
+ # Inspect a secret
31
+ #
32
+ # Docker API: GET /secrets/{id}
33
+ #
34
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretInspect
35
+ #
36
+ # @param name [String]: The ID or name of the secret.
37
+ def details name
38
+ @connection.get("/secrets/#{name}")
39
+ end
40
+
41
+ # Update a secret
42
+ #
43
+ # Docker API: POST /secrets/{id}/update
44
+ #
45
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretUpdate
46
+ #
47
+ # @param name [String]: The ID or name of the secret.
48
+ #
49
+ # @param params [Hash]: Parameters that are appended to the URL.
50
+ #
51
+ # @param body [Hash]: Request body to be sent as json.
52
+ def update name, params = {}, body = {}
53
+ @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
54
+ end
55
+
56
+ # Delete a secret
57
+ #
58
+ # Docker API: DELETE /secrets/{id}
59
+ #
60
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretDelete
61
+ #
62
+ # @param name [String]: The ID or name of the secret.
63
+ def delete name
64
+ @connection.delete("/secrets/#{name}")
65
+ end
66
+ end
@@ -0,0 +1,92 @@
1
+ # This class represents the Docker API endpoints regarding services.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Service
4
+ #
5
+ # Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Service < Docker::API::Base
7
+
8
+ # List services
9
+ #
10
+ # Docker API: GET /services
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ @connection.get(build_path("/services", params))
17
+ end
18
+
19
+ # Create a service
20
+ #
21
+ # Docker API: POST /services/create
22
+ #
23
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceCreate
24
+ #
25
+ # @param body [Hash]: Request body to be sent as json.
26
+ #
27
+ # @param authentication [Hash]: Authentication parameters.
28
+ def create body = {}, authentication = {}
29
+ headers = {"Content-Type": "application/json"}
30
+ headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
31
+ @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
32
+ end
33
+
34
+ # Update a service
35
+ #
36
+ # Docker API: POST /services/{id}/update
37
+ #
38
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceUpdate
39
+ #
40
+ # @param name [String]: The ID or name of the service.
41
+ #
42
+ # @param params [Hash]: Parameters that are appended to the URL.
43
+ #
44
+ # @param body [Hash]: Request body to be sent as json.
45
+ #
46
+ # @param authentication [Hash]: Authentication parameters.
47
+ def update name, params = {}, body = {}, authentication = {}
48
+ # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
49
+ headers = {"Content-Type": "application/json"}
50
+ headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
51
+ @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
52
+ end
53
+
54
+ # Inspect a service
55
+ #
56
+ # Docker API: GET /services/{id}
57
+ #
58
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceInspect
59
+ #
60
+ # @param name [String]: The ID or name of the service.
61
+ #
62
+ # @param params [Hash]: Parameters that are appended to the URL.
63
+ def details name, params = {}
64
+ @connection.get(build_path("/services/#{name}", params))
65
+ end
66
+
67
+ # Get stdout and stderr logs from a service.
68
+ #
69
+ # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
70
+ #
71
+ # Docker API: GET /services/{id}/logs
72
+ #
73
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceLogs
74
+ #
75
+ # @param name [String]: The ID or name of the service.
76
+ #
77
+ # @param params [Hash]: Parameters that are appended to the URL.
78
+ def logs name, params = {}
79
+ @connection.get(build_path("/services/#{name}/logs", params))
80
+ end
81
+
82
+ # Delete a service
83
+ #
84
+ # Docker API: DELETE /services/{id}
85
+ #
86
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceDelete
87
+ #
88
+ # @param name [String]: The ID or name of the service.
89
+ def delete name
90
+ @connection.delete("/services/#{name}")
91
+ end
92
+ end
@@ -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
 
@@ -0,0 +1,44 @@
1
+ # This class represents the Docker API endpoints regarding tasks.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Task
4
+ #
5
+ # 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.
6
+ class Docker::API::Task < Docker::API::Base
7
+
8
+ # List tasks
9
+ #
10
+ # Docker API: GET /tasks
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ @connection.get(build_path("/tasks",params))
17
+ end
18
+
19
+ # Inspect a task
20
+ #
21
+ # Docker API: GET /tasks/{id}
22
+ #
23
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskInspect
24
+ #
25
+ # @param name [String]: The ID or name of the task.
26
+ def details name
27
+ @connection.get("/tasks/#{name}")
28
+ end
29
+
30
+ # Get stdout and stderr logs from a task.
31
+ #
32
+ # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
33
+ #
34
+ # Docker API: GET /tasks/{id}/logs
35
+ #
36
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskLogs
37
+ #
38
+ # @param name (String) : The ID or name of the task.
39
+ #
40
+ # @param params (Hash) : Parameters that are appended to the URL.
41
+ def logs name, params = {}
42
+ @connection.get(build_path("/tasks/#{name}/logs", params))
43
+ end
44
+ end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.9.0"
3
+ GEM_VERSION = "0.14.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"
@@ -14,9 +16,149 @@ require "docker/api/exec"
14
16
  require "docker/api/system"
15
17
  require "docker/api/swarm"
16
18
  require "docker/api/node"
19
+ require "docker/api/service"
20
+ require "docker/api/task"
21
+ require "docker/api/secret"
22
+ require "docker/api/config"
23
+ require "docker/api/plugin"
17
24
 
18
25
  module Docker
19
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
+ "get_archive" => [:path],
61
+ "put_archive" => [:path, :noOverwriteDirNonDir, :copyUIDGID],
62
+ "create" => [:name]
63
+ },
64
+ "Docker::API::Volume" => {
65
+ "list" => [:filters],
66
+ "remove" => [:force],
67
+ "prune" => [:filters]
68
+ },
69
+ "Docker::API::Network" => {
70
+ "list" => [:filters],
71
+ "details" => [:verbose, :scope],
72
+ "prune" => [:filters]
73
+ },
74
+ "Docker::API::System" => {
75
+ "events" => [:since, :until, :filters]
76
+ },
77
+ "Docker::API::Exec" => {
78
+ "resize" => [:w, :h]
79
+ },
80
+ "Docker::API::Swarm" => {
81
+ "leave" => [:force],
82
+ "update" => [:version, :rotateWorkerToken, :rotateManagerToken, :rotateManagerUnlockKey]
83
+ },
84
+ "Docker::API::Node" => {
85
+ "list" => [:filters],
86
+ "update" => [:version],
87
+ "delete" => [:force]
88
+ },
89
+ "Docker::API::Service" => {
90
+ "list" => [:filters],
91
+ "update" => [:version, :registryAuthFrom, :rollback],
92
+ "details" => [:insertDefaults],
93
+ "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail]
94
+ },
95
+ "Docker::API::Secret" => {
96
+ "list" => [:filters],
97
+ "update" => [:version]
98
+ },
99
+ "Docker::API::Task" => {
100
+ "list" => [:filters],
101
+ "logs" => [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail]
102
+ },
103
+ "Docker::API::Plugin" => {
104
+ "list" => [:filters],
105
+ "privileges" => [:remote],
106
+ "install" => [:remote, :name],
107
+ "remove" => [:force],
108
+ "enable" => [:timeout],
109
+ "upgrade" => [:remote]
110
+ },
111
+ "Docker::API::Config" => {
112
+ "list" => [:filters],
113
+ "update" => [:version]
114
+ }
115
+ }
116
+
117
+ VALID_BODY = {
118
+ "Docker::API::Image" => {
119
+ "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]
120
+ },
121
+ "Docker::API::Container" => {
122
+ "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],
123
+ "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]
124
+ },
125
+ "Docker::API::Volume" => {
126
+ "create" => [:Name, :Driver, :DriverOpts, :Labels]
127
+ },
128
+ "Docker::API::Network" => {
129
+ "create" => [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels],
130
+ "connect" => [:Container, :EndpointConfig],
131
+ "disconnect" => [:Container, :Force]
132
+ },
133
+ "Docker::API::System" => {
134
+ "auth" => [:username, :password, :email, :serveraddress, :identitytoken]
135
+ },
136
+ "Docker::API::Exec" => {
137
+ "create" => [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir],
138
+ "start" => [:Detach, :Tty]
139
+ },
140
+ "Docker::API::Swarm" => {
141
+ "init" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec],
142
+ "update" => [:Name, :Labels, :Orchestration, :Raft, :Dispatcher, :CAConfig, :EncryptionConfig, :TaskDefaults],
143
+ "unlock" => [:UnlockKey],
144
+ "join" => [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken]
145
+ },
146
+ "Docker::API::Node" => {
147
+ "update" => [:Name, :Labels, :Role, :Availability]
148
+ },
149
+ "Docker::API::Service" => {
150
+ "create" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec],
151
+ "update" => [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec]
152
+ },
153
+ "Docker::API::Secret" => {
154
+ "create" => [:Name, :Labels, :Data, :Driver, :Templating],
155
+ "update" => [:Name, :Labels, :Data, :Driver, :Templating]
156
+ },
157
+ "Docker::API::Config" => {
158
+ "create" => [:Name, :Labels, :Data, :Templating],
159
+ "update" => [:Name, :Labels, :Data, :Driver, :Templating]
160
+ }
161
+ }
20
162
 
21
163
  end
22
164
  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.9.0
4
+ version: 0.14.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-13 00:00:00.000000000 Z
11
+ date: 2020-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -16,15 +16,17 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.74.0
19
+ version: 0.76.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.74.0
27
- description: Interact directly with Docker API from Ruby code.
26
+ version: 0.76.0
27
+ description: Interact with Docker API directly from Ruby code. Comprehensive implementation
28
+ (all available endpoints), no local Docker installation required, easily manipulated
29
+ http responses.
28
30
  email:
29
31
  - alysson.avila.costa@gmail.com
30
32
  executables: []
@@ -44,6 +46,7 @@ files:
44
46
  - bin/setup
45
47
  - dockerapi.gemspec
46
48
  - lib/docker/api/base.rb
49
+ - lib/docker/api/config.rb
47
50
  - lib/docker/api/connection.rb
48
51
  - lib/docker/api/container.rb
49
52
  - lib/docker/api/error.rb
@@ -51,9 +54,13 @@ files:
51
54
  - lib/docker/api/image.rb
52
55
  - lib/docker/api/network.rb
53
56
  - lib/docker/api/node.rb
57
+ - lib/docker/api/plugin.rb
54
58
  - lib/docker/api/response.rb
59
+ - lib/docker/api/secret.rb
60
+ - lib/docker/api/service.rb
55
61
  - lib/docker/api/swarm.rb
56
62
  - lib/docker/api/system.rb
63
+ - lib/docker/api/task.rb
57
64
  - lib/docker/api/version.rb
58
65
  - lib/docker/api/volume.rb
59
66
  - lib/dockerapi.rb
@@ -64,6 +71,7 @@ metadata:
64
71
  homepage_uri: https://github.com/nu12/dockerapi
65
72
  source_code_uri: https://github.com/nu12/dockerapi.git
66
73
  changelog_uri: https://github.com/nu12/dockerapi/blob/master/CHANGELOG.md
74
+ documentation_uri: https://www.rubydoc.info/gems/dockerapi
67
75
  post_install_message:
68
76
  rdoc_options: []
69
77
  require_paths:
@@ -82,5 +90,5 @@ requirements: []
82
90
  rubygems_version: 3.1.2
83
91
  signing_key:
84
92
  specification_version: 4
85
- summary: Interact directly with Docker API from Ruby code.
93
+ summary: Interact with Docker API from Ruby code.
86
94
  test_files: []