opensearch-aws-sigv4 1.1.0 → 1.2.0

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: 8afd49d01221929f86b5bf1792d12a963cb969b5edc6a9abb242241c31170221
4
+ data.tar.gz: 278f930240341ab20ed9fe5f8182c1344b1825f7af7232001d096a320c90d9f7
5
5
  SHA512:
6
- metadata.gz: 6425d6f4b4925292cca4d1ab444643b40399ce6728b865715537df1c061c776bcb759b9fbd1f5d891a72e78ebf457ec601f4d3e0bb106e151d274a9aadb0e81c
7
- data.tar.gz: 0376e3c9a1b67e4885335ecd1a751cd2db67725242f5a09f84cfa905dcbed18b2cbe64043e8ffcbb1b638bc5b71917982be13da6186c6f04cbb9f10f73c18d1f
6
+ metadata.gz: cf3e31f4899441290c6ea65c452d52a1a21b5c36debc1c3bb1c0545d963526b86321ccaf0b136c75dd0dda5851bfe91a869154a08a3b01db2368ebe45c56955d
7
+ data.tar.gz: 2f5d79ef941d038d2c2f04a39266a8919c1c09626492da0946476b73b57c34565d8fcc05863c084e98f46e75f5d9e9f42416f5048a9674cd179ce1fbcf62c2c5
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -3,12 +3,18 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3
3
 
4
4
  ## [Unreleased]
5
5
  ### Added
