opensearch-aws-sigv4 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c18c127380978f8f6c155763004c09c2f47f8fe510060f78f5e2dd22dfda7d9
4
- data.tar.gz: 1bf9b1df47af0b02f6e95950aab3bd51aa107e0d1b70dad9b210c894bcc5074f
3
+ metadata.gz: 3653f0078c0217fcf752f3a3dbd8f5fb69d528f1792c8f15bab2d227729befc4
4
+ data.tar.gz: 41e8d376d24bb217f766970265a50c4502d8b7ca6995099619bb5c9051a8e6c4
5
5
  SHA512:
6
- metadata.gz: 6425d6f4b4925292cca4d1ab444643b40399ce6728b865715537df1c061c776bcb759b9fbd1f5d891a72e78ebf457ec601f4d3e0bb106e151d274a9aadb0e81c
7
- data.tar.gz: 0376e3c9a1b67e4885335ecd1a751cd2db67725242f5a09f84cfa905dcbed18b2cbe64043e8ffcbb1b638bc5b71917982be13da6186c6f04cbb9f10f73c18d1f
6
+ metadata.gz: 65bd6720403fb13d258a21c0e21c28312d57b04346435388f23ddf976e1aedf190abbb7c469b4cacc0c418b0bd29bb7ee700eae59fb58cac388be5e8067eed72
7
+ data.tar.gz: ae9eb85688027bb1b9de52fc62f5c8a3829d99e8414c397b80486e94f225f3393a47ea7cad47bf2b448247d136c9da0b777408fd6ec927b626dd534794862e37
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- O0H56�X����=�q�.��Ёl,���1���?F�j����VU؟V���86z��,�v�`U�<>pk�<�R�,�9}�A��
2
- ��!6���S��k��.�"y|C�,� XL���
1
+ �hjnT߇~ø1o>#���X��.��Q��^����=B/��_o>�2�f���Ɓ�����4���w��VJ�������B�v�]P׸I��C��2�h�t�O��}x3?Z�j���Ȓ��<s��& �x��<X����|0W�D%�n�v�N��@+.���v�̟�M3��q��E�4g��D��[ ��l����\Q�Y�q��V��}]L�ݡu�po?�G͕b*u��r
2
+ �5�,}��M�Y��n�-�����\K��
data/README.md CHANGED
@@ -1,102 +1,19 @@
1
- # OpenSearch Aws Sigv4 Client
1
+ [<img src="OpenSearch.svg" width="400">](https://opensearch.org)
2
2
 
3
- The `opensearch-aws-sigv4` library provides an AWS Sigv4 client for [OpenSearch](http://opensearch.com).
3
+ # OpenSearch AWS Sigv4 Client
4
4
 
5
- ## Compatibility
6
-
7
- The OpenSearch Aws Sigv4 Client is compatible with Ruby 2.5 and higher.
8
-
9
- The client's API is compatible with OpenSearch's API versions from 1.0.0 till current.
10
-
11
- See [COMPATIBILITY](../COMPATIBILITY.md) for more details.
12
-
13
- ## Installation
14
-
15
- Install the package from [Rubygems](https://rubygems.org):
16
-
17
- gem install opensearch-aws-sigv4
18
-
19
- To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://gembundler.com):
20
-
21
- gem 'opensearch-aws-sigv4', git: 'git://github.com/opensearch-project/opensearch-ruby.git'
22
-
23
- or install it from a source code checkout:
24
-
25
- git clone https://github.com/opensearch-project/opensearch-ruby
26
- cd opensearch-ruby/opensearch-aws-sigv4
27
- bundle install
28
- rake install
29
-
30
- ## Usage
31
-
32
- This library is an AWS Sigv4 wrapper for
33
- [`opensearch-ruby`](https://github.com/opensearch-project/opensearch-ruby/tree/main/opensearch-ruby),
34
- which is a Ruby client for OpenSearch. The `OpenSearch::Aws::Sigv4Client` is, therefore, has all features of `OpenSearch::Client`.
35
- And since `opensearch-ruby` is a dependency of `opensearch-aws-sigv4`, you only need to install `opensearch-aws-sigv4`.
5
+ The `opensearch-aws-sigv4` library provides an AWS Sigv4 client for connecting to [Amazon OpenSearch Service](https://docs.aws.amazon.com/opensearch-service/index.html).
36
6
 
37
- ### Amazon Managed OpenSearch
38
- Via the Sigv4 Client, you can interact with an Amazon Managed OpenSearch cluster just like would with a self-managed cluster:
7
+ This library is an AWS Sigv4 wrapper for [`opensearch-ruby`](https://github.com/opensearch-project/opensearch-ruby/tree/main), which is a Ruby client for OpenSearch. The `OpenSearch::Aws::Sigv4Client`, therefore, has all features of `OpenSearch::Client`.
39
8
 
40
- ```ruby
41
- require 'opensearch-aws-sigv4'
42
- require 'aws-sigv4'
43
-
44
- signer = Aws::Sigv4::Signer.new(service: 'es',
45
- region: 'us-west-2',
46
- access_key_id: 'key_id',
47
- secret_access_key: 'secret')
48
-
49
- client = OpenSearch::Aws::Sigv4Client.new(
50
- { host: 'https://your.amz-managed-opensearch.domain',
51
- log: true },
52
- signer)
53
-
54
- client.cluster.health
55
-
56
- client.transport.reload_connections!
57
-
58
- client.search q: 'test'
59
- ```
60
-
61
- Please refer to [opensearch-ruby](https://github.com/opensearch-project/opensearch-ruby/blob/main/opensearch-ruby/README.md) documentation for further details.
62
-
63
- ### Amazon OpenSearch Serverless
64
- You can also use this client to connect to Amazon OpenSearch Serverless (AOSS). Remember to change the service for the signer to `aoss`:
65
-
66
- ```ruby
67
- require 'opensearch-aws-sigv4'
68
- require 'aws-sigv4'
69
-
70
- signer = Aws::Sigv4::Signer.new(service: 'aoss',
71
- region: 'us-west-2',
72
- access_key_id: 'key_id',
73
- secret_access_key: 'secret')
74
-
75
- client = OpenSearch::Aws::Sigv4Client.new(
76
- { host: 'https://your.amz-opensearch-serverless.endpoint',
77
- log: true },
78
- signer)
79
-
80
- index = 'prime'
81
- client.indices.create(index: index)
82
- client.index(index: index, id: '1', body: { name: 'Amazon Echo',
83
- msrp: '5999',
84
- year: 2011 })
85
- client.search(body: { query: { match: { name: 'Echo' } } })
86
- client.delete(index: index, id: '1')
87
- client.indices.delete(index: index)
88
-
89
- # Most administrative commands like the ones below will result in a 404 error for AOSS
90
- client.cluster.stats
91
- client.cat.health
92
- ```
9
+ ## Compatibility
93
10
 
94
- *NOTES:* AOSS does NOT support all API endpoints provided by a standard OpenSearch cluster. Refer to [AOSS Developer's Guide](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-genref.html) for more detail.
11
+ The `opensearch-aws-sigv4` library is compatible with all versions of `opensearch-ruby`.
95
12
 
96
- ## Development
13
+ ## User Guide
97
14
 
98
- You can run `rake -T` to check the test tasks. Use `COVERAGE=true` before running a test task to check the coverage with Simplecov.
15
+ See [USER_GUIDE](USER_GUIDE.md).
99
16
 
100
17
  ## License
101
18
 
102
- This software is licensed under the [Apache 2 license](./LICENSE).
19
+ This software is licensed under the [Apache 2 license](LICENSE).
data/USER_GUIDE.md ADDED
@@ -0,0 +1,96 @@
1
+ - [User Guide](#user-guide)
2
+ - [Setup](#setup)
3
+ - [Usage](#usage)
4
+ - [Amazon OpenSearch Service](#amazon-opensearch-service)
5
+ - [Enable Sigv4 Debug Logging](#enable-sigv4-debug-logging)
6
+ # User Guide
7
+ ## Setup
8
+
9
+ To add the gem to your project, install it using [RubyGems](https://rubygems.org/):
10
+
11
+ ```
12
+ gem install opensearch-aws-sigv4
13
+ ```
14
+
15
+ or add it to your Gemfile:
16
+ ```
17
+ gem opensearch-aws-sigv4
18
+ ```
19
+ and run:
20
+ ```
21
+ bundle install
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ This library is an AWS Sigv4 wrapper for [`opensearch-ruby`](https://github.com/opensearch-project/opensearch-ruby/tree/main), which is a Ruby client for OpenSearch. The `OpenSearch::Aws::Sigv4Client`, therefore, has all features of `OpenSearch::Client`.
27
+
28
+ ### Amazon OpenSearch Service
29
+ To sign requests for the Amazon OpenSearch Service:
30
+
31
+ ```ruby
32
+ require 'opensearch-aws-sigv4'
33
+ require 'aws-sigv4'
34
+
35
+ signer = Aws::Sigv4::Signer.new(service: 'es', # signing service name, use "aoss" for OpenSearch Serverless
36
+ region: 'us-west-2', # signing service region
37
+ access_key_id: 'key_id',
38
+ secret_access_key: 'secret')
39
+
40
+ client = OpenSearch::Aws::Sigv4Client.new({
41
+ host: 'https://your.amz-managed-opensearch.domain', # serverless endpoint for OpenSearch Serverless
42
+ log: true
43
+ }, signer)
44
+
45
+ # create an index and document
46
+ index = 'prime'
47
+ client.indices.create(index: index)
48
+ client.index(index: index, id: '1', body: { name: 'Amazon Echo',
49
+ msrp: '5999',
50
+ year: 2011 })
51
+
52
+ # search for the document
53
+ client.search(body: { query: { match: { name: 'Echo' } } })
54
+
55
+ # delete the document
56
+ client.delete(index: index, id: '1')
57
+
58
+ # delete the index
59
+ client.indices.delete(index: index)
60
+ ```
61
+
62
+ ### Enable Sigv4 Debug Logging
63
+ If you run into credentials errors, usually from expired session, set the `sigv4_debug` option to `true` when creating the client to print out the Sigv4 Signing Debug information.
64
+
65
+ ```ruby
66
+ client = OpenSearch::Aws::Sigv4Client.new({
67
+ host: 'https://your.amz-managed-opensearch.domain',
68
+ }, signer, sigv4_debug: true)
69
+
70
+ client.info
71
+ ```
72
+
73
+ ```shell
74
+ (2023-04-25 11:02:59 -0600) Sigv4 - STRING TO SIGN:
75
+ AWS4-HMAC-SHA256
76
+ 20230425T170259Z
77
+ 20230425/us-east-1/aoss/aws4_request
78
+ 0e20bdc5eda484f2b0e65f8a33514c48471500da91b1f0c8bb6b86770b5dc6c4
79
+
80
+ (2023-04-25 11:02:59 -0600) Sigv4 - CANONICAL REQUEST:
81
+ GET
82
+ /
83
+
84
+ host:your.amz-managed-opensearch.domain
85
+ x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
86
+ x-amz-date:20230425T170259Z
87
+
88
+ host;x-amz-content-sha256;x-amz-date
89
+ e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
90
+
91
+ (2023-04-25 11:02:59 -0600) Sigv4 - SIGNATURE HEADERS:
92
+ {"host"=>"your.amz-managed-opensearch.domain",
93
+ "x-amz-date"=>"20230425T170259Z",
94
+ "x-amz-content-sha256"=>"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
95
+ "authorization"=>"AWS4-HMAC-SHA256 Credential=ABCDEFGH/20230425/us-east-1/aoss/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=858f171c834231ae3c885c670217f94c68f010e85c50b0ad095444966fb5df0c"}
96
+ ```
@@ -1,43 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $LOAD_PATH.unshift(File.expand_path('../../opensearch-aws-sigv4/lib', __dir__))
4
- $LOAD_PATH.unshift(File.expand_path('../../opensearch-ruby/lib', __dir__))
5
- $LOAD_PATH.unshift(File.expand_path('../../opensearch-transport/lib', __dir__))
6
- $LOAD_PATH.unshift(File.expand_path('../../opensearch-dsl/lib', __dir__))
7
- $LOAD_PATH.unshift(File.expand_path('../../opensearch-api/lib', __dir__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
8
5
 
9
6
  require 'opensearch-aws-sigv4'
10
-
11
- gems_not_loaded = ['opensearch-dsl'].reject do |gem|
12
- begin
13
- (require gem) || true
14
- rescue LoadError
15
- false
16
- end
17
- end
18
-
19
- unless gems_not_loaded.empty?
20
- warn "The following gems were not loaded: [#{gems_not_loaded.join(', ')}]. Please install and require them explicitly."
21
- end
22
-
23
- include OpenSearch
24
- include OpenSearch::DSL if defined?(OpenSearch::DSL)
7
+ require 'aws-sigv4'
25
8
 
26
9
  begin
27
10
  require 'pry'
11
+ Pry.start
28
12
  rescue LoadError
29
- end
30
-
31
- begin
32
13
  require 'irb'
33
- rescue LoadError
34
- end
35
-
36
- if defined?(Pry)
37
- Pry.config.prompt_name = 'opensearch_sigv4'
38
- Pry.start
39
- elsif defined?(IRB)
40
14
  IRB.start
41
- else
42
- abort 'LoadError: opensearch_sigv4_console requires Pry or IRB'
43
15
  end
@@ -7,10 +7,12 @@
7
7
  # Modifications Copyright OpenSearch Contributors. See
8
8
  # GitHub history for details.
9
9
 
10
+ # frozen_string_literal: true
11
+
10
12
  module OpenSearch
11
13
  module Aws
12
14
  module Sigv4
13
- VERSION = '1.1.0'.freeze
15
+ VERSION = '1.2.1'
14
16
  end
15
17
  end
16
18
  end
@@ -1,3 +1,4 @@
1
+ # rubocop:disable Naming/FileName
1
2
  # SPDX-License-Identifier: Apache-2.0
2
3
  #
3
4
  # The OpenSearch Contributors require contributions made to
@@ -7,6 +8,8 @@
7
8
  # Modifications Copyright OpenSearch Contributors. See
8
9
  # GitHub history for details.
9
10
 
11
+ # frozen_string_literal: true
12
+
10
13
  require 'opensearch-ruby'
11
14
  require 'aws-sigv4/signer'
12
15
  require 'faraday'
@@ -39,12 +42,16 @@ module OpenSearch
39
42
  # @param [Hash] transport_args arguments for OpenSearch::Transport::Client.
40
43
  # @param [&block] block code block to be passed to OpenSearch::Transport::Client.
41
44
  # @param [Aws::Sigv4::Signer] sigv4_signer an instance of AWS Sigv4 Signer.
42
- def initialize(transport_args = {}, sigv4_signer, &block)
45
+ # @param [Hash] options
46
+ # @option options [Boolean] :sigv4_debug whether to log debug info for Sigv4 Signing
47
+ def initialize(transport_args, sigv4_signer, options: {}, &block)
43
48
  unless sigv4_signer.is_a?(::Aws::Sigv4::Signer)
44
49
  raise ArgumentError, "Please pass a Aws::Sigv4::Signer. A #{sigv4_signer.class} was given."
45
50
  end
46
51
 
47
52
  @sigv4_signer = sigv4_signer
53
+ @sigv4_debug = options[:sigv4_debug]
54
+ @logger = nil
48
55
  super(transport_args, &block)
49
56
  end
50
57
 
@@ -55,9 +62,12 @@ module OpenSearch
55
62
  http_method: method,
56
63
  url: signature_url(path, params),
57
64
  headers: headers,
58
- body: signature_body)
65
+ body: signature_body
66
+ )
59
67
  headers = (headers || {}).merge(signature.headers)
60
- super(method, path, params, body, headers)
68
+
69
+ log_signature_info(signature)
70
+ super(method, path, params, signature_body, headers)
61
71
  end
62
72
 
63
73
  private
@@ -68,10 +78,35 @@ module OpenSearch
68
78
 
69
79
  def signature_url(path, params)
70
80
  host = @transport.transport.hosts.dig(0, :host)
71
- path = '/' + path unless path.start_with?('/')
72
- query_string = params.empty? ? '' : "#{Faraday::Utils::ParamsHash[params].to_query}"
81
+ path = "/#{path}" unless path.start_with?('/')
82
+ query_string = params.empty? ? '' : Faraday::Utils::ParamsHash[params].to_query.to_s
73
83
  URI::HTTP.build(host: host, path: path, query: query_string)
74
84
  end
85
+
86
+ # @param [Aws::Sigv4::Signature] signature
87
+ def log_signature_info(signature)
88
+ return unless @sigv4_debug
89
+
90
+ log('string to sign', signature.string_to_sign)
91
+ log('canonical request', signature.canonical_request)
92
+ log('signature headers', signature.headers)
93
+ end
94
+
95
+ def log(title, message)
96
+ logger.debug("#{title.upcase}:\n\e[36m#{message}\e[0m")
97
+ end
98
+
99
+ def logger
100
+ return @logger if @logger
101
+
102
+ require 'logger'
103
+ @logger = Logger.new(
104
+ $stdout,
105
+ progname: 'Sigv4',
106
+ formatter: proc { |_severity, datetime, progname, msg| "\e[34m(#{datetime}) #{progname} - #{msg}\e[0m\n\n" }
107
+ )
108
+ end
75
109
  end
76
110
  end
77
111
  end
112
+ # rubocop:enable Naming/FileName
@@ -7,22 +7,6 @@
7
7
  # Modifications Copyright OpenSearch Contributors. See
8
8
  # GitHub history for details.
9
9
 
10
- *.gem
11
- *.rbc
12
- .bundle
13
- .config
14
- .yardoc
15
- .ruby-version
16
- .idea/
17
- Gemfile.lock
18
- InstalledFiles
19
- _yardoc
20
- coverage
21
- doc/
22
- lib/bundler/man
23
- pkg
24
- rdoc
25
- spec/reports
26
- test/tmp
27
- test/version_tmp
28
- tmp
10
+ # frozen_string_literal: true
11
+
12
+ require 'opensearch-aws-sigv4'
@@ -7,58 +7,48 @@
7
7
  # Modifications Copyright OpenSearch Contributors. See
8
8
  # GitHub history for details.
9
9
 
10
- lib = File.expand_path('../lib', __FILE__)
11
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
12
- require 'opensearch-aws-sigv4/version'
10
+ # frozen_string_literal: true
13
11
 
14
- signing_key_path = File.expand_path("../gem-private_key.pem")
12
+ require_relative 'lib/opensearch-aws-sigv4/version'
15
13
 
16
14
  Gem::Specification.new do |s|
17
15
  s.name = 'opensearch-aws-sigv4'
18
16
  s.version = OpenSearch::Aws::Sigv4::VERSION
19
- s.authors = ['Theo Truong', 'Robin Roestenburg']
20
- s.email = ['theo.nam.truong@gmail.com', 'robin.roestenburg@4me.com']
21
- s.summary = 'Ruby AWS Sigv4 Client for OpenSearch'
22
- s.homepage = 'https://opensearch.org/docs/latest'
17
+ s.homepage = 'https://github.com/opensearch-project/opensearch-ruby-aws-sigv4'
23
18
  s.license = 'Apache-2.0'
19
+ s.authors = ['OpenSearch Contributors']
20
+ s.email = 'opensearch@amazon.com'
21
+ s.summary = 'Ruby AWS Sigv4 Client for OpenSearch'
22
+ s.description = <<~DESC
23
+ A wrapper for opensearch-ruby gem that provides AWS Sigv4 signing.
24
+ It behaves like OpenSearch::Client, but signs every request with AWS Sigv4
25
+ using the credentials provided during the client's initialization.
26
+ DESC
24
27
  s.metadata = {
25
- 'homepage_uri' => 'https://opensearch.org/docs/latest/',
26
- 'source_code_uri' => 'https://github.com/opensearch-project/opensearch-ruby/tree/main',
27
- 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues'
28
+ 'homepage_uri' => 'https://github.com/opensearch-project/opensearch-ruby-aws-sigv4',
29
+ 'documentation_uri' => 'https://rubydoc.info/gems/opensearch-aws-sigv4/OpenSearch/Aws/Sigv4Client',
30
+ 'source_code_uri' => 'https://github.com/opensearch-project/opensearch-ruby-aws-sigv4/tree/main',
31
+ 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby-aws-sigv4/issues',
32
+ 'changelog_uri' => 'https://github.com/opensearch-project/opensearch-ruby-aws-sigv4/blob/main/CHANGELOG.md'
28
33
  }
29
- s.files = `git ls-files`.split($/)
30
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
- s.executables << 'opensearch_sigv4_console'
32
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
33
-
34
- if $PROGRAM_NAME.end_with?("gem") && ARGV == ["build", __FILE__] && File.exist?(signing_key_path)
35
- s.signing_key = signing_key_path
36
- s.cert_chain = ['../certs/opensearch-rubygems.pem']
37
- end
38
34
 
35
+ s.files = Dir['lib/**/*', '*.gemspec']
36
+ s.test_files = Dir['spec/unit/**/*']
39
37
  s.require_paths = ['lib']
40
- s.bindir = 'bin'
38
+ s.bindir = 'bin'
39
+ s.executables = 'opensearch_sigv4_console'
41
40
 
42
- s.extra_rdoc_files = [ 'README.md', 'LICENSE' ]
43
- s.rdoc_options = [ '--charset=UTF-8' ]
41
+ s.extra_rdoc_files = %w[README.md USER_GUIDE.md LICENSE]
42
+ s.rdoc_options = ['--charset=UTF-8']
44
43
 
45
- s.required_ruby_version = '>= 2.5'
46
-
47
- s.add_dependency 'aws-sigv4', '~> 1'
48
- s.add_dependency 'opensearch-ruby', '>= 1.0.1'
44
+ signing_key = File.expand_path('gem-private_key.pem')
45
+ if $PROGRAM_NAME.end_with?('gem') && ARGV.first == 'build' && File.exist?(signing_key)
46
+ s.signing_key = signing_key
47
+ s.cert_chain = ['.github/opensearch-rubygems.pem']
48
+ end
49
49
 
50
- s.add_development_dependency 'bundler'
51
- s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
52
- s.add_development_dependency 'pry'
53
- s.add_development_dependency 'rake', '~> 13'
54
- s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
55
- s.add_development_dependency 'rspec'
56
- s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
57
- s.add_development_dependency 'simplecov'
58
- s.add_development_dependency 'yard'
59
- s.add_development_dependency 'timecop'
50
+ s.required_ruby_version = '>= 2.4'
60
51
 
61
- s.description = <<-DESC.gsub(/^ /, '')
62
- Ruby AWS Sigv4 Client for OpenSearch
63
- DESC
52
+ s.add_dependency 'aws-sigv4', '>= 1'
53
+ s.add_dependency 'opensearch-ruby', '>= 1.0.1'
64
54
  end
@@ -7,7 +7,9 @@
7
7
  # Modifications Copyright OpenSearch Contributors. See
8
8
  # GitHub history for details.
9
9
 
10
- require_relative '../spec_helper'
10
+ # frozen_string_literal: true
11
+
12
+ require_relative '../../../spec_helper'
11
13
  require 'aws-sigv4'
12
14
  require 'timecop'
13
15
 
@@ -16,7 +18,8 @@ describe OpenSearch::Aws::Sigv4Client do
16
18
  described_class.new(
17
19
  { host: 'http://localhost:9200',
18
20
  transport_options: { ssl: { verify: false } } },
19
- signer)
21
+ signer
22
+ )
20
23
  end
