Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Gem::Specification.new do |gem|
gem.name = 'docker-api'
gem.version = Docker::VERSION
gem.add_dependency 'excon', '>= 0.64.0'
gem.add_dependency 'multi_json'
# base64 stopped being a default gem in Ruby 3.4, so `require 'base64'` in
# lib/docker.rb raises LoadError under Bundler unless it is declared.
gem.add_dependency 'base64'
Expand Down
4 changes: 2 additions & 2 deletions lib/docker.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'cgi'
require 'multi_json'
require 'json'
require 'excon'
require 'tempfile'
require 'base64'
Expand Down Expand Up @@ -133,7 +133,7 @@ def rootless?(connection = self.connection)

# Login to the Docker registry.
def authenticate!(options = {}, connection = self.connection)
creds = MultiJson.dump(options)
creds = JSON.generate(options)
connection.post('/auth', {}, body: creds)
@creds = creds
true
Expand Down
10 changes: 5 additions & 5 deletions lib/docker/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def commit(options = {})
# Based on the link, the config passed as run, needs to be passed as the
# body of the post so capture it, remove from the options, and pass it via
# the post body
config = MultiJson.dump(options.delete('run'))
config = JSON.generate(options.delete('run'))
hash = Docker::Util.parse_json(
connection.post('/commit', options, body: config)
)
Expand Down Expand Up @@ -200,7 +200,7 @@ def rename(new_name)
end

def update(opts)
connection.post(path_for(:update), {}, body: MultiJson.dump(opts))
connection.post(path_for(:update), {}, body: JSON.generate(opts))
end

def streaming_logs(opts = {}, &block)
Expand All @@ -214,7 +214,7 @@ def streaming_logs(opts = {}, &block)
end

def start!(opts = {})
connection.post(path_for(:start), {}, body: MultiJson.dump(opts))
connection.post(path_for(:start), {}, body: JSON.generate(opts))
self
end

Expand All @@ -240,7 +240,7 @@ def kill!(opts = {})
timeout = opts.delete('timeout')
query = {}
request_options = {
:body => MultiJson.dump(opts)
:body => JSON.generate(opts)
}
if timeout
query['t'] = timeout
Expand Down Expand Up @@ -346,7 +346,7 @@ def store_file(path, file_content)
def self.create(opts = {}, conn = Docker.connection)
query = opts.select { |key| CREATE_QUERY_KEYS.include?(key.to_s) }
clean_opts = opts.reject { |key| CREATE_QUERY_KEYS.include?(key.to_s) }
resp = conn.post('/containers/create', query, :body => MultiJson.dump(clean_opts))
resp = conn.post('/containers/create', query, :body => JSON.generate(clean_opts))
hash = Docker::Util.parse_json(resp) || {}
new(conn, hash)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/docker/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.create(options = {}, conn = Docker.connection)
end

resp = conn.post("/containers/#{container}/exec", {},
body: MultiJson.dump(options))
body: JSON.generate(options))
hash = Docker::Util.parse_json(resp) || {}
new(conn, hash)
end
Expand Down Expand Up @@ -60,7 +60,7 @@ def start!(options = {}, &block)
read_timeout = options[:wait]

