diff --git a/CHANGELOG.md b/CHANGELOG.md index f21165622..3cddbae30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added -- Added base64 gem to gemspec (#218)[https://github.com/opensearch-project/opensearch-ruby/pull/218] ### Changed ### Deprecated ### Removed +- Removed dependency on the base64 gem to avoid a warning with Ruby 3.3 ([#221](https://github.com/opensearch-project/opensearch-ruby/pull/221)) ### Fixed ### Security diff --git a/lib/opensearch/transport/client.rb b/lib/opensearch/transport/client.rb index acbb92814..ee4b60af2 100644 --- a/lib/opensearch/transport/client.rb +++ b/lib/opensearch/transport/client.rb @@ -24,8 +24,6 @@ # specific language governing permissions and limitations # under the License. -require 'base64' - module OpenSearch module Transport # Handles communication with an OpenSearch cluster. @@ -225,7 +223,8 @@ def extract_cloud_creds(arguments) return unless arguments[:cloud_id] && !arguments[:cloud_id].empty? name = arguments[:cloud_id].split(':')[0] - cloud_url, opensearch_instance = Base64.decode64(arguments[:cloud_id].gsub("#{name}:", '')).split('$') + base64_decoded = arguments[:cloud_id].gsub("#{name}:", '').unpack1('m') + cloud_url, opensearch_instance = base64_decoded.split('$') if cloud_url.include?(':') url, port = cloud_url.split(':') @@ -355,7 +354,8 @@ def __auto_detect_adapter # Encode credentials for the Authorization Header # Credentials is the base64 encoding of id and api_key joined by a colon def __encode(api_key) - Base64.strict_encode64([api_key[:id], api_key[:api_key]].join(':')) + joined = [api_key[:id], api_key[:api_key]].join(':') + [joined].pack('m0') end end end diff --git a/opensearch-ruby.gemspec b/opensearch-ruby.gemspec index ab1f9a1c1..f86f69800 100644 --- a/opensearch-ruby.gemspec +++ b/opensearch-ruby.gemspec @@ -64,7 +64,6 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.5' - s.add_dependency 'base64' s.add_dependency 'faraday', '>= 1.0', '< 3' s.add_dependency 'multi_json', '>= 1.0' end diff --git a/spec/opensearch/transport/client_spec.rb b/spec/opensearch/transport/client_spec.rb index 8d556cfb1..050dc458f 100644 --- a/spec/opensearch/transport/client_spec.rb +++ b/spec/opensearch/transport/client_spec.rb @@ -98,7 +98,8 @@ end it 'Adds the ApiKey header to the connection' do - expect(authorization_header).to eq("ApiKey #{Base64.strict_encode64('my_id:my_api_key')}") + strict_base64_encoded = ["my_id:my_api_key"].pack("m0") + expect(authorization_header).to eq("ApiKey #{strict_base64_encoded}") end end