21
24
 
22
25
  let(:signer) do
@@ -37,7 +40,7 @@ describe OpenSearch::Aws::Sigv4Client do
37
40
 
38
41
  context 'when a Sigv4 Signer is provided' do
39
42
  it 'does NOT raise any error' do
40
- expect { client }.to_not raise_error
43
+ expect { client }.not_to raise_error
41
44
  end
42
45
  end
43
46
  end
@@ -45,25 +48,25 @@ describe OpenSearch::Aws::Sigv4Client do
45
48
  describe '#perform_request' do
46
49
  let(:response) { { body: 'Response Body' } }
47
50
  let(:transport_double) do
48
- _double = instance_double('OpenSearch::Transport::Client', perform_request: response)
49
- _double.stub_chain(:transport, :hosts, :dig).and_return('localhost')
50
- _double
51
+ double = instance_double(OpenSearch::Transport::Client, perform_request: response)
52
+ allow(double).to receive_message_chain(:transport, :hosts, :dig).and_return('localhost')
53
+ double
51
54
  end
52
55
  let(:signed_headers) do
53
56
  { 'authorization' => 'AWS4-HMAC-SHA256 Credential=key_id/20220101/us-west-2/es/aws4_request, '\
54
- 'SignedHeaders=host;x-amz-content-sha256;x-amz-date, ' \
55
- 'Signature=9c4c690110483308f62a91c2ca873857750bca2607ba1aabdae0d2303950310a',
57
+ 'SignedHeaders=host;x-amz-content-sha256;x-amz-date, ' \
58
+ 'Signature=9c4c690110483308f62a91c2ca873857750bca2607ba1aabdae0d2303950310a',
56
59
  'host' => 'localhost',
57
60
  'x-amz-content-sha256' => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
58
61
  'x-amz-date' => '20220101T000000Z' }