# Create API Request Body
body = MultiJson.dump(
body = JSON.generate(
'Tty' => tty,
'Detach' => detached
)
Expand Down
2 changes: 1 addition & 1 deletion lib/docker/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class << self

# Create a new Image.
def create(opts = {}, creds = nil, conn = Docker.connection, &block)
credentials = creds.nil? ? Docker.creds : MultiJson.dump(creds)
credentials = creds.nil? ? Docker.creds : JSON.generate(creds)
headers = credentials && Docker::Util.build_auth_header(credentials) || {}
body = +''
conn.post(
Expand Down
6 changes: 3 additions & 3 deletions lib/docker/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ class Docker::Network
include Docker::Base

def connect(container, opts = {}, body_opts = {})
body = MultiJson.dump({ container: container }.merge(body_opts))
body = JSON.generate({ container: container }.merge(body_opts))
Docker::Util.parse_json(
connection.post(path_for('connect'), opts, body: body)
)
reload
end

def disconnect(container, opts = {})
body = MultiJson.dump(container: container)
body = JSON.generate(container: container)
Docker::Util.parse_json(
connection.post(path_for('disconnect'), opts, body: body)
)
Expand Down Expand Up @@ -43,7 +43,7 @@ def reload

class << self
def create(name, opts = {}, conn = Docker.connection)
default_opts = MultiJson.dump({
default_opts = JSON.generate({
'Name' => name,
'CheckDuplicate' => true
}.merge(opts))
Expand Down
10 changes: 5 additions & 5 deletions lib/docker/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def close_write(socket)
end

def parse_json(body)
MultiJson.load(body) unless body.nil? || body.empty? || (body == 'null')
rescue MultiJson::ParseError => ex
JSON.parse(body) unless body.nil? || body.empty? || (body == 'null')
rescue JSON::ParserError => ex
raise UnexpectedResponseError, ex.message
end

Expand Down Expand Up @@ -261,7 +261,7 @@ def filesystem_permissions(path)
end

def build_auth_header(credentials)
credentials = MultiJson.dump(credentials) if credentials.is_a?(Hash)
credentials = JSON.generate(credentials) if credentials.is_a?(Hash)
encoded_creds = Base64.urlsafe_encode64(credentials)
{
'X-Registry-Auth' => encoded_creds
Expand All @@ -270,10 +270,10 @@ def build_auth_header(credentials)

def build_config_header(credentials)
if credentials.is_a?(String)
credentials = MultiJson.load(credentials, symbolize_keys: true)
credentials = JSON.parse(credentials, symbolize_names: true)
end

header = MultiJson.dump(
header = JSON.generate(
credentials[:serveraddress].to_s => {
'username' => credentials[:username].to_s,
'password' => credentials[:password].to_s,
Expand Down
2 changes: 1 addition & 1 deletion lib/docker/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def all(opts = {}, conn = Docker.connection)
# creates a volume with an arbitrary name
def create(name, opts = {}, conn = Docker.connection)
opts['Name'] = name
resp = conn.post('/volumes/create', {}, body: MultiJson.dump(opts))
resp = conn.post('/volumes/create', {}, body: JSON.generate(opts))
hash = Docker::Util.parse_json(resp) || {}
new(conn, hash)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/docker/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@

it 'does not send the platform in the body' do
expect(Docker.connection).to receive(:post) { |_path, _query, opts|
expect(MultiJson.load(opts[:body])).to_not have_key('platform')
expect(JSON.parse(opts[:body])).to_not have_key('platform')
'{"Id":"deadbeef"}'
}

Expand Down
2 changes: 1 addition & 1 deletion spec/docker/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
context 'with a new api response' do
let(:event) do
Docker::Event.new_event(
MultiJson.dump(api_response),
JSON.generate(api_response),
nil,
nil
)
Expand Down
6 changes: 3 additions & 3 deletions spec/docker/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def expect_tar_entries(*entries)
:serveraddress => 'https://registry.com/'
}
}
let(:credential_string) { MultiJson.dump(credentials) }
let(:credential_string) { JSON.generate(credentials) }
let(:encoded_creds) { Base64.urlsafe_encode64(credential_string) }
let(:expected_header) {
{
Expand Down Expand Up @@ -280,7 +280,7 @@ def expect_tar_entries(*entries)
}

let(:credentials_object) do
MultiJson.dump(
JSON.generate(
:'https://registry.com/' => {
username: 'test',
password: 'password',
Expand All @@ -305,7 +305,7 @@ def expect_tar_entries(*entries)
context 'given credentials as a String' do
it 'returns an X-Registry-Config header encoded' do
expect(
subject.build_config_header(MultiJson.dump(credentials))
subject.build_config_header(JSON.generate(credentials))
).to eq(expected_header)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
it 'logs in and sets the creds' do
skip_without_auth
expect(authentication).to be true
expect(Docker.creds).to eq(MultiJson.dump(credentials))
expect(Docker.creds).to eq(JSON.generate(credentials))
end
end

Expand Down
Loading