Skip to content

Commit

Permalink
Remove dependency on the base64 gem (#221)
Browse files Browse the repository at this point in the history
Removed dependency on Base64 gem

Signed-off-by: Earlopain <[email protected]>
  • Loading branch information
Earlopain authored Jan 2, 2024
1 parent fe24161 commit 97fac2a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ 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]
- Added support for Ruby 3.3 ([#220](https://github.com/opensearch-project/opensearch-ruby/pull/220))
### Changed
### Deprecated
### Removed
- Removed dependency on the base64 gem ([#221](https://github.com/opensearch-project/opensearch-ruby/pull/221))
### Fixed
- Switch back to the latest OpenSearch version when testing in CI ([#219](https://github.com/opensearch-project/opensearch-ruby/pull/219))
### Security
Expand Down
8 changes: 4 additions & 4 deletions lib/opensearch/transport/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(':')
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion opensearch-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion spec/opensearch/transport/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 97fac2a

Please sign in to comment.