59
62
  end
60
63
 
61
- before(:each) do
64
+ before do
62
65
  Timecop.freeze(Time.utc(2022))
63
66
  client.transport = transport_double
64
67
  end
65
68
 
66
- after(:each) { Timecop.return }
69
+ after { Timecop.return }
67
70
 
68
71
  it 'signs the request before passing it to @transport' do
69
72
  output = client.perform_request('GET', '/', {}, '', {})
@@ -72,8 +75,27 @@ describe OpenSearch::Aws::Sigv4Client do
72
75
  end
73
76
 
74
77
  it 'skips the opensearch verification' do
75
- expect(client).to_not receive(:open_search_validation_request)
78
+ allow(client).to receive(:open_search_validation_request)
76
79
  client.perform_request('GET', '/_stats', {}, '', {})
80
+ expect(client).not_to have_received(:open_search_validation_request)
81
+ end
82
+
83
+ it 'passes the same body to sign_request and super' do
84
+ body = {
85
+ char_filter: {
86
+ test: {
87
+ type: 'mapping',
88
+ mappings: ["’ => '"]
89
+ }
90
+ }
91
+ }
92
+ signature_body = body.to_json
93
+
94
+ allow(signer).to receive(:sign_request).with(a_hash_including(body: signature_body)).and_call_original
95
+
96
+ client.perform_request('GET', '/', {}, body, {})
97
+
98
+ expect(transport_double).to have_received(:perform_request).with('GET', '/', {}, signature_body, kind_of(Hash))
77
99
  end
