Skip to content

Commit

Permalink
Drop runtime dependency on base64
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain authored and picandocodigo committed Feb 5, 2024
1 parent a581488 commit 20558af
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions elasticsearch-api/api-spec-testing/test_file/task_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

require 'base64'

module Elasticsearch
module RestAPIYAMLTests
class TestFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

require 'base64'
require_relative '../platinum_helper'

describe 'API keys API invalidation' do
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/elasticsearch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Gem::Specification.new do |s|

s.add_dependency 'elastic-transport', '~> 8.3'
s.add_dependency 'elasticsearch-api', '8.13.0'
s.add_dependency 'base64'


s.add_development_dependency 'base64'
s.add_development_dependency 'bundler'
s.add_development_dependency 'debug' unless defined?(JRUBY_VERSION)
s.add_development_dependency 'pry'
Expand Down
7 changes: 4 additions & 3 deletions elasticsearch/lib/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
require 'elasticsearch/version'
require 'elastic/transport'
require 'elasticsearch/api'
require 'base64'

module Elasticsearch
NOT_ELASTICSEARCH_WARNING = 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.'.freeze
Expand Down Expand Up @@ -108,7 +107,8 @@ def verify_elasticsearch(*args, &block)

def setup_cloud_host(cloud_id, user, password, port)
name = cloud_id.split(':')[0]
cloud_url, elasticsearch_instance = Base64.decode64(cloud_id.gsub("#{name}:", '')).split('$')
base64_decoded = cloud_id.gsub("#{name}:", '').unpack1('m')
cloud_url, elasticsearch_instance = base64_decoded.split('$')

if cloud_url.include?(':')
url, port = cloud_url.split(':')
Expand Down Expand Up @@ -150,7 +150,8 @@ def setup_cloud(arguments)
# Credentials is the base64 encoding of id and api_key joined by a colon
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
def encode(api_key)
Base64.strict_encode64([api_key[:id], api_key[:api_key]].join(':'))
credentials = [api_key[:id], api_key[:api_key]].join(':')
[credentials].pack('m0')
end

def elasticsearch_validation_request
Expand Down
1 change: 1 addition & 0 deletions elasticsearch/spec/unit/api_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

require 'spec_helper'
require 'base64'

describe Elasticsearch::Client do
context 'when using API Key' do
Expand Down

0 comments on commit 20558af

Please sign in to comment.