6
- - Added support for Amazon OpenSearch Serverless ([#131](https://github.com/opensearch-project/opensearch-ruby/issues/131))
7
-
6
+ - Ability to printout Sigv4 Signature for debugging ([#149](https://github.com/opensearch-project/opensearch-ruby/issues/149))
8
7
  ### Changed
9
8
  ### Deprecated
10
9
  ### Removed
11
10
  ### Fixed
11
+
12
+ ### Security
13
+
14
+ ## [1.1.0]
15
+ ### Added
16
+ - Added support for Amazon OpenSearch Serverless ([#131](https://github.com/opensearch-project/opensearch-ruby/issues/131))
17
+ ### Fixed
12
18
  - Sign validation requests when using AWS Sigv4 ([#134](https://github.com/opensearch-project/opensearch-ruby/pull/134))
13
19
 
14
20
  ### Security
data/README.md CHANGED
@@ -1,101 +1,18 @@
1
- # OpenSearch Aws Sigv4 Client
1
+ - [OpenSearch AWS Sigv4 Client](#opensearch-aws-sigv4-client)
2
+ - [Compatibility](#compatibility)
3
+ - [User Guide](#user-guide)
4
+ - [License](#license)
5
+ # OpenSearch AWS Sigv4 Client
2
6
 
3
- The `opensearch-aws-sigv4` library provides an AWS Sigv4 client for [OpenSearch](http://opensearch.com).
7
+ 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).
4
8
 
5
9
  ## Compatibility
6
10
 
7
- The OpenSearch Aws Sigv4 Client is compatible with Ruby 2.5 and higher.
11
+ See [COMPATIBILITY](../COMPATIBILITY.md).
8
12
 
9
- The client's API is compatible with OpenSearch's API versions from 1.0.0 till current.
13
+ ## User Guide
10
14
 
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
- ### 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:
39
-
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
- ```
93
-
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.
95
-
96
- ## Development
97
-
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
 
data/USER_GUIDE.md ADDED
@@ -0,0 +1,59 @@
1
+ - [User Guide](#user-guide)
2
+ - [Setup](#setup)
3
+ - [Usage](#usage)
4
+ - [Amazon OpenSearch Service](#amazon-opensearch-service)
5
+ # User Guide
6
+ ## Setup
7
+
8
+ To add the gem to your project, install it using [RubyGems](https://rubygems.org/):
9
+
10
+ ```
11
+ gem install opensearch-aws-sigv4
12
+ ```
13
+
14
+ or add it to your Gemfile:
15
+ ```
16
+ gem opensearch-aws-sigv4
17
+ ```
18
+ and run:
19
+ ```
20
+ bundle install
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ This library is an AWS Sigv4 wrapper for [`opensearch-ruby`](https://github.com/opensearch-project/opensearch-ruby/tree/main/opensearch-ruby), which is a Ruby client for OpenSearch. The `OpenSearch::Aws::Sigv4Client`, therefore, has all features of `OpenSearch::Client`.
26
+
27
+ ### Amazon OpenSearch Service
28
+ To sign requests for the Amazon OpenSearch Service:
29
+
30
+ ```ruby
31
+ require 'opensearch-aws-sigv4'
32
+ require 'aws-sigv4'
33
+
34
+ signer = Aws::Sigv4::Signer.new(service: 'es', # signing service name, use "aoss" for OpenSearch Serverless
35
+ region: 'us-west-2', # signing service region
36
+ access_key_id: 'key_id',
37
+ secret_access_key: 'secret')
38
+
39
+ client = OpenSearch::Aws::Sigv4Client.new({
40
+ host: 'https://your.amz-managed-opensearch.domain', # serverless endpoint for OpenSearch Serverless
41
+ log: true
42
+ }, signer)
43
+
44
+ # create an index and document
45
+ index = 'prime'
46
+ client.indices.create(index: index)
47
+ client.index(index: index, id: '1', body: { name: 'Amazon Echo',
48
+ msrp: '5999',
49
+ year: 2011 })
50
+
51
+ # search for the document
52
+ client.search(body: { query: { match: { name: 'Echo' } } })
53
+
54
+ # delete the document
55
+ client.delete(index: index, id: '1')
56
+
57
+ # delete the index
58
+ client.indices.delete(index: index)
59
+ ```
@@ -10,7 +10,7 @@
10
10
  module OpenSearch
11
11
  module Aws
12
12
  module Sigv4
13
- VERSION = '1.1.0'.freeze
13
+ VERSION = '1.2.0'.freeze
14
14
  end
15
15
  end
16
16
  end
@@ -39,12 +39,16 @@ module OpenSearch
39
39
  # @param [Hash] transport_args arguments for OpenSearch::Transport::Client.
40
40
  # @param [&block] block code block to be passed to OpenSearch::Transport::Client.
41
41
  # @param [Aws::Sigv4::Signer] sigv4_signer an instance of AWS Sigv4 Signer.
42
- def initialize(transport_args = {}, sigv4_signer, &block)
42
+ # @param [Hash] options
43
+ # @option options [Boolean] :sigv4_debug whether to log debug info for Sigv4 Signing
44
+ def initialize(transport_args = {}, sigv4_signer, options: {}, &block)
43
45
  unless sigv4_signer.is_a?(::Aws::Sigv4::Signer)
44
46
  raise ArgumentError, "Please pass a Aws::Sigv4::Signer. A #{sigv4_signer.class} was given."
45
47
  end
46
48
 
47
49
  @sigv4_signer = sigv4_signer
50
+ @sigv4_debug = options[:sigv4_debug]
51
+ @logger = nil
48
52
  super(transport_args, &block)
49
53
  end
50
54
 
@@ -57,6 +61,8 @@ module OpenSearch
57
61
  headers: headers,
58
62
  body: signature_body)
59
63
  headers = (headers || {}).merge(signature.headers)
64
+
65
+ log_signature_info(signature)
60
66
  super(method, path, params, body, headers)
61
67
  end
62
68
 
@@ -72,6 +78,29 @@ module OpenSearch
72
78
  query_string = params.empty? ? '' : "#{Faraday::Utils::ParamsHash[params].to_query}"
73
79
  URI::HTTP.build(host: host, path: path, query: query_string)
74
80
  end
81
+
82
+ # @param [Aws::Sigv4::Signature] signature
83
+ def log_signature_info(signature)
84
+ return unless @sigv4_debug
85
+
86
+ log('string to sign', signature.string_to_sign)
87
+ log('canonical request', signature.canonical_request)
88
+ log('signature headers', signature.headers)
89
+ end
90
+
91
+ def log(title, message)
92
+ logger.debug("#{title.upcase}:\n\e[36m#{message}\e[0m")
93
+ end
94
+
95
+ def logger
96
+ return @logger if @logger
97
+
98
+ require 'logger'
99
+ @logger = Logger.new(
100
+ STDOUT,
101
+ progname: 'Sigv4',
102
+ formatter: proc { |_severity, datetime, progname, msg| "\e[34m(#{datetime}) #{progname} - #{msg}\e[0m\n\n" })
103
+ end
75
104
  end
76
105
  end
77
106
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Truong
@@ -31,7 +31,7 @@ cert_chain:
31
31
  r+j7FLyKuk5DzIxiCp8QN5dU71BbGUmsHf/C5UV76WLPOFX/szeaHhPwpjR3sK7r
32
32
  5zLgCV1KP7cgDdCYMlmZGeSViU8NV+Yy8/ghrzGpqVw=
33
33
  -----END CERTIFICATE-----
34
- date: 2023-01-20 00:00:00.000000000 Z
34
+ date: 2023-02-28 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aws-sigv4
@@ -220,6 +220,7 @@ files:
220
220
  - LICENSE
221
221
  - README.md
222
222
  - Rakefile
223
+ - USER_GUIDE.md
223
224
  - bin/opensearch_sigv4_console
224
225
  - lib/opensearch-aws-sigv4.rb
225
226
  - lib/opensearch-aws-sigv4/version.rb
metadata.gz.sig CHANGED
Binary file