78
100
  end
79
101
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensearch-aws-sigv4
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - Theo Truong
8
- - Robin Roestenburg
7
+ - OpenSearch Contributors
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain:
12
11
  - |
13
12
  -----BEGIN CERTIFICATE-----
14
- MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRMwEQYDVQQDDApvcGVu
13
+ MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQsFADBCMRMwEQYDVQQDDApvcGVu
15
14
  c2VhcmNoMRYwFAYKCZImiZPyLGQBGRYGYW1hem9uMRMwEQYKCZImiZPyLGQBGRYD
16
- Y29tMB4XDTIyMDgxNzE3NTIzNFoXDTIzMDgxNzE3NTIzNFowQjETMBEGA1UEAwwK
15
+ Y29tMB4XDTIzMDgyNDIwNDIwNFoXDTI0MDgyMzIwNDIwNFowQjETMBEGA1UEAwwK
17
16
  b3BlbnNlYXJjaDEWMBQGCgmSJomT8ixkARkWBmFtYXpvbjETMBEGCgmSJomT8ixk
18
17
  ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM1z3/jcitjV
19
18
  umXwRFn+JSBBd36qZB54Dtucf6+E2fmNPzBRhgYN5XJy/+clQJ9NIJV7C8H52P3V
@@ -24,27 +23,27 @@ cert_chain:
24
23
  zfR37/NQFkECAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
