From 5a97a078810ef56dc7307c5fb3801144d9d5b0c9 Mon Sep 17 00:00:00 2001 From: nu12 <34694287+nu12@users.noreply.github.com> Date: Mon, 25 Aug 2025 17:42:01 -0400 Subject: [PATCH 1/2] Move request meta --- lib/docker/api/base.rb | 16 ++++++++++- lib/docker/api/config.rb | 10 +++---- lib/docker/api/connection.rb | 19 +++---------- lib/docker/api/container.rb | 52 ++++++++++++++++++------------------ lib/docker/api/exec.rb | 8 +++--- lib/docker/api/image.rb | 28 +++++++++---------- lib/docker/api/network.rb | 14 +++++----- lib/docker/api/node.rb | 8 +++--- lib/docker/api/plugin.rb | 24 ++++++++--------- lib/docker/api/secret.rb | 10 +++---- lib/docker/api/service.rb | 12 ++++----- lib/docker/api/swarm.rb | 14 +++++----- lib/docker/api/system.rb | 12 ++++----- lib/docker/api/task.rb | 8 +++--- lib/docker/api/volume.rb | 10 +++---- 15 files changed, 123 insertions(+), 122 deletions(-) diff --git a/lib/docker/api/base.rb b/lib/docker/api/base.rb index c1e5a0d..b162d44 100644 --- a/lib/docker/api/base.rb +++ b/lib/docker/api/base.rb @@ -1,6 +1,20 @@ ## # Base class to provide general methods, helpers and implementations accross classes. class Docker::API::Base + [:get, :post, :head, :delete, :put].each do | method | + define_method(method) { | path | self.request(method: method, path: path) } + end + + ## + # Call an Excon request and returns a Docker::API::Response object. + # + # @param params [Hash]: Request parameters. + def request params + response = Docker::API::Response.new(@connection.excon.request(params).data) + response.request_params = params + p response if Docker::API.print_response_to_stdout + response + end ## # Create new object and sets the validation to happen automatically when method parameters include "params" or "body". @@ -45,7 +59,7 @@ def default_writer path # @param &block: Replace the default output to stdout behavior. def default_reader path, url, header = {"Content-Type" => "application/x-tar"}, &block file = File.open(File.expand_path(path), "r") - 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 : default_streamer ) + response = request(method: :post, path: url , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block : default_streamer ) file.close response end diff --git a/lib/docker/api/config.rb b/lib/docker/api/config.rb index 996529a..e8002da 100644 --- a/lib/docker/api/config.rb +++ b/lib/docker/api/config.rb @@ -13,7 +13,7 @@ class Docker::API::Config < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/configs",params)) + get(build_path("/configs",params)) end # Create a config @@ -24,7 +24,7 @@ def list params = {} # # @param body [Hash]: Request body to be sent as json. def create body = {} - @connection.request(method: :post, path: "/v#{Docker::API::API_VERSION}/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: "/v#{Docker::API::API_VERSION}/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json) end # Inspect a config @@ -35,7 +35,7 @@ def create body = {} # # @param name [String]: The ID or name of the config. def details name - @connection.get("/v#{Docker::API::API_VERSION}/configs/#{name}") + get("/v#{Docker::API::API_VERSION}/configs/#{name}") end # Update a config @@ -50,7 +50,7 @@ def details name # # @param body [Hash]: Request body to be sent as json. def update name, params = {}, body = {} - @connection.request(method: :post, path: build_path("/v#{Docker::API::API_VERSION}/configs/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/v#{Docker::API::API_VERSION}/configs/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json) end # Delete a config @@ -61,6 +61,6 @@ def update name, params = {}, body = {} # # @param name [String]: The ID or name of the config. def remove name - @connection.delete("/v#{Docker::API::API_VERSION}/configs/#{name}") + delete("/v#{Docker::API::API_VERSION}/configs/#{name}") end end \ No newline at end of file diff --git a/lib/docker/api/connection.rb b/lib/docker/api/connection.rb index 40a749e..d04b65e 100644 --- a/lib/docker/api/connection.rb +++ b/lib/docker/api/connection.rb @@ -1,20 +1,7 @@ ## # Connection class. class Docker::API::Connection - [:get, :post, :head, :delete, :put].each do | method | - define_method(method) { | path | self.request(method: method, path: path) } - end - - ## - # Call an Excon request and returns a Docker::API::Response object. - # - # @param params [Hash]: Request parameters. - def request params - response = Docker::API::Response.new(@connection.request(params).data) - response.request_params = params - p response if Docker::API.print_response_to_stdout - response - end + attr_reader(:excon) ## # Create an Excon connection. @@ -22,8 +9,8 @@ def request params # @param url [String]: URL for the connection. # @param params [String]: Additional parameters. def initialize url = nil, params = {} - return @connection = Excon.new('unix:///', params.merge({socket: '/var/run/docker.sock'})) unless url - @connection = Excon.new(url, params) + return @excon = Excon.new('unix:///', params.merge({socket: '/var/run/docker.sock'})) unless url + @excon = Excon.new(url, params) end end \ No newline at end of file diff --git a/lib/docker/api/container.rb b/lib/docker/api/container.rb index 3a2942b..0cbdaeb 100644 --- a/lib/docker/api/container.rb +++ b/lib/docker/api/container.rb @@ -11,7 +11,7 @@ class Docker::API::Container < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/containers/json", params)) + get(build_path("/containers/json", params)) end ## @@ -23,7 +23,7 @@ def list params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def details name, params = {} - @connection.get(build_path("/containers/#{name}/json", params)) + get(build_path("/containers/#{name}/json", params)) end ## @@ -35,7 +35,7 @@ def details name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def top name, params = {} - @connection.get(build_path("/containers/#{name}/top", params)) + get(build_path("/containers/#{name}/top", params)) end ## @@ -46,7 +46,7 @@ def top name, params = {} # # @param name [String]: The ID or name of the container. def changes name - @connection.get(build_path("/containers/#{name}/changes")) + get(build_path("/containers/#{name}/changes")) end ## @@ -58,7 +58,7 @@ def changes name # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def start name, params = {} - @connection.post(build_path("/containers/#{name}/start", params)) + post(build_path("/containers/#{name}/start", params)) end ## @@ -70,7 +70,7 @@ def start name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def stop name, params = {} - @connection.post(build_path("/containers/#{name}/stop", params)) + post(build_path("/containers/#{name}/stop", params)) end ## @@ -82,7 +82,7 @@ def stop name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def restart name, params = {} - @connection.post(build_path("/containers/#{name}/restart", params)) + post(build_path("/containers/#{name}/restart", params)) end ## @@ -94,7 +94,7 @@ def restart name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def kill name, params = {} - @connection.post(build_path("/containers/#{name}/kill", params)) + post(build_path("/containers/#{name}/kill", params)) end ## @@ -106,7 +106,7 @@ def kill name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def wait name, params = {} - @connection.post(build_path("/containers/#{name}/wait", params)) + post(build_path("/containers/#{name}/wait", params)) end ## @@ -119,7 +119,7 @@ def wait name, params = {} # @param body [Hash]: Request body to be sent as json. def update name, body = {} - @connection.request(method: :post, path: build_path("/containers/#{name}/update"), headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/containers/#{name}/update"), headers: {"Content-Type": "application/json"}, body: body.to_json) end ## @@ -131,7 +131,7 @@ def update name, body = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def rename name, params = {} - @connection.post(build_path("/containers/#{name}/rename", params)) + post(build_path("/containers/#{name}/rename", params)) end ## @@ -143,7 +143,7 @@ def rename name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def resize name, params = {} - @connection.post(build_path("/containers/#{name}/resize", params)) + post(build_path("/containers/#{name}/resize", params)) end ## @@ -154,7 +154,7 @@ def resize name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - @connection.post(build_path("/containers/prune", params)) + post(build_path("/containers/prune", params)) end ## @@ -165,7 +165,7 @@ def prune params = {} # # @param name [String]: The ID or name of the container. def pause name - @connection.post(build_path("/containers/#{name}/pause")) + post(build_path("/containers/#{name}/pause")) end ## @@ -176,7 +176,7 @@ def pause name # # @param name [String]: The ID or name of the container. def unpause name - @connection.post(build_path("/containers/#{name}/unpause")) + post(build_path("/containers/#{name}/unpause")) end ## @@ -188,7 +188,7 @@ def unpause name # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - @connection.delete(build_path("/containers/#{name}", params)) + delete(build_path("/containers/#{name}", params)) end ## @@ -205,9 +205,9 @@ def logs name, params = {}, &block path = build_path("/containers/#{name}/logs", params) if [true, 1 ].include? params[:follow] - @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer) + request(method: :get, path: path , response_block: block_given? ? block : default_streamer) else - @connection.get(path) + get(path) end end @@ -221,7 +221,7 @@ def logs name, params = {}, &block # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default output to stdout behavior. def attach name, params = {}, &block - @connection.request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block : default_streamer) + request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block : default_streamer) end ## @@ -233,7 +233,7 @@ def attach name, params = {}, &block # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def create params = {}, body = {} - @connection.request(method: :post, path: build_path("/containers/create", params), headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/containers/create", params), headers: {"Content-Type": "application/json"}, body: body.to_json) end ## @@ -248,9 +248,9 @@ def create params = {}, body = {} def stats name, params = {}, &block path = build_path("/containers/#{name}/stats", params) if [true, 1 ].include? params[:stream] - @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer) + request(method: :get, path: path , response_block: block_given? ? block : default_streamer) else - @connection.get(path) + get(path) end end @@ -266,7 +266,7 @@ def stats name, params = {}, &block def export name, path, &block response = self.details(name) return response unless response.status == 200 - @connection.request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block : default_writer(path)) + request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block : default_writer(path)) end ## @@ -282,11 +282,11 @@ def export name, path, &block # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default file writing behavior. def get_archive name, path, params = {}, &block - response = @connection.head(build_path("/containers/#{name}/archive", params)) + response = head(build_path("/containers/#{name}/archive", params)) return response unless response.status == 200 file = File.open( File.expand_path( path ) , "wb") - response = @connection.request(method: :get, path: build_path("/containers/#{name}/archive", params) , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) }) + response = request(method: :get, path: build_path("/containers/#{name}/archive", params) , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) }) file.close response end @@ -304,7 +304,7 @@ def get_archive name, path, params = {}, &block # @param params [Hash]: Parameters that are appended to the URL. def put_archive name, path, params = {} file = File.open( File.expand_path( path ) , "r") - response = @connection.request(method: :put, path: build_path("/containers/#{name}/archive", params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} ) + response = request(method: :put, path: build_path("/containers/#{name}/archive", params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} ) file.close response end diff --git a/lib/docker/api/exec.rb b/lib/docker/api/exec.rb index ddd7745..191c6ab 100644 --- a/lib/docker/api/exec.rb +++ b/lib/docker/api/exec.rb @@ -12,7 +12,7 @@ class Docker::API::Exec < Docker::API::Base # @param name [String]: The ID or name of the container. # @param body [Hash]: Request body to be sent as json. def create name, body = {} - @connection.request(method: :post, path: build_path("/containers/#{name}/exec"), headers: {"Content-Type": "application/json"}, body: body.to_json ) + request(method: :post, path: build_path("/containers/#{name}/exec"), headers: {"Content-Type": "application/json"}, body: body.to_json ) end ## @@ -25,7 +25,7 @@ def create name, body = {} # @param body [Hash]: Request body to be sent as json. # @param &block: Replace the default output to stdout behavior. def start name, body = {}, &block - @connection.request(method: :post, path: build_path("/exec/#{name}/start"), headers: {"Content-Type": "application/json"}, body: body.to_json, + request(method: :post, path: build_path("/exec/#{name}/start"), headers: {"Content-Type": "application/json"}, body: body.to_json, response_block: block_given? ? block : default_streamer ) end @@ -38,7 +38,7 @@ def start name, body = {}, &block # @param name [String]: Exec instance ID. # @param body [Hash]: Request body to be sent as json. def resize name, params = {} - @connection.post(build_path("/exec/#{name}/resize", params)) + post(build_path("/exec/#{name}/resize", params)) end ## @@ -49,7 +49,7 @@ def resize name, params = {} # # @param name [String]: Exec instance ID. def details name - @connection.get(build_path("/exec/#{name}/json")) + get(build_path("/exec/#{name}/json")) end end \ No newline at end of file diff --git a/lib/docker/api/image.rb b/lib/docker/api/image.rb index 0cde0ef..c2bf0f3 100644 --- a/lib/docker/api/image.rb +++ b/lib/docker/api/image.rb @@ -11,7 +11,7 @@ class Docker::API::Image < Docker::API::Base # # @param name [String]: The ID or name of the image. def details name - @connection.get(build_path("/images/#{name}/json")) + get(build_path("/images/#{name}/json")) end ## @@ -25,7 +25,7 @@ def details name def distribution name, authentication = {} request = {method: :get, path: build_path("/distribution/#{name}/json")} request[:headers] = {"X-Registry-Auth" => auth_encoder(authentication)} if authentication.any? - @connection.request(request) + request(request) end ## @@ -36,7 +36,7 @@ def distribution name, authentication = {} # # @param name [String]: The ID or name of the image. def history name - @connection.get(build_path("/images/#{name}/history")) + get(build_path("/images/#{name}/history")) end ## @@ -47,7 +47,7 @@ def history name # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/images/json", params)) + get(build_path("/images/json", params)) end ## @@ -58,7 +58,7 @@ def list params = {} # # @param params [Hash]: Parameters that are appended to the URL. def search params = {} - @connection.get(build_path("/images/search", params)) + get(build_path("/images/search", params)) end ## @@ -70,7 +70,7 @@ def search params = {} # @param name [String]: The ID or name of the image. # @param params [Hash]: Parameters that are appended to the URL. def tag name, params = {} - @connection.post(build_path("/images/#{name}/tag", params)) + post(build_path("/images/#{name}/tag", params)) end ## @@ -81,7 +81,7 @@ def tag name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - @connection.post(build_path("/images/prune", params)) + post(build_path("/images/prune", params)) end ## @@ -95,7 +95,7 @@ def prune params = {} # @param name [String]: The ID or name of the image. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - @connection.delete(build_path("/images/#{name}", params)) + delete(build_path("/images/#{name}", params)) end ## @@ -108,7 +108,7 @@ def remove name, params = {} # @param path [String]: Path to the exported file. # @param &block: Replace the default file writing behavior. def export name, path, &block - @connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block : default_writer(path)) + request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block : default_writer(path)) end ## @@ -134,7 +134,7 @@ def import path, params = {} # @param authentication [Hash]: Authentication parameters. def push name, params = {}, authentication = {} raise StandardError.new("Provide authentication parameters to push an image") unless authentication.any? - @connection.request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => auth_encoder(authentication) } ) + request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => auth_encoder(authentication) } ) end ## @@ -148,7 +148,7 @@ def push name, params = {}, authentication = {} def commit params = {}, body = {} container = Docker::API::Container.new(@connection).details(params[:container]) return container if [404, 301].include? container.status - @connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json) + request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json) end ## @@ -168,7 +168,7 @@ def create params = {}, authentication = {}, &block default_reader(path, build_path("/images/create", params)) else request[:headers] = { "X-Registry-Auth" => auth_encoder(authentication) } if authentication.any? - @connection.request(request) + request(request) end end @@ -189,7 +189,7 @@ def build path, params = {}, authentication = {}, &block headers.merge!({"X-Registry-Config": auth_encoder(authentication) }) if authentication.any? if path == nil and params.has_key? :remote - response = @connection.request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block : default_streamer) + response = request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block : default_streamer) else default_reader(path, build_path("/build", params), headers) end @@ -203,6 +203,6 @@ def build path, params = {}, authentication = {}, &block # # @param params [Hash]: Parameters that are appended to the URL. def delete_cache params = {} - @connection.post(build_path("/build/prune", params)) + post(build_path("/build/prune", params)) end end \ No newline at end of file diff --git a/lib/docker/api/network.rb b/lib/docker/api/network.rb index 48c3ddb..739c795 100644 --- a/lib/docker/api/network.rb +++ b/lib/docker/api/network.rb @@ -11,7 +11,7 @@ class Docker::API::Network < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/networks", params)) + get(build_path("/networks", params)) end ## @@ -23,7 +23,7 @@ def list params = {} # @param name [String]: The ID or name of the network. # @param params [Hash]: Parameters that are appended to the URL. def details name, params = {} - @connection.get(build_path("/networks/#{name}", params)) + get(build_path("/networks/#{name}", params)) end ## @@ -34,7 +34,7 @@ def details name, params = {} # # @param body [Hash]: Request body to be sent as json. def create body = {} - @connection.request(method: :post, path: build_path("/networks/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/networks/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -45,7 +45,7 @@ def create body = {} # # @param name [String]: The ID or name of the network. def remove name - @connection.delete(build_path("/networks/#{name}")) + delete(build_path("/networks/#{name}")) end ## @@ -56,7 +56,7 @@ def remove name # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - @connection.post(build_path("/networks/prune", params)) + post(build_path("/networks/prune", params)) end ## @@ -68,7 +68,7 @@ def prune params = {} # @param name [String]: The ID or name of the network. # @param body [Hash]: Request body to be sent as json. def connect name, body = {} - @connection.request(method: :post, path: build_path("/networks/#{name}/connect"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/networks/#{name}/connect"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -80,7 +80,7 @@ def connect name, body = {} # @param name [String]: The ID or name of the network. # @param body [Hash]: Request body to be sent as json. def disconnect name, body = {} - @connection.request(method: :post, path: build_path("/networks/#{name}/disconnect"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/networks/#{name}/disconnect"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end end \ No newline at end of file diff --git a/lib/docker/api/node.rb b/lib/docker/api/node.rb index 597013e..29b7cf0 100644 --- a/lib/docker/api/node.rb +++ b/lib/docker/api/node.rb @@ -12,7 +12,7 @@ class Docker::API::Node < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/nodes", params)) + get(build_path("/nodes", params)) end ## @@ -25,7 +25,7 @@ def list params = {} # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def update name, params = {}, body = {} - @connection.request(method: :post, path: build_path("/nodes/#{name}/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/nodes/#{name}/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -37,7 +37,7 @@ def update name, params = {}, body = {} # @param name [String]: The ID or name of the node. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - @connection.delete(build_path("/nodes/#{name}", params)) + delete(build_path("/nodes/#{name}", params)) end ## @@ -48,6 +48,6 @@ def remove name, params = {} # # @param name [String]: The ID or name of the node. def details name - @connection.get(build_path("/nodes/#{name}")) + get(build_path("/nodes/#{name}")) end end \ No newline at end of file diff --git a/lib/docker/api/plugin.rb b/lib/docker/api/plugin.rb index ff8a86e..db05762 100644 --- a/lib/docker/api/plugin.rb +++ b/lib/docker/api/plugin.rb @@ -11,7 +11,7 @@ class Docker::API::Plugin < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/plugins", params)) + get(build_path("/plugins", params)) end # Get plugin privileges @@ -22,7 +22,7 @@ def list params = {} # # @param params [Hash]: Parameters that are appended to the URL. def privileges params = {} - @connection.get(build_path("/plugins/privileges", params)) + get(build_path("/plugins/privileges", params)) end # Install a plugin @@ -41,7 +41,7 @@ def privileges params = {} def install params = {}, privileges = [], authentication = {} headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0 - @connection.request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json ) + request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json ) end # Inspect a plugin @@ -52,7 +52,7 @@ def install params = {}, privileges = [], authentication = {} # # @param name [String]: The ID or name of the plugin. def details name - @connection.get(build_path("/plugins/#{name}/json")) + get(build_path("/plugins/#{name}/json")) end # Remove a plugin @@ -65,7 +65,7 @@ def details name # # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - @connection.delete(build_path("/plugins/#{name}",params)) + delete(build_path("/plugins/#{name}",params)) end # Enable a plugin @@ -78,7 +78,7 @@ def remove name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def enable name, params = {} - @connection.post(build_path("/plugins/#{name}/enable", params)) + post(build_path("/plugins/#{name}/enable", params)) end # Disable a plugin @@ -89,7 +89,7 @@ def enable name, params = {} # # @param name [String]: The ID or name of the plugin. def disable name - @connection.post(build_path("/plugins/#{name}/disable")) + post(build_path("/plugins/#{name}/disable")) end # Upgrade a plugin @@ -108,7 +108,7 @@ def disable name def upgrade name, params = {}, privileges = [], authentication = {} headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0 - @connection.request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json ) + request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json ) end # Create a plugin @@ -122,7 +122,7 @@ def upgrade name, params = {}, privileges = [], authentication = {} # @param path [String]: Path to tar file that contains rootfs folder and config.json file. def create name, path file = File.open( File.expand_path( path ) , "r") - response = @connection.request(method: :post, path: build_path("/plugins/create?name=#{name}"), body: file.read.to_s ) + response = request(method: :post, path: build_path("/plugins/create?name=#{name}"), body: file.read.to_s ) file.close response end @@ -138,9 +138,9 @@ def create name, path # @param authentication [Hash]: Authentication parameters. def push name, authentication = {} if authentication.keys.size > 0 - @connection.request(method: :post, path: build_path("/plugins/#{name}/push"), headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) + request(method: :post, path: build_path("/plugins/#{name}/push"), headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) else - @connection.post(build_path("/plugins/#{name}/push")) + post(build_path("/plugins/#{name}/push")) end end @@ -154,7 +154,7 @@ def push name, authentication = {} # # @param config [Array]: Plugin configuration to be sent as json in request body. def configure name, config - @connection.request(method: :post, path: build_path("/plugins/#{name}/set"), headers: {"Content-Type" => "application/json"}, body:config.to_json) + request(method: :post, path: build_path("/plugins/#{name}/set"), headers: {"Content-Type" => "application/json"}, body:config.to_json) end end \ No newline at end of file diff --git a/lib/docker/api/secret.rb b/lib/docker/api/secret.rb index a46eee6..a9e0179 100644 --- a/lib/docker/api/secret.rb +++ b/lib/docker/api/secret.rb @@ -11,7 +11,7 @@ class Docker::API::Secret < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/secrets",params)) + get(build_path("/secrets",params)) end # Create a secret @@ -21,7 +21,7 @@ def list params = {} # # @param body [Hash]: Request body to be sent as json. def create body = {} - @connection.request(method: :post, path: build_path("/secrets/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/secrets/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end # Inspect a secret @@ -31,7 +31,7 @@ def create body = {} # # @param name [String]: The ID or name of the secret. def details name - @connection.get(build_path("/secrets/#{name}")) + get(build_path("/secrets/#{name}")) end # Update a secret @@ -43,7 +43,7 @@ def details name # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def update name, params = {}, body = {} - @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type" => "application/json"}, body: body.to_json) end # Delete a secret @@ -53,6 +53,6 @@ def update name, params = {}, body = {} # # @param name [String]: The ID or name of the secret. def remove name - @connection.delete(build_path("/secrets/#{name}")) + delete(build_path("/secrets/#{name}")) end end \ No newline at end of file diff --git a/lib/docker/api/service.rb b/lib/docker/api/service.rb index 48a6a6d..4242fde 100644 --- a/lib/docker/api/service.rb +++ b/lib/docker/api/service.rb @@ -11,7 +11,7 @@ class Docker::API::Service < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/services", params)) + get(build_path("/services", params)) end # Create a service @@ -24,7 +24,7 @@ def list params = {} def create body = {}, authentication = {} headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0 - @connection.request(method: :post, path: build_path("/services/create"), headers: headers, body: body.to_json) + request(method: :post, path: build_path("/services/create"), headers: headers, body: body.to_json) end # Update a service @@ -40,7 +40,7 @@ def update name, params = {}, body = {}, authentication = {} # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719 headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0 - @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json) + request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json) end # Inspect a service @@ -51,7 +51,7 @@ def update name, params = {}, body = {}, authentication = {} # @param name [String]: The ID or name of the service. # @param params [Hash]: Parameters that are appended to the URL. def details name, params = {} - @connection.get(build_path("/services/#{name}", params)) + get(build_path("/services/#{name}", params)) end # Get stdout and stderr logs from a service. @@ -62,7 +62,7 @@ def details name, params = {} # @param name [String]: The ID or name of the service. # @param params [Hash]: Parameters that are appended to the URL. def logs name, params = {} - @connection.get(build_path("/services/#{name}/logs", params)) + get(build_path("/services/#{name}/logs", params)) end # Delete a service @@ -72,6 +72,6 @@ def logs name, params = {} # # @param name [String]: The ID or name of the service. def remove name - @connection.delete(build_path("/services/#{name}")) + delete(build_path("/services/#{name}")) end end diff --git a/lib/docker/api/swarm.rb b/lib/docker/api/swarm.rb index e83bea0..d53f50e 100644 --- a/lib/docker/api/swarm.rb +++ b/lib/docker/api/swarm.rb @@ -11,7 +11,7 @@ class Docker::API::Swarm < Docker::API::Base # # @param body [Hash]: Request body to be sent as json. def init body = {} - @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -23,7 +23,7 @@ def init body = {} # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def update params = {}, body = {} - @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -32,7 +32,7 @@ def update params = {}, body = {} # Docker API: GET /swarm # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInspect def details - @connection.get(build_path("/swarm")) + get(build_path("/swarm")) end ## @@ -41,7 +41,7 @@ def details # Docker API: GET /swarm/unlockkey # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlockkey def unlock_key - @connection.get(build_path("/swarm/unlockkey")) + get(build_path("/swarm/unlockkey")) end ## @@ -52,7 +52,7 @@ def unlock_key # # @param body [Hash]: Request body to be sent as json. def unlock body = {} - @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -63,7 +63,7 @@ def unlock body = {} # # @param body [Hash]: Request body to be sent as json. def join body = {} - @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -74,6 +74,6 @@ def join body = {} # # @param params [Hash]: Parameters that are appended to the URL. def leave params = {} - @connection.post(build_path("/swarm/leave", params)) + post(build_path("/swarm/leave", params)) end end \ No newline at end of file diff --git a/lib/docker/api/system.rb b/lib/docker/api/system.rb index 430d4e2..05ef00c 100644 --- a/lib/docker/api/system.rb +++ b/lib/docker/api/system.rb @@ -11,7 +11,7 @@ class Docker::API::System < Docker::API::Base # # @param body [Hash]: Request body to be sent as json. def auth body = {} - @connection.request(method: :post, path: build_path("/auth"), headers: { "Content-Type" => "application/json" }, body: body.to_json) + request(method: :post, path: build_path("/auth"), headers: { "Content-Type" => "application/json" }, body: body.to_json) end ## @@ -23,7 +23,7 @@ def auth body = {} # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default output to stdout behavior. def events params = {}, &block - @connection.request(method: :get, path: build_path("/events", params), response_block: block_given? ? block : default_streamer ) + request(method: :get, path: build_path("/events", params), response_block: block_given? ? block : default_streamer ) end ## @@ -32,7 +32,7 @@ def events params = {}, &block # Docker API: GET /_ping # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemPing def ping - @connection.get(build_path("/_ping")) + get(build_path("/_ping")) end ## @@ -41,7 +41,7 @@ def ping # Docker API: GET /info # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemInfo def info - @connection.get(build_path("/info")) + get(build_path("/info")) end ## @@ -50,7 +50,7 @@ def info # Docker API: GET /version # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemVersion def version - @connection.get(build_path("/version")) + get(build_path("/version")) end ## @@ -59,7 +59,7 @@ def version # Docker API: GET /system/df # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemDataUsage def df params = {} - @connection.get(build_path("/system/df", params)) + get(build_path("/system/df", params)) end end \ No newline at end of file diff --git a/lib/docker/api/task.rb b/lib/docker/api/task.rb index cee912b..ed49391 100644 --- a/lib/docker/api/task.rb +++ b/lib/docker/api/task.rb @@ -11,7 +11,7 @@ class Docker::API::Task < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/tasks",params)) + get(build_path("/tasks",params)) end # Inspect a task @@ -21,7 +21,7 @@ def list params = {} # # @param name [String]: The ID or name of the task. def details name - @connection.get(build_path("/tasks/#{name}")) + get(build_path("/tasks/#{name}")) end # Get stdout and stderr logs from a task. @@ -36,9 +36,9 @@ def logs name, params = {}, &block path = build_path("/tasks/#{name}/logs", params) if [true, 1 ].include? params[:follow] - @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer) + request(method: :get, path: path , response_block: block_given? ? block : default_streamer) else - @connection.get(path) + get(path) end end end \ No newline at end of file diff --git a/lib/docker/api/volume.rb b/lib/docker/api/volume.rb index c993918..876d487 100644 --- a/lib/docker/api/volume.rb +++ b/lib/docker/api/volume.rb @@ -11,7 +11,7 @@ class Docker::API::Volume < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - @connection.get(build_path("/volumes", params)) + get(build_path("/volumes", params)) end ## @@ -22,7 +22,7 @@ def list params = {} # # @param name [String]: The ID or name of the volume. def details name - @connection.get(build_path("/volumes/#{name}")) + get(build_path("/volumes/#{name}")) end ## @@ -33,7 +33,7 @@ def details name # # @param body [Hash]: Request body to be sent as json. def create body = {} - @connection.request(method: :post, path: build_path("/volumes/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: build_path("/volumes/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -45,7 +45,7 @@ def create body = {} # @param name [String]: The ID or name of the volume. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - @connection.delete(build_path("/volumes/#{name}",params)) + delete(build_path("/volumes/#{name}",params)) end ## @@ -56,6 +56,6 @@ def remove name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - @connection.post(build_path("/volumes/prune", params)) + post(build_path("/volumes/prune", params)) end end From 40ccda21f1c08b71568524a566949ea59b4e3e82 Mon Sep 17 00:00:00 2001 From: nu12 <34694287+nu12@users.noreply.github.com> Date: Tue, 26 Aug 2025 13:45:20 -0400 Subject: [PATCH 2/2] Fix config endpoint for update --- Gemfile.lock | 2 +- README.md | 2 +- lib/docker/api/base.rb | 7 +++-- lib/docker/api/config.rb | 10 +++--- lib/docker/api/container.rb | 59 +++++++++++++++++------------------ lib/docker/api/exec.rb | 8 ++--- lib/docker/api/image.rb | 36 ++++++++++----------- lib/docker/api/network.rb | 14 ++++----- lib/docker/api/node.rb | 8 ++--- lib/docker/api/plugin.rb | 24 +++++++------- lib/docker/api/secret.rb | 10 +++--- lib/docker/api/service.rb | 12 +++---- lib/docker/api/swarm.rb | 14 ++++----- lib/docker/api/system.rb | 12 +++---- lib/docker/api/task.rb | 10 +++--- lib/docker/api/version.rb | 2 +- lib/docker/api/volume.rb | 10 +++--- spec/endpoints/config_spec.rb | 2 +- 18 files changed, 121 insertions(+), 121 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b8be097..2f4dac3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dockerapi (0.22.0) + dockerapi (0.22.1) base64 excon (>= 0.97, < 2) diff --git a/README.md b/README.md index 11e5c35..4691d12 100644 --- a/README.md +++ b/README.md @@ -592,7 +592,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To * Update version. * Run tests. * Commit changes. -* Release / push version to Rubygems & Github. +* Push a new Github tag with `git tag $(bundle exec rake version | tr -d '"') && git push --tags`. ## Contributing diff --git a/lib/docker/api/base.rb b/lib/docker/api/base.rb index b162d44..de01cac 100644 --- a/lib/docker/api/base.rb +++ b/lib/docker/api/base.rb @@ -2,7 +2,7 @@ # Base class to provide general methods, helpers and implementations accross classes. class Docker::API::Base [:get, :post, :head, :delete, :put].each do | method | - define_method(method) { | path | self.request(method: method, path: path) } + define_method(method) { | path, params = {} | self.request(method: method, path: path, params: params) } end ## @@ -10,6 +10,7 @@ class Docker::API::Base # # @param params [Hash]: Request parameters. def request params + params[:path] = build_path(params[:path], params[:params] ||= {}) response = Docker::API::Response.new(@connection.excon.request(params).data) response.request_params = params p response if Docker::API.print_response_to_stdout @@ -57,9 +58,9 @@ def default_writer path # @param url [String]: Endpoint URL where the file is going to be sent. # @param header [Hash]: Header of the request. # @param &block: Replace the default output to stdout behavior. - def default_reader path, url, header = {"Content-Type" => "application/x-tar"}, &block + def default_reader path, base_url, params, header = {"Content-Type" => "application/x-tar"}, &block file = File.open(File.expand_path(path), "r") - response = request(method: :post, path: url , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block : default_streamer ) + response = request(method: :post, path: base_url, params: params , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block : default_streamer ) file.close response end diff --git a/lib/docker/api/config.rb b/lib/docker/api/config.rb index e8002da..8d543d8 100644 --- a/lib/docker/api/config.rb +++ b/lib/docker/api/config.rb @@ -13,7 +13,7 @@ class Docker::API::Config < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/configs",params)) + get("/configs", params) end # Create a config @@ -24,7 +24,7 @@ def list params = {} # # @param body [Hash]: Request body to be sent as json. def create body = {} - request(method: :post, path: "/v#{Docker::API::API_VERSION}/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: "/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json) end # Inspect a config @@ -35,7 +35,7 @@ def create body = {} # # @param name [String]: The ID or name of the config. def details name - get("/v#{Docker::API::API_VERSION}/configs/#{name}") + get("/configs/#{name}") end # Update a config @@ -50,7 +50,7 @@ def details name # # @param body [Hash]: Request body to be sent as json. def update name, params = {}, body = {} - request(method: :post, path: build_path("/v#{Docker::API::API_VERSION}/configs/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: "/configs/#{name}/update", params: params, headers: {"Content-Type": "application/json"}, body: body.to_json) end # Delete a config @@ -61,6 +61,6 @@ def update name, params = {}, body = {} # # @param name [String]: The ID or name of the config. def remove name - delete("/v#{Docker::API::API_VERSION}/configs/#{name}") + delete("/configs/#{name}") end end \ No newline at end of file diff --git a/lib/docker/api/container.rb b/lib/docker/api/container.rb index 0cbdaeb..6dffcc0 100644 --- a/lib/docker/api/container.rb +++ b/lib/docker/api/container.rb @@ -11,7 +11,7 @@ class Docker::API::Container < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/containers/json", params)) + get("/containers/json", params) end ## @@ -23,7 +23,7 @@ def list params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def details name, params = {} - get(build_path("/containers/#{name}/json", params)) + get("/containers/#{name}/json", params) end ## @@ -35,7 +35,7 @@ def details name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def top name, params = {} - get(build_path("/containers/#{name}/top", params)) + get("/containers/#{name}/top", params) end ## @@ -46,7 +46,7 @@ def top name, params = {} # # @param name [String]: The ID or name of the container. def changes name - get(build_path("/containers/#{name}/changes")) + get("/containers/#{name}/changes") end ## @@ -58,7 +58,7 @@ def changes name # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def start name, params = {} - post(build_path("/containers/#{name}/start", params)) + post("/containers/#{name}/start", params) end ## @@ -70,7 +70,7 @@ def start name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def stop name, params = {} - post(build_path("/containers/#{name}/stop", params)) + post("/containers/#{name}/stop", params) end ## @@ -82,7 +82,7 @@ def stop name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def restart name, params = {} - post(build_path("/containers/#{name}/restart", params)) + post("/containers/#{name}/restart", params) end ## @@ -94,7 +94,7 @@ def restart name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def kill name, params = {} - post(build_path("/containers/#{name}/kill", params)) + post("/containers/#{name}/kill", params) end ## @@ -106,7 +106,7 @@ def kill name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def wait name, params = {} - post(build_path("/containers/#{name}/wait", params)) + post("/containers/#{name}/wait", params) end ## @@ -118,8 +118,7 @@ def wait name, params = {} # @param name [String]: The ID or name of the container. # @param body [Hash]: Request body to be sent as json. def update name, body = {} - - request(method: :post, path: build_path("/containers/#{name}/update"), headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: "/containers/#{name}/update", headers: {"Content-Type": "application/json"}, body: body.to_json) end ## @@ -131,7 +130,7 @@ def update name, body = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def rename name, params = {} - post(build_path("/containers/#{name}/rename", params)) + post("/containers/#{name}/rename", params) end ## @@ -143,7 +142,7 @@ def rename name, params = {} # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def resize name, params = {} - post(build_path("/containers/#{name}/resize", params)) + post("/containers/#{name}/resize", params) end ## @@ -154,7 +153,7 @@ def resize name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - post(build_path("/containers/prune", params)) + post("/containers/prune", params) end ## @@ -165,7 +164,7 @@ def prune params = {} # # @param name [String]: The ID or name of the container. def pause name - post(build_path("/containers/#{name}/pause")) + post("/containers/#{name}/pause") end ## @@ -176,7 +175,7 @@ def pause name # # @param name [String]: The ID or name of the container. def unpause name - post(build_path("/containers/#{name}/unpause")) + post("/containers/#{name}/unpause") end ## @@ -188,7 +187,7 @@ def unpause name # @param name [String]: The ID or name of the container. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - delete(build_path("/containers/#{name}", params)) + delete("/containers/#{name}", params) end ## @@ -201,13 +200,12 @@ def remove name, params = {} # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default output to stdout behavior. def logs name, params = {}, &block - - path = build_path("/containers/#{name}/logs", params) + path = "/containers/#{name}/logs" if [true, 1 ].include? params[:follow] - request(method: :get, path: path , response_block: block_given? ? block : default_streamer) + request(method: :get, path: path, params: params, response_block: block_given? ? block : default_streamer) else - get(path) + get(path, params) end end @@ -221,7 +219,7 @@ def logs name, params = {}, &block # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default output to stdout behavior. def attach name, params = {}, &block - request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block : default_streamer) + request(method: :post, path: "/containers/#{name}/attach", params: params , response_block: block_given? ? block : default_streamer) end ## @@ -233,7 +231,7 @@ def attach name, params = {}, &block # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def create params = {}, body = {} - request(method: :post, path: build_path("/containers/create", params), headers: {"Content-Type": "application/json"}, body: body.to_json) + request(method: :post, path: "/containers/create", params: params, headers: {"Content-Type": "application/json"}, body: body.to_json) end ## @@ -246,11 +244,12 @@ def create params = {}, body = {} # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default output to stdout behavior. def stats name, params = {}, &block - path = build_path("/containers/#{name}/stats", params) + path = "/containers/#{name}/stats" + if [true, 1 ].include? params[:stream] - request(method: :get, path: path , response_block: block_given? ? block : default_streamer) + request(method: :get, path: path, params: params, response_block: block_given? ? block : default_streamer) else - get(path) + get(path, params) end end @@ -266,7 +265,7 @@ def stats name, params = {}, &block def export name, path, &block response = self.details(name) return response unless response.status == 200 - request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block : default_writer(path)) + request(method: :get, path: "/containers/#{name}/export", response_block: block_given? ? block : default_writer(path)) end ## @@ -282,11 +281,11 @@ def export name, path, &block # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default file writing behavior. def get_archive name, path, params = {}, &block - response = head(build_path("/containers/#{name}/archive", params)) + response = head("/containers/#{name}/archive", params) return response unless response.status == 200 file = File.open( File.expand_path( path ) , "wb") - response = request(method: :get, path: build_path("/containers/#{name}/archive", params) , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) }) + response = request(method: :get, path: "/containers/#{name}/archive", params: params , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) }) file.close response end @@ -304,7 +303,7 @@ def get_archive name, path, params = {}, &block # @param params [Hash]: Parameters that are appended to the URL. def put_archive name, path, params = {} file = File.open( File.expand_path( path ) , "r") - response = request(method: :put, path: build_path("/containers/#{name}/archive", params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} ) + response = request(method: :put, path: "/containers/#{name}/archive", params: params , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} ) file.close response end diff --git a/lib/docker/api/exec.rb b/lib/docker/api/exec.rb index 191c6ab..6c7edab 100644 --- a/lib/docker/api/exec.rb +++ b/lib/docker/api/exec.rb @@ -12,7 +12,7 @@ class Docker::API::Exec < Docker::API::Base # @param name [String]: The ID or name of the container. # @param body [Hash]: Request body to be sent as json. def create name, body = {} - request(method: :post, path: build_path("/containers/#{name}/exec"), headers: {"Content-Type": "application/json"}, body: body.to_json ) + request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json ) end ## @@ -25,7 +25,7 @@ def create name, body = {} # @param body [Hash]: Request body to be sent as json. # @param &block: Replace the default output to stdout behavior. def start name, body = {}, &block - request(method: :post, path: build_path("/exec/#{name}/start"), headers: {"Content-Type": "application/json"}, body: body.to_json, + request(method: :post, path: "/exec/#{name}/start", headers: {"Content-Type": "application/json"}, body: body.to_json, response_block: block_given? ? block : default_streamer ) end @@ -38,7 +38,7 @@ def start name, body = {}, &block # @param name [String]: Exec instance ID. # @param body [Hash]: Request body to be sent as json. def resize name, params = {} - post(build_path("/exec/#{name}/resize", params)) + post("/exec/#{name}/resize", params) end ## @@ -49,7 +49,7 @@ def resize name, params = {} # # @param name [String]: Exec instance ID. def details name - get(build_path("/exec/#{name}/json")) + get("/exec/#{name}/json") end end \ No newline at end of file diff --git a/lib/docker/api/image.rb b/lib/docker/api/image.rb index c2bf0f3..ac44983 100644 --- a/lib/docker/api/image.rb +++ b/lib/docker/api/image.rb @@ -11,7 +11,7 @@ class Docker::API::Image < Docker::API::Base # # @param name [String]: The ID or name of the image. def details name - get(build_path("/images/#{name}/json")) + get("/images/#{name}/json") end ## @@ -23,7 +23,7 @@ def details name # @param name [String]: The ID or name of the image. # @param authentication [Hash]: Authentication parameters. def distribution name, authentication = {} - request = {method: :get, path: build_path("/distribution/#{name}/json")} + request = {method: :get, path: "/distribution/#{name}/json"} request[:headers] = {"X-Registry-Auth" => auth_encoder(authentication)} if authentication.any? request(request) end @@ -36,7 +36,7 @@ def distribution name, authentication = {} # # @param name [String]: The ID or name of the image. def history name - get(build_path("/images/#{name}/history")) + get("/images/#{name}/history") end ## @@ -47,7 +47,7 @@ def history name # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/images/json", params)) + get("/images/json", params) end ## @@ -58,7 +58,7 @@ def list params = {} # # @param params [Hash]: Parameters that are appended to the URL. def search params = {} - get(build_path("/images/search", params)) + get("/images/search", params) end ## @@ -70,7 +70,7 @@ def search params = {} # @param name [String]: The ID or name of the image. # @param params [Hash]: Parameters that are appended to the URL. def tag name, params = {} - post(build_path("/images/#{name}/tag", params)) + post("/images/#{name}/tag", params) end ## @@ -81,7 +81,7 @@ def tag name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - post(build_path("/images/prune", params)) + post("/images/prune", params) end ## @@ -95,7 +95,7 @@ def prune params = {} # @param name [String]: The ID or name of the image. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - delete(build_path("/images/#{name}", params)) + delete("/images/#{name}", params) end ## @@ -108,7 +108,7 @@ def remove name, params = {} # @param path [String]: Path to the exported file. # @param &block: Replace the default file writing behavior. def export name, path, &block - request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block : default_writer(path)) + request(method: :get, path: "/images/#{name}/get" , response_block: block_given? ? block : default_writer(path)) end ## @@ -117,10 +117,10 @@ def export name, path, &block # Docker API: POST /images/load # @see https://docs.docker.com/engine/api/v1.40/#operation/ImageLoad # - # @param name [String]: The ID or name of the image. + # @param path [String]: Path to the file to be read. # @param params [Hash]: Parameters that are appended to the URL. def import path, params = {} - default_reader(path, build_path("/images/load", params)) + default_reader(path, "/images/load", params) end ## @@ -134,7 +134,7 @@ def import path, params = {} # @param authentication [Hash]: Authentication parameters. def push name, params = {}, authentication = {} raise StandardError.new("Provide authentication parameters to push an image") unless authentication.any? - request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => auth_encoder(authentication) } ) + request(method: :post, path: "/images/#{name}/push", params: params, headers: { "X-Registry-Auth" => auth_encoder(authentication) } ) end ## @@ -148,7 +148,7 @@ def push name, params = {}, authentication = {} def commit params = {}, body = {} container = Docker::API::Container.new(@connection).details(params[:container]) return container if [404, 301].include? container.status - request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json) + request(method: :post, path: "/commit", params: params, headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json) end ## @@ -161,11 +161,11 @@ def commit params = {}, body = {} # @param authentication [Hash]: Authentication parameters. # @param &block: Replace the default output to stdout behavior. def create params = {}, authentication = {}, &block - request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block : default_streamer } + request = {method: :post, path: "/images/create", params: params, response_block: block_given? ? block : default_streamer } if params.has_key? :fromSrc and !params[:fromSrc].match(/^(http|https)/) # then it's using a tar file path = params[:fromSrc] params[:fromSrc] = "-" - default_reader(path, build_path("/images/create", params)) + default_reader(path, "/images/create", params) else request[:headers] = { "X-Registry-Auth" => auth_encoder(authentication) } if authentication.any? request(request) @@ -189,9 +189,9 @@ def build path, params = {}, authentication = {}, &block headers.merge!({"X-Registry-Config": auth_encoder(authentication) }) if authentication.any? if path == nil and params.has_key? :remote - response = request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block : default_streamer) + response = request(method: :post, path: "/build", params: params, headers: headers, response_block: block_given? ? block : default_streamer) else - default_reader(path, build_path("/build", params), headers) + default_reader(path, "/build", params, headers) end end @@ -203,6 +203,6 @@ def build path, params = {}, authentication = {}, &block # # @param params [Hash]: Parameters that are appended to the URL. def delete_cache params = {} - post(build_path("/build/prune", params)) + post("/build/prune", params) end end \ No newline at end of file diff --git a/lib/docker/api/network.rb b/lib/docker/api/network.rb index 739c795..f54f8b8 100644 --- a/lib/docker/api/network.rb +++ b/lib/docker/api/network.rb @@ -11,7 +11,7 @@ class Docker::API::Network < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/networks", params)) + get("/networks", params) end ## @@ -23,7 +23,7 @@ def list params = {} # @param name [String]: The ID or name of the network. # @param params [Hash]: Parameters that are appended to the URL. def details name, params = {} - get(build_path("/networks/#{name}", params)) + get("/networks/#{name}", params) end ## @@ -34,7 +34,7 @@ def details name, params = {} # # @param body [Hash]: Request body to be sent as json. def create body = {} - request(method: :post, path: build_path("/networks/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/networks/create", headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -45,7 +45,7 @@ def create body = {} # # @param name [String]: The ID or name of the network. def remove name - delete(build_path("/networks/#{name}")) + delete("/networks/#{name}") end ## @@ -56,7 +56,7 @@ def remove name # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - post(build_path("/networks/prune", params)) + post("/networks/prune", params) end ## @@ -68,7 +68,7 @@ def prune params = {} # @param name [String]: The ID or name of the network. # @param body [Hash]: Request body to be sent as json. def connect name, body = {} - request(method: :post, path: build_path("/networks/#{name}/connect"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/networks/#{name}/connect", headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -80,7 +80,7 @@ def connect name, body = {} # @param name [String]: The ID or name of the network. # @param body [Hash]: Request body to be sent as json. def disconnect name, body = {} - request(method: :post, path: build_path("/networks/#{name}/disconnect"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/networks/#{name}/disconnect", headers: {"Content-Type" => "application/json"}, body: body.to_json) end end \ No newline at end of file diff --git a/lib/docker/api/node.rb b/lib/docker/api/node.rb index 29b7cf0..7d98c48 100644 --- a/lib/docker/api/node.rb +++ b/lib/docker/api/node.rb @@ -12,7 +12,7 @@ class Docker::API::Node < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/nodes", params)) + get("/nodes", params) end ## @@ -25,7 +25,7 @@ def list params = {} # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def update name, params = {}, body = {} - request(method: :post, path: build_path("/nodes/#{name}/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/nodes/#{name}/update", params: params, headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -37,7 +37,7 @@ def update name, params = {}, body = {} # @param name [String]: The ID or name of the node. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - delete(build_path("/nodes/#{name}", params)) + delete("/nodes/#{name}", params) end ## @@ -48,6 +48,6 @@ def remove name, params = {} # # @param name [String]: The ID or name of the node. def details name - get(build_path("/nodes/#{name}")) + get("/nodes/#{name}") end end \ No newline at end of file diff --git a/lib/docker/api/plugin.rb b/lib/docker/api/plugin.rb index db05762..f8b9347 100644 --- a/lib/docker/api/plugin.rb +++ b/lib/docker/api/plugin.rb @@ -11,7 +11,7 @@ class Docker::API::Plugin < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/plugins", params)) + get("/plugins", params) end # Get plugin privileges @@ -22,7 +22,7 @@ def list params = {} # # @param params [Hash]: Parameters that are appended to the URL. def privileges params = {} - get(build_path("/plugins/privileges", params)) + get("/plugins/privileges", params) end # Install a plugin @@ -41,7 +41,7 @@ def privileges params = {} def install params = {}, privileges = [], authentication = {} headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0 - request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json ) + request(method: :post, path: "/plugins/pull", params: params, headers: headers, body: privileges.to_json ) end # Inspect a plugin @@ -52,7 +52,7 @@ def install params = {}, privileges = [], authentication = {} # # @param name [String]: The ID or name of the plugin. def details name - get(build_path("/plugins/#{name}/json")) + get("/plugins/#{name}/json") end # Remove a plugin @@ -65,7 +65,7 @@ def details name # # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - delete(build_path("/plugins/#{name}",params)) + delete("/plugins/#{name}",params) end # Enable a plugin @@ -78,7 +78,7 @@ def remove name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def enable name, params = {} - post(build_path("/plugins/#{name}/enable", params)) + post("/plugins/#{name}/enable", params) end # Disable a plugin @@ -89,7 +89,7 @@ def enable name, params = {} # # @param name [String]: The ID or name of the plugin. def disable name - post(build_path("/plugins/#{name}/disable")) + post("/plugins/#{name}/disable") end # Upgrade a plugin @@ -108,7 +108,7 @@ def disable name def upgrade name, params = {}, privileges = [], authentication = {} headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0 - request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json ) + request(method: :post, path: "/plugins/#{name}/upgrade", params: params, headers: headers, body: privileges.to_json ) end # Create a plugin @@ -122,7 +122,7 @@ def upgrade name, params = {}, privileges = [], authentication = {} # @param path [String]: Path to tar file that contains rootfs folder and config.json file. def create name, path file = File.open( File.expand_path( path ) , "r") - response = request(method: :post, path: build_path("/plugins/create?name=#{name}"), body: file.read.to_s ) + response = request(method: :post, path: "/plugins/create?name=#{name}", body: file.read.to_s ) file.close response end @@ -138,9 +138,9 @@ def create name, path # @param authentication [Hash]: Authentication parameters. def push name, authentication = {} if authentication.keys.size > 0 - request(method: :post, path: build_path("/plugins/#{name}/push"), headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) + request(method: :post, path: "/plugins/#{name}/push", headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) else - post(build_path("/plugins/#{name}/push")) + post("/plugins/#{name}/push") end end @@ -154,7 +154,7 @@ def push name, authentication = {} # # @param config [Array]: Plugin configuration to be sent as json in request body. def configure name, config - request(method: :post, path: build_path("/plugins/#{name}/set"), headers: {"Content-Type" => "application/json"}, body:config.to_json) + request(method: :post, path: "/plugins/#{name}/set", headers: {"Content-Type" => "application/json"}, body:config.to_json) end end \ No newline at end of file diff --git a/lib/docker/api/secret.rb b/lib/docker/api/secret.rb index a9e0179..eddfda3 100644 --- a/lib/docker/api/secret.rb +++ b/lib/docker/api/secret.rb @@ -11,7 +11,7 @@ class Docker::API::Secret < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/secrets",params)) + get("/secrets",params) end # Create a secret @@ -21,7 +21,7 @@ def list params = {} # # @param body [Hash]: Request body to be sent as json. def create body = {} - request(method: :post, path: build_path("/secrets/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/secrets/create", headers: {"Content-Type" => "application/json"}, body: body.to_json) end # Inspect a secret @@ -31,7 +31,7 @@ def create body = {} # # @param name [String]: The ID or name of the secret. def details name - get(build_path("/secrets/#{name}")) + get("/secrets/#{name}") end # Update a secret @@ -43,7 +43,7 @@ def details name # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def update name, params = {}, body = {} - request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/secrets/#{name}/update",params: params, headers: {"Content-Type" => "application/json"}, body: body.to_json) end # Delete a secret @@ -53,6 +53,6 @@ def update name, params = {}, body = {} # # @param name [String]: The ID or name of the secret. def remove name - delete(build_path("/secrets/#{name}")) + delete("/secrets/#{name}") end end \ No newline at end of file diff --git a/lib/docker/api/service.rb b/lib/docker/api/service.rb index 4242fde..058b6ae 100644 --- a/lib/docker/api/service.rb +++ b/lib/docker/api/service.rb @@ -11,7 +11,7 @@ class Docker::API::Service < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/services", params)) + get("/services", params) end # Create a service @@ -24,7 +24,7 @@ def list params = {} def create body = {}, authentication = {} headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0 - request(method: :post, path: build_path("/services/create"), headers: headers, body: body.to_json) + request(method: :post, path: "/services/create", headers: headers, body: body.to_json) end # Update a service @@ -40,7 +40,7 @@ def update name, params = {}, body = {}, authentication = {} # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719 headers = {"Content-Type" => "application/json"} headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0 - request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json) + request(method: :post, path: "/services/#{name}/update", params: params, headers: headers, body: body.to_json) end # Inspect a service @@ -51,7 +51,7 @@ def update name, params = {}, body = {}, authentication = {} # @param name [String]: The ID or name of the service. # @param params [Hash]: Parameters that are appended to the URL. def details name, params = {} - get(build_path("/services/#{name}", params)) + get("/services/#{name}", params) end # Get stdout and stderr logs from a service. @@ -62,7 +62,7 @@ def details name, params = {} # @param name [String]: The ID or name of the service. # @param params [Hash]: Parameters that are appended to the URL. def logs name, params = {} - get(build_path("/services/#{name}/logs", params)) + get("/services/#{name}/logs", params) end # Delete a service @@ -72,6 +72,6 @@ def logs name, params = {} # # @param name [String]: The ID or name of the service. def remove name - delete(build_path("/services/#{name}")) + delete("/services/#{name}") end end diff --git a/lib/docker/api/swarm.rb b/lib/docker/api/swarm.rb index d53f50e..4939acb 100644 --- a/lib/docker/api/swarm.rb +++ b/lib/docker/api/swarm.rb @@ -11,7 +11,7 @@ class Docker::API::Swarm < Docker::API::Base # # @param body [Hash]: Request body to be sent as json. def init body = {} - request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/swarm/init", headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -23,7 +23,7 @@ def init body = {} # @param params [Hash]: Parameters that are appended to the URL. # @param body [Hash]: Request body to be sent as json. def update params = {}, body = {} - request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/swarm/update", params: params, headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -32,7 +32,7 @@ def update params = {}, body = {} # Docker API: GET /swarm # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInspect def details - get(build_path("/swarm")) + get("/swarm") end ## @@ -41,7 +41,7 @@ def details # Docker API: GET /swarm/unlockkey # @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlockkey def unlock_key - get(build_path("/swarm/unlockkey")) + get("/swarm/unlockkey") end ## @@ -52,7 +52,7 @@ def unlock_key # # @param body [Hash]: Request body to be sent as json. def unlock body = {} - request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/swarm/unlock", headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -63,7 +63,7 @@ def unlock body = {} # # @param body [Hash]: Request body to be sent as json. def join body = {} - request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/swarm/join", headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -74,6 +74,6 @@ def join body = {} # # @param params [Hash]: Parameters that are appended to the URL. def leave params = {} - post(build_path("/swarm/leave", params)) + post("/swarm/leave", params) end end \ No newline at end of file diff --git a/lib/docker/api/system.rb b/lib/docker/api/system.rb index 05ef00c..d335697 100644 --- a/lib/docker/api/system.rb +++ b/lib/docker/api/system.rb @@ -11,7 +11,7 @@ class Docker::API::System < Docker::API::Base # # @param body [Hash]: Request body to be sent as json. def auth body = {} - request(method: :post, path: build_path("/auth"), headers: { "Content-Type" => "application/json" }, body: body.to_json) + request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json) end ## @@ -23,7 +23,7 @@ def auth body = {} # @param params [Hash]: Parameters that are appended to the URL. # @param &block: Replace the default output to stdout behavior. def events params = {}, &block - request(method: :get, path: build_path("/events", params), response_block: block_given? ? block : default_streamer ) + request(method: :get, path: "/events", params: params, response_block: block_given? ? block : default_streamer ) end ## @@ -32,7 +32,7 @@ def events params = {}, &block # Docker API: GET /_ping # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemPing def ping - get(build_path("/_ping")) + get("/_ping") end ## @@ -41,7 +41,7 @@ def ping # Docker API: GET /info # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemInfo def info - get(build_path("/info")) + get("/info") end ## @@ -50,7 +50,7 @@ def info # Docker API: GET /version # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemVersion def version - get(build_path("/version")) + get("/version") end ## @@ -59,7 +59,7 @@ def version # Docker API: GET /system/df # @see https://docs.docker.com/engine/api/v1.40/#operation/SystemDataUsage def df params = {} - get(build_path("/system/df", params)) + get("/system/df", params) end end \ No newline at end of file diff --git a/lib/docker/api/task.rb b/lib/docker/api/task.rb index ed49391..ae09a3a 100644 --- a/lib/docker/api/task.rb +++ b/lib/docker/api/task.rb @@ -11,7 +11,7 @@ class Docker::API::Task < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/tasks",params)) + get("/tasks",params) end # Inspect a task @@ -21,7 +21,7 @@ def list params = {} # # @param name [String]: The ID or name of the task. def details name - get(build_path("/tasks/#{name}")) + get("/tasks/#{name}") end # Get stdout and stderr logs from a task. @@ -33,12 +33,12 @@ def details name # @param params (Hash) : Parameters that are appended to the URL. # @param &block: Replace the default output to stdout behavior. def logs name, params = {}, &block - path = build_path("/tasks/#{name}/logs", params) + path = "/tasks/#{name}/logs" if [true, 1 ].include? params[:follow] - request(method: :get, path: path , response_block: block_given? ? block : default_streamer) + request(method: :get, path: path , params: params, response_block: block_given? ? block : default_streamer) else - get(path) + get(path, params) end end end \ No newline at end of file diff --git a/lib/docker/api/version.rb b/lib/docker/api/version.rb index 4e671eb..6fd3d28 100644 --- a/lib/docker/api/version.rb +++ b/lib/docker/api/version.rb @@ -1,6 +1,6 @@ module Docker module API - GEM_VERSION = "0.22.0" + GEM_VERSION = "0.22.1" API_VERSION = "1.43" diff --git a/lib/docker/api/volume.rb b/lib/docker/api/volume.rb index 876d487..7ff7b2e 100644 --- a/lib/docker/api/volume.rb +++ b/lib/docker/api/volume.rb @@ -11,7 +11,7 @@ class Docker::API::Volume < Docker::API::Base # # @param params [Hash]: Parameters that are appended to the URL. def list params = {} - get(build_path("/volumes", params)) + get("/volumes", params) end ## @@ -22,7 +22,7 @@ def list params = {} # # @param name [String]: The ID or name of the volume. def details name - get(build_path("/volumes/#{name}")) + get("/volumes/#{name}") end ## @@ -33,7 +33,7 @@ def details name # # @param body [Hash]: Request body to be sent as json. def create body = {} - request(method: :post, path: build_path("/volumes/create"), headers: {"Content-Type" => "application/json"}, body: body.to_json) + request(method: :post, path: "/volumes/create", headers: {"Content-Type" => "application/json"}, body: body.to_json) end ## @@ -45,7 +45,7 @@ def create body = {} # @param name [String]: The ID or name of the volume. # @param params [Hash]: Parameters that are appended to the URL. def remove name, params = {} - delete(build_path("/volumes/#{name}",params)) + delete("/volumes/#{name}",params) end ## @@ -56,6 +56,6 @@ def remove name, params = {} # # @param params [Hash]: Parameters that are appended to the URL. def prune params = {} - post(build_path("/volumes/prune", params)) + post("/volumes/prune", params) end end diff --git a/spec/endpoints/config_spec.rb b/spec/endpoints/config_spec.rb index 7ea1de7..e5dd14f 100644 --- a/spec/endpoints/config_spec.rb +++ b/spec/endpoints/config_spec.rb @@ -44,7 +44,7 @@ let(:version) { subject.details("rspec-config").json["Version"]["Index"] } let(:spec) { subject.details("rspec-config").json["Spec"] } - it { expect(subject.update("rspec-config", {version: version}, spec).request_params[:path]).to eq('/v1.43/v1.43/configs/rspec-config/update?version=abc') } + it { expect(subject.update("rspec-config", {version: version}, spec).request_params[:path]).to eq('/v1.43/configs/rspec-config/update?version=abc') } it { expect(subject.update("rspec-config", {version: version}, spec).request_params[:method]).to eq(:post) } it { expect{subject.update("rspec-config", invalid: true)}.not_to raise_error } it { expect{subject.update("rspec-config", {version: version}, {invalid: true})}.not_to raise_error }