opensearch-aws-sigv4 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43ed10e26e1b3308e4a19d3d479269c36d27b2244d4d688852afbf80d7fb16c9
4
+ data.tar.gz: 7c53006f740126f7f3a19fbc7b9a83f0096484c0240a514c8ff7c843fd8b5c2b
5
+ SHA512:
6
+ metadata.gz: f93669b3c6e92edad450f72aab6a53cfe1f0dd80bc2e63dfe4da8b2e9f78f7788933a45092d077d1df0926b9e20c53677529853b36ce6f56541781dba14358d0
7
+ data.tar.gz: 6951cf5f5f3da63dc30df598b21cb798945670055db39b8312b78bfd296bb33eea0538940b54cbfd255af9dd78ae49be2cbe11f41802d49320eafc14852f1ae1
checksums.yaml.gz.sig ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,28 @@
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
+ *.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
data/Gemfile ADDED
@@ -0,0 +1,25 @@
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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # OpenSearch Aws Sigv4 Client
2
+
3
+ The `opensearch-aws-sigv4` library provides an AWS Sigv4 client for [OpenSearch](http://opensearch.com).
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`.
36
+
37
+ ```ruby
38
+ require 'opensearch-aws-sigv4'
39
+ require 'aws-sigv4'
40
+
41
+ signer = Aws::Sigv4::Signer.new(service: 'es',
42
+ region: 'us-west-2',
43
+ access_key_id: 'key_id',
44
+ secret_access_key: 'secret')
45
+
46
+ client = OpenSearch::Aws::Sigv4Client.new({ log: true }, signer)
47
+
48
+ client.cluster.health
49
+
50
+ client.transport.reload_connections!
51
+
52
+ client.search q: 'test'
53
+ ```
54
+
55
+ Please refer to [opensearch-ruby](https://github.com/opensearch-project/opensearch-ruby/blob/main/opensearch-ruby/README.md) documentation for further details.
56
+
57
+ ## Development
58
+
59
+ You can run `rake -T` to check the test tasks. Use `COVERAGE=true` before running a test task to check the coverage with Simplecov.
60
+
61
+ ## License
62
+
63
+ This software is licensed under the [Apache 2 license](./LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,41 @@
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
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
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__))
8
+
9
+ 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)
25
+
26
+ begin
27
+ require 'pry'
28
+ rescue LoadError
29
+ end
30
+
31
+ begin
32
+ 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
+ IRB.start
41
+ else
42
+ abort 'LoadError: opensearch_sigv4_console requires Pry or IRB'
43
+ end
@@ -0,0 +1,16 @@
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
+ module OpenSearch
11
+ module Aws
12
+ module Sigv4
13
+ VERSION = '1.0.0'.freeze
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,74 @@
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-ruby'
11
+ require 'aws-sigv4/signer'
12
+ require 'faraday'
13
+ require 'json'
14
+
15
+ module OpenSearch
16
+ module Aws
17
+ # AWS Sigv4 Wrapper for OpenSearch::Client.
18
+ # This client accepts a Sigv4 Signer during initialization, and signs every request
19
+ # with a Sigv4 Signature with the provided signer.
20
+ #
21
+ # @example
22
+ # signer = Aws::Sigv4::Signer.new(service: 'es',
23
+ # region: 'us-east-1',
24
+ # access_key_id: '<access_key_id>',
25
+ # secret_access_key: '<secret_access_key>',
26
+ # session_token: '<session_token>')
27
+ #
28
+ # client = OpenSearch::Aws::Sigv4Client.new(
29
+ # { host: 'https://my-os-domain.us-east-1.es.amazonaws.com/' },
30
+ # signer
31
+ # )
32
+ #
33
+ # puts client.cat.health
34
+ #
35
+ # @attr [Aws::Sigv4::Signer] sigv4_signer Signer used to sign every request
36
+ class Sigv4Client < ::OpenSearch::Client
37
+ attr_accessor :sigv4_signer
38
+
39
+ # @param [Hash] transport_args arguments for OpenSearch::Transport::Client.
40
+ # @param [&block] block code block to be passed to OpenSearch::Transport::Client.
41
+ # @param [Aws::Sigv4::Signer] sigv4_signer an instance of AWS Sigv4 Signer.
42
+ def initialize(transport_args = {}, sigv4_signer, &block)
43
+ unless sigv4_signer.is_a?(::Aws::Sigv4::Signer)
44
+ raise ArgumentError, "Please pass a Aws::Sigv4::Signer. A #{sigv4_signer.class} was given."
45
+ end
46
+
47
+ @sigv4_signer = sigv4_signer
48
+ super transport_args, &block
49
+ end
50
+
51
+ # @see OpenSearch::Transport::Transport::Base::perform_request
52
+ def perform_request(method, path, params = {}, body = nil, headers = nil)
53
+ verify_open_search unless @verified
54
+ signature_body = body.is_a?(Hash) ? body.to_json : body.to_s
55
+ signature = sigv4_signer.sign_request(
56
+ http_method: method,
57
+ url: signature_url(path, params),
58
+ headers: headers,
59
+ body: signature_body)
60
+ headers = (headers || {}).merge(signature.headers)
61
+ @transport.perform_request(method, path, params, body, headers)
62
+ end
63
+
64
+ private
65
+
66
+ def signature_url(path, params)
67
+ host = @transport.transport.hosts.dig(0, :host)
68
+ path = '/' + path unless path.start_with?('/')
69
+ query_string = params.empty? ? '' : "#{Faraday::Utils::ParamsHash[params].to_query}"
70
+ URI::HTTP.build(host: host, path: path, query: query_string)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,64 @@
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
+ lib = File.expand_path('../lib', __FILE__)
11
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
12
+ require 'opensearch-aws-sigv4/version'
13
+
14
+ signing_key_path = File.expand_path("../gem-private_key.pem")
15
+
16
+ Gem::Specification.new do |s|
17
+ s.name = 'opensearch-aws-sigv4'
18
+ s.version = OpenSearch::Aws::Sigv4::VERSION
19
+ s.authors = ['Theo Truong']
20
+ s.email = ['theo.nam.truong@gmail.com']
21
+ s.summary = 'Ruby AWS Sigv4 Client for OpenSearch'
22
+ s.homepage = 'https://opensearch.org/docs/latest'
23
+ s.license = 'Apache-2.0'
24
+ 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
+ }
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
+
39
+ s.require_paths = ['lib']
40
+ s.bindir = 'bin'
41
+
42
+ s.extra_rdoc_files = [ 'README.md', 'LICENSE' ]
43
+ s.rdoc_options = [ '--charset=UTF-8' ]
44
+
45
+ s.required_ruby_version = '>= 2.5'
46
+
47
+ s.add_dependency 'aws-sigv4', '~> 1'
48
+ s.add_dependency 'opensearch-ruby', '>= 1.0.1'
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'
60
+
61
+ s.description = <<-DESC.gsub(/^ /, '')
62
+ Ruby AWS Sigv4 Client for OpenSearch
63
+ DESC
64
+ end
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,75 @@
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 'aws-sigv4'
12
+ require 'timecop'
13
+
14
+ describe OpenSearch::Aws::Sigv4Client do
15
+ subject(:client) do
16
+ OpenSearch::Aws::Sigv4Client.new(
17
+ { host: 'http://localhost:9200',
18
+ transport_options: { ssl: { verify: false } } },
19
+ signer)
20
+ end
21
+
22
+ let(:signer) do
23
+ Aws::Sigv4::Signer.new(service: 'es',
24
+ region: 'us-west-2',
25
+ access_key_id: 'key_id',
26
+ secret_access_key: 'secret')
27
+ end
28
+
29
+ describe '.initialize' do
30
+ context 'when a Sigv4 Signer is NOT provided' do
31
+ let(:signer) { nil }
32
+
33
+ it 'raises an argument error' do
34
+ expect { client }.to raise_error ArgumentError, 'Please pass a Aws::Sigv4::Signer. A NilClass was given.'
35
+ end
36
+ end
37
+
38
+ context 'when a Sigv4 Signer is provided' do
39
+ it 'does NOT raise any error' do
40
+ expect { client }.to_not raise_error
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#perform_request' do
46
+ let(:response) { { body: 'Response Body' } }
47
+ 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
+ end
52
+ let(:signed_headers) do
53
+ { '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',
56
+ 'host' => 'localhost',
57
+ 'x-amz-content-sha256' => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
58
+ 'x-amz-date' => '20220101T000000Z' }
59
+ end
60
+
61
+ before(:each) do
62
+ Timecop.freeze(Time.utc(2022))
63
+ allow(client).to receive(:verify_open_search) { true }
64
+ client.transport = transport_double
65
+ end
66
+
67
+ after(:each) { Timecop.return }
68
+
69
+ it 'signs the request before passing it to @transport' do
70
+ output = client.perform_request('GET', '/', {}, '', {})
71
+ expect(output).to eq(response)
72
+ expect(transport_double).to have_received(:perform_request).with('GET', '/', {}, '', signed_headers)
73
+ end
74
+ end
75
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ I<�=i�L�E:|p�
2
+ �;����e^���4@<,t������$h�5ڍb���6�[���2F�di����6hϋ
3
+ s��_Jg����[�^8�R���(����8����b�<TT�0#���O���1�Y���V�X��P�B�������HߞZ��������:(��x�$�v��+�:�o ��=nj#���_���֋@4��,�r�?'�N���5ϯ$�xTJ"6@�q�[l�`q�F�e�:)0p5E
metadata ADDED
@@ -0,0 +1,257 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opensearch-aws-sigv4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Theo Truong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRMwEQYDVQQDDApvcGVu
14
+ c2VhcmNoMRYwFAYKCZImiZPyLGQBGRYGYW1hem9uMRMwEQYKCZImiZPyLGQBGRYD
15
+ Y29tMB4XDTIyMDgxNzE3NTIzNFoXDTIzMDgxNzE3NTIzNFowQjETMBEGA1UEAwwK
16
+ b3BlbnNlYXJjaDEWMBQGCgmSJomT8ixkARkWBmFtYXpvbjETMBEGCgmSJomT8ixk
17
+ ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM1z3/jcitjV
18
+ umXwRFn+JSBBd36qZB54Dtucf6+E2fmNPzBRhgYN5XJy/+clQJ9NIJV7C8H52P3V
19
+ dsce/VXcNAcgfUdlN57nM0ksjFFNlnHWXea8Ub9/6R1K0p1RBizEINzUneoJLvqe
20
+ 7w/KfvBJStj7AmJgZmzCiu98j75YLcdLhZQykRyJdB03wZsMQUvxPFkhTZn+Qi8k
21
+ 0U909l9JD0i1PC0xVukYlskUA2xeo36kMMllABJGN536Z0aIT2KX2XTiKK7hILoP
22
+ +flNmgA4eyXa5Ki9q4HBN6QhsTKdEinqGngQnUI35YTu2AHsvfjn1wP/nUa9aRVH
23
+ zfR37/NQFkECAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
24
+ BBYEFJJ2myhLXK742btavNbG0IWrMNBIMCAGA1UdEQQZMBeBFW9wZW5zZWFyY2hA
25
+ YW1hem9uLmNvbTAgBgNVHRIEGTAXgRVvcGVuc2VhcmNoQGFtYXpvbi5jb20wDQYJ
26
+ KoZIhvcNAQEFBQADggEBAH5pWLYwKWFh1OjdCReGz/VEAiF4jXXputoN5Z8ga+1Z
27
+ lg8/diJf0PlP2B46PdmxH/TVc/o+qglNO2cHVEp8xZfEd83dfioOBeK90URQUpC5
28
+ UZmO0LZusg46SQKwKa2ukpIy2fNi3PeHRiV+W2Zv69GoWppyLun+fMez7wVoah2r
29
+ r5ROUYuAvFUvga1Vm+49pKiPM5n+MAYP5t/vWhgymY3SYQ1TfewkvKAFiFXikOR+
30
+ r+j7FLyKuk5DzIxiCp8QN5dU71BbGUmsHf/C5UV76WLPOFX/szeaHhPwpjR3sK7r
31
+ 5zLgCV1KP7cgDdCYMlmZGeSViU8NV+Yy8/ghrzGpqVw=
32
+ -----END CERTIFICATE-----
33
+ date: 2022-11-30 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: aws-sigv4
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1'
49
+ - !ruby/object:Gem::Dependency
50
+ name: opensearch-ruby
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.1
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.1
63
+ - !ruby/object:Gem::Dependency
64
+ name: bundler
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ - !ruby/object:Gem::Dependency
78
+ name: byebug
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ - !ruby/object:Gem::Dependency
92
+ name: pry
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ - !ruby/object:Gem::Dependency
106
+ name: rake
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '13'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '13'
119
+ - !ruby/object:Gem::Dependency
120
+ name: require-prof
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ - !ruby/object:Gem::Dependency
134
+ name: rspec
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ - !ruby/object:Gem::Dependency
148
+ name: ruby-prof
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ - !ruby/object:Gem::Dependency
162
+ name: simplecov
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ - !ruby/object:Gem::Dependency
176
+ name: yard
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ - !ruby/object:Gem::Dependency
190
+ name: timecop
191
+ requirement: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ type: :development
197
+ prerelease: false
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ description: 'Ruby AWS Sigv4 Client for OpenSearch
204
+
205
+ '
206
+ email:
207
+ - theo.nam.truong@gmail.com
208
+ executables:
209
+ - opensearch_sigv4_console
210
+ extensions: []
211
+ extra_rdoc_files:
212
+ - README.md
213
+ - LICENSE
214
+ files:
215
+ - ".gitignore"
216
+ - Gemfile
217
+ - LICENSE
218
+ - README.md
219
+ - Rakefile
220
+ - bin/opensearch_sigv4_console
221
+ - lib/opensearch-aws-sigv4.rb
222
+ - lib/opensearch-aws-sigv4/version.rb
223
+ - opensearch-aws-sigv4.gemspec
224
+ - spec/integration/sigv4_client_integration_spec.rb
225
+ - spec/spec_helper.rb
226
+ - spec/unit/sigv4_client_spec.rb
227
+ homepage: https://opensearch.org/docs/latest
228
+ licenses:
229
+ - Apache-2.0
230
+ metadata:
231
+ homepage_uri: https://opensearch.org/docs/latest/
232
+ source_code_uri: https://github.com/opensearch-project/opensearch-ruby/tree/main
233
+ bug_tracker_uri: https://github.com/opensearch-project/opensearch-ruby/issues
234
+ post_install_message:
235
+ rdoc_options:
236
+ - "--charset=UTF-8"
237
+ require_paths:
238
+ - lib
239
+ required_ruby_version: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '2.5'
244
+ required_rubygems_version: !ruby/object:Gem::Requirement
245
+ requirements:
246
+ - - ">="
247
+ - !ruby/object:Gem::Version
248
+ version: '0'
249
+ requirements: []
250
+ rubygems_version: 3.3.26
251
+ signing_key:
252
+ specification_version: 4
253
+ summary: Ruby AWS Sigv4 Client for OpenSearch
254
+ test_files:
255
+ - spec/integration/sigv4_client_integration_spec.rb
256
+ - spec/spec_helper.rb
257
+ - spec/unit/sigv4_client_spec.rb
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ )2�60U�$��������
2
+ ��6P�wM0~D͹P����bӒ56��1G`���V�<`L