25
24
  BBYEFJJ2myhLXK742btavNbG0IWrMNBIMCAGA1UdEQQZMBeBFW9wZW5zZWFyY2hA
26
25
  YW1hem9uLmNvbTAgBgNVHRIEGTAXgRVvcGVuc2VhcmNoQGFtYXpvbi5jb20wDQYJ
27
- KoZIhvcNAQEFBQADggEBAH5pWLYwKWFh1OjdCReGz/VEAiF4jXXputoN5Z8ga+1Z
28
- lg8/diJf0PlP2B46PdmxH/TVc/o+qglNO2cHVEp8xZfEd83dfioOBeK90URQUpC5
29
- UZmO0LZusg46SQKwKa2ukpIy2fNi3PeHRiV+W2Zv69GoWppyLun+fMez7wVoah2r
30
- r5ROUYuAvFUvga1Vm+49pKiPM5n+MAYP5t/vWhgymY3SYQ1TfewkvKAFiFXikOR+
31
- r+j7FLyKuk5DzIxiCp8QN5dU71BbGUmsHf/C5UV76WLPOFX/szeaHhPwpjR3sK7r
32
- 5zLgCV1KP7cgDdCYMlmZGeSViU8NV+Yy8/ghrzGpqVw=
26
+ KoZIhvcNAQELBQADggEBABAQpnELuY5AgdNUIlIVRVATO6iZOXTbt3a9oVbQdLPe
27
+ BfMObZyJydg0+leyR3oFyN9ZIFiEFwpd0biFf39DuC0M6Oge0Rv4oO9GRI3yyv77
28
+ 9m59he+5DI3hbqtGje108oqRe61NZMlKcy/DCBVkzzZFsJ17GC09tY/gwhmNRtLV
29
+ 3vYIEY6vmn57wrGn1NUzWdG+x/XVjYPw5Kwo+/rCxxZqpVTklMqVWV43N/lFrUOe
30
+ 1DlemA1SsUBIoF7CwtVd/RTG/K1iT6nBD08fdKxodMhI5ujkP3N7gkxzRf6aKN4z
31
+ glnDJYZjluKBUsKTOLdPW1CZpb0AHLpNqDf8SVHsPFk=
33
32
  -----END CERTIFICATE-----
