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 6, 2024
1 parent a779e32 commit ba392a1
Show file tree
Hide file tree
Showing 5 changed files with 9 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
3 changes: 1 addition & 2 deletions elasticsearch/elasticsearch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.5'

s.add_dependency 'elastic-transport', '~> 8.3'

s.add_dependency 'elasticsearch-api', '8.11.1'
s.add_dependency 'base64'

s.add_development_dependency 'base64'
s.add_development_dependency 'bundler'
s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
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 @@ -112,7 +111,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 @@ -154,7 +154,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 ba392a1

Please sign in to comment.