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

Remove dependency on the base64 gem #221

Merged
merged 1 commit into from
Jan 2, 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: 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
Loading