34
- date: 2023-01-20 00:00:00.000000000 Z
33
+ date: 2023-10-03 00:00:00.000000000 Z
35
34
  dependencies:
36
35
  - !ruby/object:Gem::Dependency
37
36
  name: aws-sigv4
38
37
  requirement: !ruby/object:Gem::Requirement
39
38
  requirements:
40
- - - "~>"
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  version: '1'
43
42
  type: :runtime
44
43
  prerelease: false
45
44
  version_requirements: !ruby/object:Gem::Requirement
46
45
  requirements:
47
- - - "~>"
46
+ - - ">="
48
47
  - !ruby/object:Gem::Version
49
48
  version: '1'
50
49
  - !ruby/object:Gem::Dependency
@@ -61,179 +60,37 @@ dependencies:
61
60
  - - ">="
62
61
  - !ruby/object:Gem::Version
63
62
  version: 1.0.1
64
- - !ruby/object:Gem::Dependency
65
- name: bundler
66
- requirement: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: byebug
80
- requirement: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '0'
85
- type: :development
86
- prerelease: false
87
- version_requirements: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- - !ruby/object:Gem::Dependency
93
- name: pry
94
- requirement: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- type: :development
100
- prerelease: false
101
- version_requirements: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- - !ruby/object:Gem::Dependency
107
- name: rake
108
- requirement: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: '13'
113
- type: :development
114
- prerelease: false
115
- version_requirements: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '13'
120
- - !ruby/object:Gem::Dependency
121
- name: require-prof
122
- requirement: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- type: :development
128
- prerelease: false
129
- version_requirements: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- - !ruby/object:Gem::Dependency
135
- name: rspec
136
- requirement: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: '0'
141
- type: :development
142
- prerelease: false
143
- version_requirements: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- version: '0'
148
- - !ruby/object:Gem::Dependency
149
- name: ruby-prof
150
- requirement: !ruby/object:Gem::Requirement
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- version: '0'
155
- type: :development
156
- prerelease: false
157
- version_requirements: !ruby/object:Gem::Requirement
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- version: '0'
162
- - !ruby/object:Gem::Dependency
163
- name: simplecov
164
- requirement: !ruby/object:Gem::Requirement
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- version: '0'
169
- type: :development
170
- prerelease: false
171
- version_requirements: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- version: '0'
176
- - !ruby/object:Gem::Dependency
177
- name: yard
178
- requirement: !ruby/object:Gem::Requirement
179
- requirements:
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- version: '0'
183
- type: :development
184
- prerelease: false
185
- version_requirements: !ruby/object:Gem::Requirement
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- version: '0'
190
- - !ruby/object:Gem::Dependency
191
- name: timecop
192
- requirement: !ruby/object:Gem::Requirement
193
- requirements:
194
- - - ">="
195
- - !ruby/object:Gem::Version
196
- version: '0'
197
- type: :development
198
- prerelease: false
199
- version_requirements: !ruby/object:Gem::Requirement
200
- requirements:
201
- - - ">="
202
- - !ruby/object:Gem::Version
203
- version: '0'
204
- description: 'Ruby AWS Sigv4 Client for OpenSearch
205
-
206
- '
207
- email:
208
- - theo.nam.truong@gmail.com
209
- - robin.roestenburg@4me.com
63
+ description: |
64
+ A wrapper for opensearch-ruby gem that provides AWS Sigv4 signing.
65
+ It behaves like OpenSearch::Client, but signs every request with AWS Sigv4
66
+ using the credentials provided during the client's initialization.
67
+ email: opensearch@amazon.com
210
68
  executables:
