aws-crt 0.1.1.pre-x86_64-linux → 0.1.2-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e62cfd46e46d91a5ea5f0de7b21fccd76082dde8f1ae84307808869eded6c2e3
4
- data.tar.gz: 9bc886a6bc951c9bd9fe4eb147a7eb708e5d7cc034dcf7b1e80be79bdfd71509
3
+ metadata.gz: 83b919be5a89b746f166fc22389aeceb078dfbcdf7ecf458f892d8e99a01192f
4
+ data.tar.gz: c8ce81ae51b834875ff209f1e6cb6d90e4f3fc9d33307fe68e727cdfe1f1220d
5
5
  SHA512:
6
- metadata.gz: 3ef09981c4c16b3ae3e709b602e75c950c2d166801e5d7e374f3e51690208a82660da04b6c67dab56f48179790fe9ac3f96322df1e8ac49d7b6e201efbeefaf6
7
- data.tar.gz: 61f0f6b8dd630ca4a7946b7a76e1cc512f24341b6ea79b184905efa472717ec4991496be809685297d4163872fe2900aef929d12d6840d03fc8312915fd47e6a
6
+ metadata.gz: 05f774f1512aaa6a44b8bf682a7fa62b729a1b9b298f145499f2bd918589b9304b5e5c9963d579e00bf169080c6f6cc42552d89267c205df3114b0ad2baae271
7
+ data.tar.gz: ff3560f5d419f0d05f1cb1ad95b098ee6d30cd671a9abcbd8de27d6a1425e297441bce23009ad557cad2652ff77f527c69e26c227f39336d5ef888ce13f2376e
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ Unreleased Changes
2
+ ------------------
3
+
4
+
5
+ 0.1.0 (2021-08-04)
6
+ ------------------
7
+
8
+ * Feature - Initial preview release of `aws-crt` gem.
data/LICENSE.txt 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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1.pre
1
+ 0.1.2
Binary file
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ module Auth
6
+ # CRT CredentialOptions
7
+ class CredentialsOptions
8
+ include Aws::Crt::ManagedNative
9
+ native_destroy Aws::Crt::Native.method(:credentials_options_release)
10
+
11
+ UINT64_MAX = 18_446_744_073_709_551_615
12
+
13
+ # @param [String] access_key_id
14
+ # @param [String] secret_access_key
15
+ # @param [String] session_token (nil)
16
+ # @param [Time|int] expiration (nil) - Either a Time or an int
17
+ # seconds since unix epoch
18
+ def initialize(access_key_id, secret_access_key,
19
+ session_token = nil, expiration = nil)
20
+ if !access_key_id || access_key_id.empty?
21
+ raise ArgumentError, 'access_key_id must be set'
22
+ end
23
+
24
+ if !secret_access_key || secret_access_key.empty?
25
+ raise ArgumentError, 'secret_access_key must be set'
26
+ end
27
+
28
+ manage_native do
29
+ Aws::Crt::Native.credentials_options_new
30
+ end
31
+
32
+ Aws::Crt::Native.credentials_options_set_access_key_id(
33
+ native, access_key_id, access_key_id.length
34
+ )
35
+
36
+ Aws::Crt::Native.credentials_options_set_secret_access_key(
37
+ native, secret_access_key, secret_access_key.length
38
+ )
39
+
40
+ if session_token && !session_token.empty?
41
+ Aws::Crt::Native.credentials_options_set_session_token(
42
+ native, session_token, session_token.length
43
+ )
44
+ end
45
+
46
+ Aws::Crt::Native.credentials_options_set_expiration_timepoint_seconds(
47
+ native, expiration&.to_i || UINT64_MAX
48
+ )
49
+ end
50
+ end
51
+
52
+ # Utility class for Credentials.
53
+ class Credentials
54
+ include Aws::Crt::ManagedNative
55
+ native_destroy Aws::Crt::Native.method(:credentials_release)
56
+
57
+ # @param [String] access_key_id
58
+ # @param [String] secret_access_key
59
+ # @param [String] session_token (nil)
60
+ # @param [Time|int] expiration (nil) - Either a Time or an int
61
+ # seconds since unix epoch
62
+ def initialize(access_key_id, secret_access_key,
63
+ session_token = nil, expiration = nil)
64
+
65
+ credential_options = CredentialsOptions.new(
66
+ access_key_id, secret_access_key,
67
+ session_token, expiration
68
+ )
69
+ manage_native do
70
+ Aws::Crt::Native.credentials_new(
71
+ credential_options.native
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ module Auth
6
+ # Signing Config
7
+ class Signable
8
+ include Aws::Crt::ManagedNative
9
+ native_destroy Aws::Crt::Native.method(:signable_release)
10
+
11
+ # @param [Http::Message] http_request
12
+ def initialize(http_request)
13
+ manage_native do
14
+ Aws::Crt::Native.signable_new_from_http_request(http_request.native)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ # High level Ruby abstractions for CRT Auth functionality
6
+ module Auth
7
+ # Ruby interface to CRT signing functions
8
+ module Signer
9
+ # Sign a request
10
+ # @param [SigningConfig] - SigningConfig to apply to this signature
11
+ # @param [Signable] - Signable object (request) to sign.
12
+ #
13
+ # @return [Hash] Return a hash with keys:
14
+ # * signature[String] - the computed signature
15
+ # * headers[Hash] - signed headers, including the `Authorization`
16
+ # header.
17
+ def self.sign_request(
18
+ signing_config, signable, method = 'default', path = 'default'
19
+ )
20
+ out = {}
21
+ callback = proc do |result, status, _userdata|
22
+ Aws::Crt::Errors.raise_last_error unless status.zero?
23
+ http_request = Http::Message.new(method, path)
24
+ Aws::Crt::Native.signing_result_apply_to_http_request(
25
+ result,
26
+ http_request.native
27
+ )
28
+ out[:path] = http_request.path
29
+ out[:headers] = http_request.headers
30
+ if (auth = out[:headers]['Authorization']) &&
31
+ (match = /Signature=([a-f0-9]+)/.match(auth))
32
+ out[:signature] = match[1]
33
+ end
34
+ out[:http_request] = http_request
35
+
36
+ nil
37
+ end
38
+
39
+ # Currently this will always be synchronous
40
+ # (because we are resolving credentials) - so do not need to
41
+ # sync threads/callbacks
42
+ Aws::Crt::Native.sign_request_aws(
43
+ signable.native, signing_config.native, callback, nil
44
+ )
45
+ out
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Aws
6
+ module Crt
7
+ module Auth
8
+ # Signing Config
9
+ class SigningConfig
10
+ include Aws::Crt::ManagedNative
11
+ native_destroy Aws::Crt::Native.method(:signing_config_aws_release)
12
+
13
+ # @param [Hash] options
14
+ # @option options [required, Aws::Crt::Native::signing_algorithm]
15
+ # :algorithm
16
+ # @option options [required, Aws::Crt::Native::signature_type]
17
+ # :signature_type
18
+ # @option options [required, Credentials] :credentials
19
+ # @option options [required, String] :region
20
+ # @option options [required, String] :service
21
+ # @option options [Time] :date (Time.now)
22
+ # @option options [Array<String>]
23
+ # :unsigned_headers ([])
24
+ # @option options [Boolean] :use_double_uri_encode (false)
25
+ # @option options [Boolean] :should_normalize_uri_path (false)
26
+ # @option options [Boolean] :omit_session_token (false)
27
+
28
+ # @option options [Boolean] :signed_body_header_type
29
+ # (:sbht_content_sha256) -
30
+ # Controls if signing adds a header containing the
31
+ # canonical request's body value
32
+ # @option options [String] :signed_body_value - Optional string to use
33
+ # as the canonical request's body value. If string is empty, a value
34
+ # will be calculated from the payload during signing. Typically,
35
+ # this is the SHA-256 of the (request/chunk/event) payload,
36
+ # written as lowercase hex. If this has been precalculated, it can
37
+ # be set here. Special values used by certain services can also
38
+ # be set (e.g. "UNSIGNED-PAYLOAD"
39
+ # "STREAMING-AWS4-HMAC-SHA256-PAYLOAD"
40
+ # "STREAMING-AWS4-HMAC-SHA256-EVENTS").
41
+ # @option options[Integer] :expiration_in_seconds (0) -
42
+ # If non-zero and the
43
+ # signing transform is query param, then signing will add
44
+ # X-Amz-Expires to the query string, equal to the value
45
+ # specified here. If this value is zero or if header signing
46
+ # is being used then this parameter has no effect.
47
+ def initialize(options = {})
48
+ # validation of parameters is handled in signing_config_new
49
+
50
+ # create a callback function for aws_should_sign_header_fn
51
+ @sign_header_fn = extract_unsigned_header_fn(
52
+ options[:unsigned_headers]
53
+ )
54
+
55
+ signed_body_header_type = options.fetch(
56
+ :signed_body_header_type,
57
+ :sbht_content_sha256
58
+ )
59
+
60
+ # ensure we retain a reference to the credentials to avoid GC
61
+ @credentials = options[:credentials]
62
+ manage_native do
63
+ Aws::Crt::Native.signing_config_aws_new
64
+ end
65
+
66
+ Aws::Crt::Native.signing_config_aws_set_algorithm(native, options[:algorithm])
67
+ Aws::Crt::Native.signing_config_aws_set_signature_type(native, options[:signature_type])
68
+ Aws::Crt::Native.signing_config_aws_set_region(native, options[:region], options[:region].length)
69
+ Aws::Crt::Native.signing_config_aws_set_service(native, options[:service], options[:service].length)
70
+ Aws::Crt::Native.signing_config_aws_set_date(native, extract_date(options))
71
+ Aws::Crt::Native.signing_config_aws_set_credentials_provider(native, @credentials&.native)
72
+ Aws::Crt::Native.signing_config_aws_set_signed_body_header_type(native, signed_body_header_type)
73
+ if @sign_header_fn
74
+ Aws::Crt::Native.signing_config_aws_set_should_sign_header_fn(native, @sign_header_fn)
75
+ end
76
+
77
+ assign_body_value(options)
78
+ assign_flags(options)
79
+
80
+ validate_config!
81
+ end
82
+
83
+ private
84
+
85
+ def extract_date(options)
86
+ (options[:date] || Time.now).to_i
87
+ end
88
+
89
+ def extract_unsigned_header_fn(unsigned_headers)
90
+ return nil unless unsigned_headers&.size&.positive?
91
+
92
+ unsigned_headers = Set.new(unsigned_headers.map(&:downcase))
93
+ proc do |param_ptr, len, _p|
94
+ param = param_ptr.read_string(len)
95
+ !unsigned_headers.include? param.to_s.downcase
96
+ end
97
+ end
98
+
99
+ def assign_flags(options)
100
+ Aws::Crt::Native.signing_config_aws_set_use_double_uri_encode(native, options.fetch(:use_double_uri_encode, false))
101
+ Aws::Crt::Native.signing_config_aws_set_should_normalize_uri_path(native, options.fetch(:should_normalize_uri_path, false))
102
+ Aws::Crt::Native.signing_config_aws_set_omit_session_token(native, options.fetch(:omit_session_token, false))
103
+ Aws::Crt::Native.signing_config_aws_set_expiration_in_seconds(native, options.fetch(:expiration_in_seconds, 0))
104
+ end
105
+
106
+ def assign_body_value(options)
107
+ if options[:signed_body_value]
108
+ Aws::Crt::Native.signing_config_aws_set_signed_body_value(native, options[:signed_body_value], options[:signed_body_value].length)
109
+ end
110
+ end
111
+
112
+ def validate_config!
113
+ unless Aws::Crt::Native.signing_config_aws_validate(native)
114
+ # validate returns a boolean rather than int to indicate status
115
+ # but still sets the exception
116
+ Errors.raise_last_error
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ module Auth
6
+ # CRT CredentialOptions
7
+ class StaticCredentialsProviderOptions
8
+ include Aws::Crt::ManagedNative
9
+ native_destroy Aws::Crt::Native.method(:credentials_provider_static_options_release)
10
+
11
+ # @param [String] access_key_id
12
+ # @param [String] secret_access_key
13
+ # @param [String] session_token (nil)
14
+ def initialize(access_key_id, secret_access_key,
15
+ session_token = nil)
16
+ if !access_key_id || access_key_id.empty?
17
+ raise ArgumentError, 'access_key_id must be set'
18
+ end
19
+
20
+ if !secret_access_key || secret_access_key.empty?
21
+ raise ArgumentError, 'secret_access_key must be set'
22
+ end
23
+
24
+ manage_native do
25
+ Aws::Crt::Native.credentials_provider_static_options_new
26
+ end
27
+
28
+ Aws::Crt::Native.credentials_provider_static_options_set_access_key_id(
29
+ native, access_key_id, access_key_id.length
30
+ )
31
+
32
+ Aws::Crt::Native.credentials_provider_static_options_set_secret_access_key(
33
+ native, secret_access_key, secret_access_key.length
34
+ )
35
+
36
+ if session_token && !session_token.empty?
37
+ Aws::Crt::Native.credentials_provider_static_options_set_session_token(
38
+ native, session_token, session_token.length
39
+ )
40
+ end
41
+ end
42
+ end
43
+
44
+ # Utility class for Credentials.
45
+ class StaticCredentialsProvider
46
+ include Aws::Crt::ManagedNative
47
+ native_destroy Aws::Crt::Native.method(:credentials_provider_release)
48
+
49
+ # @param [String] access_key_id
50
+ # @param [String] secret_access_key
51
+ # @param [String] session_token (nil)
52
+ def initialize(access_key_id, secret_access_key,
53
+ session_token = nil)
54
+
55
+ credential_options = StaticCredentialsProviderOptions.new(
56
+ access_key_id, secret_access_key,
57
+ session_token
58
+ )
59
+ manage_native do
60
+ Aws::Crt::Native.credentials_provider_static_new(
61
+ credential_options.native
62
+ )
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ # High level Ruby abstractions for CRT Checksums functionality
6
+ module Checksums
7
+ def self.crc32(str, previous = 0)
8
+ Aws::Crt::Native.crc32(
9
+ FFI::MemoryPointer.from_string(str),
10
+ str.size,
11
+ previous
12
+ )
13
+ end
14
+
15
+ def self.crc32c(str, previous = 0)
16
+ Aws::Crt::Native.crc32c(
17
+ FFI::MemoryPointer.from_string(str),
18
+ str.size,
19
+ previous
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ # High level Ruby abstractions for CRT HTTP functionality
6
+ module Http
7
+ # HTTP Headers
8
+ class Headers
9
+ include Aws::Crt::ManagedNative
10
+ native_destroy Aws::Crt::Native.method(
11
+ :http_headers_release
12
+ )
13
+
14
+ def initialize(headers = {})
15
+ blob = StringBlob.encode(headers.flatten)
16
+ blob_ptr = FFI::MemoryPointer.new(:char, blob.length)
17
+ blob_ptr.write_array_of_char(blob)
18
+
19
+ manage_native do
20
+ Aws::Crt::Native.http_headers_new_from_blob(blob_ptr, blob.length)
21
+ end
22
+ end
23
+
24
+ def to_blob_strings
25
+ buf_out = Aws::Crt::Native::CrtBuf.new
26
+ Aws::Crt::Native.http_headers_to_blob(native, buf_out)
27
+ StringBlob.decode(buf_out.to_blob)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ # High level Ruby abstractions for CRT HTTP functionality
6
+ module Http
7
+ # HTTP Message (request)
8
+ class Message
9
+ include Aws::Crt::ManagedNative
10
+ native_destroy Aws::Crt::Native.method(
11
+ :http_message_release
12
+ )
13
+
14
+ def initialize(method, path, headers = {})
15
+ strings = [method, path] +
16
+ headers.flatten
17
+ blob = StringBlob.encode(strings)
18
+ blob_ptr = FFI::MemoryPointer.new(:char, blob.length)
19
+ blob_ptr.write_array_of_char(blob)
20
+
21
+ manage_native do
22
+ Aws::Crt::Native.http_message_new_from_blob(blob_ptr, blob.length)
23
+ end
24
+ end
25
+
26
+ def to_blob_strings
27
+ buf_out = Aws::Crt::Native::CrtBuf.new
28
+ Aws::Crt::Native.http_message_to_blob(native, buf_out)
29
+ StringBlob.decode(buf_out.to_blob)
30
+ end
31
+
32
+ def headers
33
+ blob_strings = to_blob_strings
34
+ # blob_strings must have at least 2 element and must have
35
+ # pairs of header/values
36
+ if blob_strings.length < 2 ||
37
+ blob_strings.length.odd?
38
+ raise Aws::Crt::Errors::Error,
39
+ 'Invalid blob_string for HTTP Message'
40
+ end
41
+ blob_strings[2..blob_strings.length].each_slice(2).to_h
42
+ end
43
+
44
+ def method
45
+ to_blob_strings[0]
46
+ end
47
+
48
+ def path
49
+ to_blob_strings[1]
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -4,13 +4,12 @@ module Aws
4
4
  module Crt
5
5
  # High level Ruby abstractions for CRT IO functionality
6
6
  module IO
7
- # A collection of event-loops.
8
- # An event-loop is a thread for doing async work, such as I/O.
9
- # Classes that need to do async work will ask the EventLoopGroup
10
- # for an event-loop to use.
11
- class EventLoopGroup
7
+ # Options for an EventLoopGroup
8
+ class EventLoopGroupOptions
12
9
  include Aws::Crt::ManagedNative
13
- native_destroy Aws::Crt::Native.method(:event_loop_group_release)
10
+ native_destroy Aws::Crt::Native.method(
11
+ :event_loop_group_options_release
12
+ )
14
13
 
15
14
  def initialize(max_threads = nil)
16
15
  unless max_threads.nil? ||
@@ -22,8 +21,29 @@ module Aws
22
21
  max_threads = 0 if max_threads.nil?
23
22
 
24
23
  manage_native do
25
- Aws::Crt::Native.event_loop_group_new(max_threads)
24
+ Aws::Crt::Native.event_loop_group_options_new
25
+ end
26
+
27
+ Aws::Crt::Native.event_loop_group_options_set_max_threads(@native,
28
+ max_threads)
29
+ end
30
+ end
31
+
32
+ # A collection of event-loops.
33
+ # An event-loop is a thread for doing async work, such as I/O.
34
+ # Classes that need to do async work will ask the EventLoopGroup
35
+ # for an event-loop to use.
36
+ class EventLoopGroup
37
+ include Aws::Crt::ManagedNative
38
+ native_destroy Aws::Crt::Native.method(:event_loop_group_release)
39
+
40
+ def initialize(max_threads = nil)
41
+ @options = EventLoopGroupOptions.new(max_threads)
42
+
43
+ manage_native do
44
+ Aws::Crt::Native.event_loop_group_new(@options.native)
26
45
  end
46
+ Aws::Crt::Native.event_loop_group_acquire(@native)
27
47
  end
28
48
  end
29
49
  end
@@ -7,17 +7,18 @@ module Aws
7
7
  module Native
8
8
  extend FFI::Library
9
9
 
10
- ffi_lib [crt_bin_path(local_platform), 'libaws-crt']
10
+ ffi_lib [crt_bin_path(local_platform), 'libaws-crt-ffi']
11
11
 
12
- # aws_byte_cursor binding
13
- class ByteCursor < FFI::Struct
14
- layout :len, :size_t,
15
- :ptr, :pointer
12
+ # Warning, when used as an output structure
13
+ # the memory in ptr needs to be manually destructed!
14
+ class CrtBuf < FFI::Struct
15
+ layout :ptr, :pointer,
16
+ :len, :size_t
16
17
 
17
- def to_s
18
+ def to_blob
18
19
  return unless (self[:len]).positive? && !(self[:ptr]).null?
19
20
 
20
- self[:ptr].read_string(self[:len])
21
+ self[:ptr].read_array_of_char(self[:len])
21
22
  end
22
23
  end
23
24
 
@@ -107,53 +108,115 @@ module Aws
107
108
 
108
109
  # Core API
109
110
  attach_function :aws_crt_init, [], :void, raise: false
111
+ attach_function :aws_crt_clean_up, [], :void
110
112
  attach_function :aws_crt_last_error, [], :int, raise: false
111
113
  attach_function :aws_crt_error_str, [:int], :string, raise: false
112
114
  attach_function :aws_crt_error_name, [:int], :string, raise: false
113
115
  attach_function :aws_crt_error_debug_str, [:int], :string, raise: false
114
116
  attach_function :aws_crt_reset_error, [], :void, raise: false
117
+ attach_function :aws_crt_thread_join_all, [:uint64], :int
118
+
119
+ # Core Memory Management
120
+ attach_function :aws_crt_mem_release, [:pointer], :void, raise: false
121
+ attach_function :aws_crt_mem_bytes, [], :uint64, raise: false
122
+ attach_function :aws_crt_mem_count, [], :uint64, raise: false
123
+ attach_function :aws_crt_mem_dump, [], :void, raise: false
115
124
 
116
- attach_function :aws_crt_thread_join_all_managed, [], :int
125
+ typedef :pointer, :blob
117
126
 
118
127
  # IO API
119
- attach_function :aws_crt_event_loop_group_new, [:uint16], :pointer
120
- attach_function :aws_crt_event_loop_group_release, [:pointer], :void
128
+ typedef :pointer, :event_loop_group_options_ptr
129
+ attach_function :aws_crt_event_loop_group_options_new, [], :event_loop_group_options_ptr
130
+ attach_function :aws_crt_event_loop_group_options_release, [:event_loop_group_options_ptr], :void
131
+ attach_function :aws_crt_event_loop_group_options_set_max_threads, %i[event_loop_group_options_ptr uint16], :void
132
+
133
+ typedef :pointer, :event_loop_group_ptr
134
+ attach_function :aws_crt_event_loop_group_new, [:event_loop_group_options_ptr], :pointer
135
+ attach_function :aws_crt_event_loop_group_acquire, [:event_loop_group_ptr], :event_loop_group_ptr
136
+ attach_function :aws_crt_event_loop_group_release, [:event_loop_group_ptr], :void
137
+
138
+ # HTTP API
139
+ typedef :pointer, :headers_ptr
140
+ attach_function :aws_crt_http_headers_new_from_blob, %i[blob size_t], :headers_ptr
141
+ attach_function :aws_crt_http_headers_to_blob, [:headers_ptr, CrtBuf], :void
142
+ attach_function :aws_crt_http_headers_release, [:headers_ptr], :void
143
+
144
+ typedef :pointer, :http_message_ptr
145
+ attach_function :aws_crt_http_message_new_from_blob, %i[blob size_t], :http_message_ptr
146
+ attach_function :aws_crt_http_message_to_blob, [:http_message_ptr, CrtBuf], :void
147
+ attach_function :aws_crt_http_message_release, [:http_message_ptr], :void
121
148
 
122
149
  # Auth API
123
- attach_function :aws_crt_credentials_new, %i[string string string uint64], :pointer
124
- attach_function :aws_crt_credentials_release, [:pointer], :void
125
- attach_function :aws_crt_credentials_get_access_key_id, [:pointer], ByteCursor.by_value
126
- attach_function :aws_crt_credentials_get_secret_access_key, [:pointer], ByteCursor.by_value
127
- attach_function :aws_crt_credentials_get_session_token, [:pointer], ByteCursor.by_value
128
- attach_function :aws_crt_credentials_get_expiration_timepoint_seconds, [:pointer], :uint64
150
+ typedef :pointer, :credentials_options_ptr
151
+ attach_function :aws_crt_credentials_options_new, [], :credentials_options_ptr
152
+ attach_function :aws_crt_credentials_options_release, [:credentials_options_ptr], :void
153
+ attach_function :aws_crt_credentials_options_set_access_key_id, %i[credentials_options_ptr string size_t], :void
154
+ attach_function :aws_crt_credentials_options_set_secret_access_key, %i[credentials_options_ptr string size_t], :void
155
+ attach_function :aws_crt_credentials_options_set_session_token, %i[credentials_options_ptr string size_t], :void
156
+ attach_function :aws_crt_credentials_options_set_expiration_timepoint_seconds, %i[credentials_options_ptr uint64], :void
157
+
158
+ typedef :pointer, :credentials_ptr
159
+ attach_function :aws_crt_credentials_new, [:credentials_options_ptr], :credentials_ptr
160
+ attach_function :aws_crt_credentials_acquire, [:credentials_ptr], :credentials_ptr
161
+ attach_function :aws_crt_credentials_release, [:credentials_ptr], :void
162
+
163
+ typedef :pointer, :credentials_provider_ptr
164
+ attach_function :aws_crt_credentials_provider_acquire, [:credentials_provider_ptr], :credentials_provider_ptr
165
+ attach_function :aws_crt_credentials_provider_release, [:credentials_provider_ptr], :void
166
+
167
+ typedef :pointer, :static_cred_provider_options_ptr
168
+ attach_function :aws_crt_credentials_provider_static_options_new, [], :static_cred_provider_options_ptr
169
+ attach_function :aws_crt_credentials_provider_static_options_release, [:static_cred_provider_options_ptr], :void
170
+ attach_function :aws_crt_credentials_provider_static_options_set_access_key_id, %i[static_cred_provider_options_ptr string size_t], :void
171
+ attach_function :aws_crt_credentials_provider_static_options_set_secret_access_key, %i[static_cred_provider_options_ptr string size_t], :void
172
+ attach_function :aws_crt_credentials_provider_static_options_set_session_token, %i[static_cred_provider_options_ptr string size_t], :void
173
+
174
+ attach_function :aws_crt_credentials_provider_static_new, [:static_cred_provider_options_ptr], :credentials_provider_ptr
129
175
 
130
176
  enum :signing_algorithm, %i[sigv4 sigv4a]
131
- enum :signature_type, %i[http_request_headers http_request_query_params
132
- http_request_chunk http_request_event]
177
+ enum :signature_type, %i[
178
+ http_request_headers http_request_query_params
179
+ http_request_chunk http_request_event
180
+ canonical_request_headers canonical_request_query_params
181
+ ]
133
182
  enum :signed_body_header_type, %i[sbht_none sbht_content_sha256]
134
- callback :should_sign_header_fn, [ByteCursor.by_ref, :pointer], :bool
135
- attach_function :aws_crt_signing_config_new, %i[signing_algorithm signature_type string string string uint64 pointer signed_body_header_type should_sign_header_fn bool bool bool uint64], :pointer
136
- attach_function :aws_crt_signing_config_release, [:pointer], :void
137
- attach_function :aws_crt_signing_config_is_signing_synchronous, [:pointer], :bool, raise: false
138
-
139
- attach_function :aws_crt_signable_new, [], :pointer
140
- attach_function :aws_crt_signable_release, [:pointer], :void
141
- attach_function :aws_crt_signable_set_property, %i[pointer string string], :int
142
- attach_function :aws_crt_signable_get_property, %i[pointer string], :string, raise: false
143
- attach_function :aws_crt_signable_append_property_list, %i[pointer string string string], :int
144
- attach_function :aws_crt_signable_set_property_list, %i[pointer string size_t pointer pointer], :int
145
-
146
- callback :signing_complete_fn, %i[pointer int pointer], :void
147
- attach_function :aws_crt_sign_request_synchronous, %i[pointer pointer signing_complete_fn], :int
148
- attach_function :aws_crt_verify_sigv4a_signing, %i[pointer pointer string string string string], :int
149
-
150
- attach_function :aws_crt_signing_result_get_property, %i[pointer string], :string, raise: false
151
- attach_function :aws_crt_signing_result_get_property_list, %i[pointer string], PropertyList.by_ref, raise: false
152
- attach_function :aws_crt_property_list_release, %i[pointer], :void
183
+
184
+ typedef :pointer, :signing_config_ptr
185
+ callback :should_sign_header_fn, %i[pointer size_t pointer], :bool
186
+ attach_function :aws_crt_signing_config_aws_new, [], :signing_config_ptr
187
+ attach_function :aws_crt_signing_config_aws_release, [:signing_config_ptr], :void
188
+ attach_function :aws_crt_signing_config_aws_validate, [:signing_config_ptr], :bool
189
+ attach_function :aws_crt_signing_config_aws_set_algorithm, %i[signing_config_ptr signing_algorithm], :void
190
+ attach_function :aws_crt_signing_config_aws_set_signature_type, %i[signing_config_ptr signature_type], :void
191
+ attach_function :aws_crt_signing_config_aws_set_credentials_provider, %i[signing_config_ptr credentials_provider_ptr], :void
192
+ attach_function :aws_crt_signing_config_aws_set_region, %i[signing_config_ptr string size_t], :void
193
+ attach_function :aws_crt_signing_config_aws_set_service, %i[signing_config_ptr string size_t], :void
194
+ attach_function :aws_crt_signing_config_aws_set_use_double_uri_encode, %i[signing_config_ptr bool], :void
195
+ attach_function :aws_crt_signing_config_aws_set_should_normalize_uri_path, %i[signing_config_ptr bool], :void
196
+ attach_function :aws_crt_signing_config_aws_set_omit_session_token, %i[signing_config_ptr bool], :void
197
+ attach_function :aws_crt_signing_config_aws_set_signed_body_value, %i[signing_config_ptr string size_t], :void
198
+ attach_function :aws_crt_signing_config_aws_set_signed_body_header_type, %i[signing_config_ptr signed_body_header_type], :void
199
+ attach_function :aws_crt_signing_config_aws_set_expiration_in_seconds, %i[signing_config_ptr uint64], :void
200
+ attach_function :aws_crt_signing_config_aws_set_date, %i[signing_config_ptr uint64], :void
201
+ attach_function :aws_crt_signing_config_aws_set_should_sign_header_fn, %i[signing_config_ptr should_sign_header_fn], :void
202
+
203
+ typedef :pointer, :signable_ptr
204
+ attach_function :aws_crt_signable_new_from_http_request, [:http_message_ptr], :signable_ptr
205
+ attach_function :aws_crt_signable_release, [:signable_ptr], :void
206
+
207
+ typedef :pointer, :user_data_ptr
208
+ typedef :pointer, :signing_result_ptr
209
+
210
+ callback :signing_complete_fn, %i[signing_result_ptr int user_data_ptr], :void
211
+ attach_function :aws_crt_sign_request_aws, %i[signable_ptr signing_config_ptr signing_complete_fn user_data_ptr], :int
212
+ attach_function :aws_crt_signing_result_apply_to_http_request, %i[signing_result_ptr http_message_ptr], :int
213
+
214
+ # Checksums
215
+ attach_function :aws_crt_crc32, %i[pointer size_t uint32], :uint32, raise: false
216
+ attach_function :aws_crt_crc32c, %i[pointer size_t uint32], :uint32, raise: false
153
217
 
154
218
  # Internal testing API
155
219
  attach_function :aws_crt_test_error, [:int], :int
156
- attach_function :aws_crt_test_pointer_error, [], :pointer
157
220
  end
158
221
  end
159
222
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  # Maps OS name to crt binary name.
4
4
  OS_BINARIES = {
5
- 'darwin' => 'libaws-crt.dylib',
6
- 'linux' => 'libaws-crt.so',
7
- 'mingw32' => 'aws-crt.dll'
5
+ 'darwin' => 'libaws-crt-ffi.dylib',
6
+ 'linux' => 'libaws-crt-ffi.so',
7
+ 'mingw32' => 'aws-crt-ffi.dll'
8
8
  }.freeze
9
9
 
10
- DEFAULT_BINARY = 'libaws-crt.so'
10
+ DEFAULT_BINARY = 'libaws-crt-ffi.so'
11
11
 
12
12
  # @return [String] returns Gem::Platform style name for the current system
13
13
  # similar to Gem::Platform.local but will return systems host os/cpu
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
5
+ module Aws
6
+ module Crt
7
+ # module for CRT Blob utility methods
8
+ # CRT encodes lists of strings as [length, str*]
9
+ # using null padded, unsigned long
10
+ module StringBlob
11
+ # Encode an array of strings into
12
+ # a buffer (blob)
13
+ # @param strings [Array<String>]
14
+ # @return buffer (Array<char>)
15
+ def self.encode(strings)
16
+ buffer = StringIO.new
17
+ strings.each do |s|
18
+ e = s.to_s.unpack('c*')
19
+ buffer << [e.length].pack('N')
20
+ buffer << (e).pack('c*')
21
+ end
22
+ buffer.string.unpack('c*')
23
+ end
24
+
25
+ # Decode a blob (StringBlob)/Buffer into
26
+ # an array of strings
27
+ # @param buffer - array of chars (buffer)
28
+ # @return strings
29
+ def self.decode(buffer)
30
+ strings = []
31
+ i = 0
32
+ while i < buffer.size
33
+ len = buffer[i, 4].pack('c*').unpack1('N')
34
+ strings << (buffer[i + 4, len].pack('c*'))
35
+ .force_encoding(Encoding::UTF_8)
36
+ i += len + 4
37
+ end
38
+ strings
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/aws-crt.rb CHANGED
@@ -4,12 +4,25 @@ require_relative 'aws-crt/platforms'
4
4
  require_relative 'aws-crt/native'
5
5
  require_relative 'aws-crt/errors'
6
6
  require_relative 'aws-crt/managed_native'
7
- require_relative 'aws-crt/io'
7
+ require_relative 'aws-crt/string_blob'
8
+
9
+ require_relative 'aws-crt/io/event_loop_group'
10
+ require_relative 'aws-crt/http/headers'
11
+ require_relative 'aws-crt/http/message'
12
+
13
+ require_relative 'aws-crt/auth/credentials'
14
+ require_relative 'aws-crt/auth/static_credentials_provider'
15
+ require_relative 'aws-crt/auth/signing_config'
16
+ require_relative 'aws-crt/auth/signable'
17
+ require_relative 'aws-crt/auth/signer'
18
+ require_relative 'aws-crt/checksums/crc'
8
19
 
9
20
  # Top level Amazon Web Services (AWS) namespace
10
21
  module Aws
11
- # Top level namespace for all common runtime (CRT) functionality
22
+ # Common runtime bindings
12
23
  module Crt
24
+ GEM_VERSION = File.read(File.expand_path('../VERSION', __dir__)).strip
25
+
13
26
  # Ensure native init() is called when gem loads
14
27
  Aws::Crt::Native.init
15
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-crt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.pre
4
+ version: 0.1.2
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-08 00:00:00.000000000 Z
11
+ date: 2021-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -44,14 +44,25 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - CHANGELOG.md
48
+ - LICENSE.txt
47
49
  - VERSION
48
- - bin/x86_64/libaws-crt.so
50
+ - bin/x86_64/libaws-crt-ffi.so
49
51
  - lib/aws-crt.rb
52
+ - lib/aws-crt/auth/credentials.rb
53
+ - lib/aws-crt/auth/signable.rb
54
+ - lib/aws-crt/auth/signer.rb
55
+ - lib/aws-crt/auth/signing_config.rb
56
+ - lib/aws-crt/auth/static_credentials_provider.rb
57
+ - lib/aws-crt/checksums/crc.rb
50
58
  - lib/aws-crt/errors.rb
51
- - lib/aws-crt/io.rb
59
+ - lib/aws-crt/http/headers.rb
60
+ - lib/aws-crt/http/message.rb
61
+ - lib/aws-crt/io/event_loop_group.rb
52
62
  - lib/aws-crt/managed_native.rb
53
63
  - lib/aws-crt/native.rb
54
64
  - lib/aws-crt/platforms.rb
65
+ - lib/aws-crt/string_blob.rb
55
66
  homepage: https://github.com/awslabs/aws-crt-ruby
56
67
  licenses:
57
68
  - Apache-2.0
@@ -67,9 +78,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
78
  version: '2.5'
68
79
  required_rubygems_version: !ruby/object:Gem::Requirement
69
80
  requirements:
70
- - - ">"
81
+ - - ">="
71
82
  - !ruby/object:Gem::Version
72
- version: 1.3.1
83
+ version: '0'
73
84
  requirements: []
74
85
  rubygems_version: 3.2.3
75
86
  signing_key:
Binary file