Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.11][Backport] Drop runtime dependency on base64 #2300

Merged
merged 1 commit into from
Feb 6, 2024
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
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
Loading