211
69
  - opensearch_sigv4_console
212
70
  extensions: []
213
71
  extra_rdoc_files:
214
72
  - README.md
73
+ - USER_GUIDE.md
215
74
  - LICENSE
216
75
  files:
217
- - ".gitignore"
218
- - CHANGELOG.md
219
- - Gemfile
220
76
  - LICENSE
221
77
  - README.md
222
- - Rakefile
78
+ - USER_GUIDE.md
223
79
  - bin/opensearch_sigv4_console
224
80
  - lib/opensearch-aws-sigv4.rb
225
81
  - lib/opensearch-aws-sigv4/version.rb
82
+ - lib/opensearch_aws_sigv4.rb
226
83
  - opensearch-aws-sigv4.gemspec
227
- - spec/integration/sigv4_client_integration_spec.rb
228
- - spec/spec_helper.rb
229
- - spec/unit/sigv4_client_spec.rb
230
- homepage: https://opensearch.org/docs/latest
84
+ - spec/unit/open_search/aws/sigv4_client_spec.rb
85
+ homepage: https://github.com/opensearch-project/opensearch-ruby-aws-sigv4
231
86
  licenses:
232
87
  - Apache-2.0
233
88
  metadata:
234
- homepage_uri: https://opensearch.org/docs/latest/
235
- source_code_uri: https://github.com/opensearch-project/opensearch-ruby/tree/main
236
- bug_tracker_uri: https://github.com/opensearch-project/opensearch-ruby/issues
89
+ homepage_uri: https://github.com/opensearch-project/opensearch-ruby-aws-sigv4
90
+ documentation_uri: https://rubydoc.info/gems/opensearch-aws-sigv4/OpenSearch/Aws/Sigv4Client
91
+ source_code_uri: https://github.com/opensearch-project/opensearch-ruby-aws-sigv4/tree/main
92
+ bug_tracker_uri: https://github.com/opensearch-project/opensearch-ruby-aws-sigv4/issues
93
+ changelog_uri: https://github.com/opensearch-project/opensearch-ruby-aws-sigv4/blob/main/CHANGELOG.md
237
94
  post_install_message:
238
95
  rdoc_options:
239
96
  - "--charset=UTF-8"
@@ -243,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
100
  requirements:
244
101
  - - ">="
245
102
  - !ruby/object:Gem::Version
246
- version: '2.5'
103
+ version: '2.4'
247
104
  required_rubygems_version: !ruby/object:Gem::Requirement
248
105
  requirements:
249
106
  - - ">="
@@ -255,6 +112,4 @@ signing_key:
255
112
  specification_version: 4
256
113
  summary: Ruby AWS Sigv4 Client for OpenSearch
257
114
  test_files:
258
- - spec/integration/sigv4_client_integration_spec.rb
259
- - spec/spec_helper.rb
260
- - spec/unit/sigv4_client_spec.rb
115
+ - spec/unit/open_search/aws/sigv4_client_spec.rb
metadata.gz.sig CHANGED
Binary file
data/CHANGELOG.md DELETED
@@ -1,18 +0,0 @@
1
- # CHANGELOG
2
- Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3
-
4
- ## [Unreleased]
5
- ### Added
6
- - Added support for Amazon OpenSearch Serverless ([#131](https://github.com/opensearch-project/opensearch-ruby/issues/131))
7
-
8
- ### Changed
9
- ### Deprecated
10
- ### Removed
11
- ### Fixed
12
- - Sign validation requests when using AWS Sigv4 ([#134](https://github.com/opensearch-project/opensearch-ruby/pull/134))
13
-
14
- ### Security
15
-
16
- ## 1.0.0
17
- ### Added
18
- - Added `OpenSearch::AWS::Sigv4Client` ([#110](https://github.com/opensearch-project/opensearch-ruby/pull/110))
data/Gemfile DELETED
@@ -1,25 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0
2
- #
3
- # The OpenSearch Contributors require contributions made to
4
- # this file be licensed under the Apache-2.0 license or a
5
- # compatible open source license.
6
- #
7
- # Modifications Copyright OpenSearch Contributors. See
8
- # GitHub history for details.
9
-
10
- source 'https://rubygems.org'
11
-
12
- # Specify your gem's dependencies in opensearch-aws-sigv4.gemspec
13
- gemspec
14
-
15
- if File.exist? File.expand_path("../../opensearch-api/opensearch-api.gemspec", __FILE__)
16
- gem 'opensearch-api', :path => File.expand_path("../../opensearch-api", __FILE__), :require => false
17
- end
18
-
19
- if File.exist? File.expand_path("../../opensearch-transport/opensearch-transport.gemspec", __FILE__)
20
- gem 'opensearch-transport', :path => File.expand_path("../../opensearch-transport", __FILE__), :require => false
21
- end
22
-
23
- if File.exist? File.expand_path("../../opensearch-ruby/opensearch-ruby.gemspec", __FILE__)
24
- gem 'opensearch-ruby', :path => File.expand_path("../../opensearch-ruby", __FILE__), :require => false
25
- end
data/Rakefile DELETED
@@ -1,41 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0
2
- #
3
- # The OpenSearch Contributors require contributions made to
4
- # this file be licensed under the Apache-2.0 license or a
5
- # compatible open source license.
6
- #
7
- # Modifications Copyright OpenSearch Contributors. See
8
- # GitHub history for details.
9
-
10
- require 'bundler/gem_tasks'
11
-
12
- task(:default) { system 'rake --tasks' }
13
-
14
- desc 'Run unit tests'
15
- task test: 'test:spec'
16
-
17
- # ----- Test tasks ------------------------------------------------------------
18
- require 'rspec/core/rake_task'
19
-
20
- namespace :test do
21
- RSpec::Core::RakeTask.new(:integration) do |t|
22
- t.pattern = 'spec/integration/**{,/*/**}/*_spec.rb'
23
- end
24
-
25
- RSpec::Core::RakeTask.new(:unit) do |t|
26
- t.pattern = 'spec/unit/**{,/*/**}/*_spec.rb'
27
- end
28
-
29
- desc 'Run unit and integration tests'
30
- task :all do
31
- Rake::Task['test:unit'].invoke
32
- Rake::Task['test:integration'].invoke
33
- end
34
- end
35
-
36
- # ----- Documentation tasks ---------------------------------------------------
37
-
38
- require 'yard'
39
- YARD::Rake::YardocTask.new(:doc) do |t|
40
- t.options = %w| --embed-mixins --markup=markdown |
41
- end
@@ -1,42 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0
2
- #
3
- # The OpenSearch Contributors require contributions made to
4
- # this file be licensed under the Apache-2.0 license or a
5
- # compatible open source license.
6
- #
7
- # Modifications Copyright OpenSearch Contributors. See
8
- # GitHub history for details.
9
-
10
- require_relative '../spec_helper'
11
- require 'logger'
12
- require 'aws-sigv4'
13
-
14
- describe OpenSearch::Aws::Sigv4Client do
15
- let(:client) do
16
- signer = Aws::Sigv4::Signer.new(service: 'es',
17
- region: 'us-west-2',
18
- access_key_id: 'key_id',
19
- secret_access_key: 'secret')
20
-
21
- OpenSearch::Aws::Sigv4Client.new({ host: OPENSEARCH_URL, logger: Logger.new($stdout) }, signer)
22
- end
23
-
24
- it 'performs API actions without throwing any errors' do
25
- expect do
26
- # Index a document
27
- client.index(index: 'test-index', id: '1', body: { title: 'Test' })
28
-
29
- # Refresh the index
30
- client.indices.refresh(index: 'test-index')
31
-
32
- # Search
33
- response = client.search(index: 'test-index', body: { query: { match: { title: 'test' } } })
34
-
35
- expect(response['hits']['total']['value']).to eq 1
36
- expect(response['hits']['hits'][0]['_source']['title']).to eq 'Test'
37
-
38
- # Delete the index
39
- client.indices.delete(index: 'test-index')
40
- end.not_to raise_error
41
- end
42
- end
data/spec/spec_helper.rb DELETED
@@ -1,18 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0
2
- #
3
- # The OpenSearch Contributors require contributions made to
4
- # this file be licensed under the Apache-2.0 license or a
5
- # compatible open source license.
6
- #
7
- # Modifications Copyright OpenSearch Contributors. See
8
- # GitHub history for details.
9
-
10
- require 'opensearch-aws-sigv4'
11
- require 'rspec'
12
-
13
- OPENSEARCH_URL = ENV['TEST_OPENSEARCH_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
14
- raise URI::InvalidURIError unless OPENSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
15
-
16
- RSpec.configure do |config|
17
- config.formatter = :documentation
18
- end