aws-crt 0.1.2-x86_64-mingw32
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 +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -0
- data/bin/x86_64/aws-crt-ffi.dll +0 -0
- data/lib/aws-crt/auth/credentials.rb +78 -0
- data/lib/aws-crt/auth/signable.rb +20 -0
- data/lib/aws-crt/auth/signer.rb +50 -0
- data/lib/aws-crt/auth/signing_config.rb +122 -0
- data/lib/aws-crt/auth/static_credentials_provider.rb +68 -0
- data/lib/aws-crt/checksums/crc.rb +24 -0
- data/lib/aws-crt/errors.rb +77 -0
- data/lib/aws-crt/http/headers.rb +32 -0
- data/lib/aws-crt/http/message.rb +54 -0
- data/lib/aws-crt/io/event_loop_group.rb +51 -0
- data/lib/aws-crt/managed_native.rb +87 -0
- data/lib/aws-crt/native.rb +222 -0
- data/lib/aws-crt/platforms.rb +63 -0
- data/lib/aws-crt/string_blob.rb +42 -0
- data/lib/aws-crt.rb +29 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f3f818a00bacdc85f827f617818584760d2f42d51b4fe86fecdb3007c5010aef
|
4
|
+
data.tar.gz: fdf8f4cc6a587eb22a87a1fb572466387c253ef3639b1f19064af713f6e6900c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0c0c0c69e8a2ec04b5aa79b15828c729f72070b76c1817322f5b82ac7a0b5e984cf957ec4f0b6ae557908a55e0cfb09663848b5169a5b16f17454c44a7e3df6
|
7
|
+
data.tar.gz: d1b457ca996175da2c333b7b170c039585130a7e3cbbdb24b755759189841645fa3b5ba918b4171bb439a03f7dee4f6c18dd1e7fb530809089008d8440b7653a
|
data/CHANGELOG.md
ADDED
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
ADDED
@@ -0,0 +1 @@
|
|
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,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Crt
|
5
|
+
# Base class for CRT Errors
|
6
|
+
class Error < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
# CRT Errors - includes utilities for mapping errors from CRT to
|
10
|
+
# Ruby Exceptions
|
11
|
+
module Errors
|
12
|
+
@const_set_mutex = Mutex.new
|
13
|
+
|
14
|
+
AWS_TO_RUBY_ERROR_MAP = {
|
15
|
+
'AWS_ERROR_INVALID_INDEX' => IndexError,
|
16
|
+
'AWS_ERROR_OOM' => NoMemoryError,
|
17
|
+
'AWS_ERROR_UNIMPLEMENTED' => NotImplementedError,
|
18
|
+
'AWS_ERROR_INVALID_ARGUMENT' => ArgumentError,
|
19
|
+
'AWS_ERROR_SYS_CALL_FAILURE' => SystemCallError,
|
20
|
+
'AWS_ERROR_DIVIDE_BY_ZERO' => ZeroDivisionError,
|
21
|
+
'AWS_ERROR_HASHTBL_ITEM_NOT_FOUND' => KeyError
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
def self.raise_last_error
|
25
|
+
error_code = Aws::Crt::Native.last_error
|
26
|
+
return if error_code.zero?
|
27
|
+
|
28
|
+
error_name = Aws::Crt::Native.error_name(error_code)
|
29
|
+
msg = Aws::Crt::Native.error_debug_str(error_code)
|
30
|
+
Aws::Crt::Native.reset_error
|
31
|
+
raise error_class(error_name), msg
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get the error class for a given error_name
|
35
|
+
def self.error_class(error_name)
|
36
|
+
if AWS_TO_RUBY_ERROR_MAP.include? error_name
|
37
|
+
return AWS_TO_RUBY_ERROR_MAP[error_name]
|
38
|
+
end
|
39
|
+
|
40
|
+
constant = error_class_constant(error_name)
|
41
|
+
if error_const_set?(constant)
|
42
|
+
# modeled error class exist
|
43
|
+
# set code attribute
|
44
|
+
const_get(constant)
|
45
|
+
|
46
|
+
else
|
47
|
+
add_error_constant(constant)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Convert an error code to an error class name/constant.
|
52
|
+
# This requires filtering non-safe characters from the constant
|
53
|
+
# name and ensuring it begins with an uppercase letter.
|
54
|
+
def self.error_class_constant(error_name)
|
55
|
+
error_name.to_s.gsub(/AWS_ERROR_/, '').split('_').map(&:capitalize).join
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.add_error_constant(constant)
|
59
|
+
@const_set_mutex.synchronize do
|
60
|
+
# Ensure the const was not defined while blocked by the mutex
|
61
|
+
if error_const_set?(constant)
|
62
|
+
const_get(constant)
|
63
|
+
else
|
64
|
+
error_class = Class.new(Aws::Crt::Error)
|
65
|
+
const_set(constant, error_class)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.error_const_set?(constant)
|
71
|
+
# Purposefully not using #const_defined? as that method returns true
|
72
|
+
# for constants not defined directly in the current module.
|
73
|
+
constants.include?(constant.to_sym)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
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
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Crt
|
5
|
+
# High level Ruby abstractions for CRT IO functionality
|
6
|
+
module IO
|
7
|
+
# Options for an EventLoopGroup
|
8
|
+
class EventLoopGroupOptions
|
9
|
+
include Aws::Crt::ManagedNative
|
10
|
+
native_destroy Aws::Crt::Native.method(
|
11
|
+
:event_loop_group_options_release
|
12
|
+
)
|
13
|
+
|
14
|
+
def initialize(max_threads = nil)
|
15
|
+
unless max_threads.nil? ||
|
16
|
+
(max_threads.is_a?(Integer) && max_threads.positive?)
|
17
|
+
raise ArgumentError, 'max_threads must be nil or positive Integer'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Ruby uses nil to request default values, native code uses 0
|
21
|
+
max_threads = 0 if max_threads.nil?
|
22
|
+
|
23
|
+
manage_native do
|
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)
|
45
|
+
end
|
46
|
+
Aws::Crt::Native.event_loop_group_acquire(@native)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Crt
|
5
|
+
# A mixin module for generic managed native functionality
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# class C
|
9
|
+
# include Aws::Crt::ManagedNative
|
10
|
+
# native_destroy Aws::Crt::Native.method(:test_struct_destroy)
|
11
|
+
#
|
12
|
+
# def initialize
|
13
|
+
# manage_native { Aws::Crt::Native::test_struct_new() }
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def use_native
|
17
|
+
# Aws::Crt::Native::test_method(native) #use that getter for native
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
module ManagedNative
|
21
|
+
def self.included(sub_class)
|
22
|
+
sub_class.extend(ClassMethods)
|
23
|
+
end
|
24
|
+
|
25
|
+
# expects a block that returns a :pointer to the native resource
|
26
|
+
# that this class manages
|
27
|
+
def manage_native(&block)
|
28
|
+
# check that a destructor has been registered
|
29
|
+
unless self.class.instance_variable_get('@destructor')
|
30
|
+
raise 'No native destructor registered. use native_destroy to ' \
|
31
|
+
'set the method used to cleanup the native object this ' \
|
32
|
+
'class manages.'
|
33
|
+
end
|
34
|
+
native = block.call
|
35
|
+
@native = FFI::AutoPointer.new(native, self.class.method(:on_release))
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param [Boolean] safe (true) - raise an exception if the native object
|
39
|
+
# is not set (has been freed or never created)
|
40
|
+
# @return [FFI:Pointer]
|
41
|
+
def native(safe: true)
|
42
|
+
raise '@native is unset or has been freed.' if safe && !@native
|
43
|
+
|
44
|
+
@native
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Boolean]
|
48
|
+
def native_set?
|
49
|
+
!!@native
|
50
|
+
end
|
51
|
+
|
52
|
+
# Immediately release this instance's attachment to the underlying
|
53
|
+
# resources, without waiting for the garbage collector.
|
54
|
+
# Note that underlying resources will remain alive until nothing
|
55
|
+
# else is using them.
|
56
|
+
def release
|
57
|
+
return unless @native
|
58
|
+
|
59
|
+
@native.free
|
60
|
+
@native = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# ClassMethods for ManagedNative
|
64
|
+
module ClassMethods
|
65
|
+
# Register the method used to cleanup the native object this class
|
66
|
+
# manages. Must be a method, use object.method(:method_name).
|
67
|
+
#
|
68
|
+
# Example:
|
69
|
+
# native_destroy Aws::Crt::Native.method(:test_release)
|
70
|
+
def native_destroy(destructor)
|
71
|
+
unless destructor.is_a?(Method)
|
72
|
+
raise ArgumentError,
|
73
|
+
'destructor must be a Method. ' \
|
74
|
+
'Use object.method(:method_name)'
|
75
|
+
end
|
76
|
+
@destructor = destructor
|
77
|
+
end
|
78
|
+
|
79
|
+
# Do not call directly
|
80
|
+
# method passed to FFI Autopointer to call the destructor
|
81
|
+
def on_release(native)
|
82
|
+
@destructor.call(native)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
module Aws
|
5
|
+
module Crt
|
6
|
+
# FFI Bindings to native CRT functions
|
7
|
+
module Native
|
8
|
+
extend FFI::Library
|
9
|
+
|
10
|
+
ffi_lib [crt_bin_path(local_platform), 'libaws-crt-ffi']
|
11
|
+
|
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
|
17
|
+
|
18
|
+
def to_blob
|
19
|
+
return unless (self[:len]).positive? && !(self[:ptr]).null?
|
20
|
+
|
21
|
+
self[:ptr].read_array_of_char(self[:len])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Managed PropertyList Struct (for outputs)
|
26
|
+
class PropertyList < FFI::ManagedStruct
|
27
|
+
layout :len, :size_t,
|
28
|
+
:names, :pointer,
|
29
|
+
:values, :pointer
|
30
|
+
|
31
|
+
def props
|
32
|
+
return nil if to_ptr.null?
|
33
|
+
|
34
|
+
return {} unless (self[:len]).positive?
|
35
|
+
|
36
|
+
out = {}
|
37
|
+
names_p = self[:names].get_array_of_pointer(0, self[:len])
|
38
|
+
values_p = self[:values].get_array_of_pointer(0, self[:len])
|
39
|
+
names_p.zip(values_p).each do |name_p, value_p|
|
40
|
+
out[name_p.read_string.dup] = value_p.read_string.dup
|
41
|
+
end
|
42
|
+
out
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.release(ptr)
|
46
|
+
Aws::Crt::Native.aws_crt_property_list_release(ptr)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Given a ruby hash (string -> string), return two native arrays:
|
51
|
+
# char** (:pointer) AND a list of all of the FFI::MemoryPointers
|
52
|
+
# that must be kept around to avoid GC
|
53
|
+
def self.hash_to_native_arrays(hash)
|
54
|
+
key_array, keys_p = array_to_native(hash.keys)
|
55
|
+
value_array, values_p = array_to_native(hash.values)
|
56
|
+
[key_array, value_array, keys_p + values_p]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Given a ruby array of strings, return a native array: char** and
|
60
|
+
# the FFI::MemoryPointers (these need to be pined for the length the
|
61
|
+
# native memory will be used to avoid GC)
|
62
|
+
def self.array_to_native(array)
|
63
|
+
native = FFI::MemoryPointer.new(:pointer, array.size)
|
64
|
+
pointers = array.map do |s|
|
65
|
+
FFI::MemoryPointer.from_string(s.to_s)
|
66
|
+
end
|
67
|
+
native.write_array_of_pointer(pointers)
|
68
|
+
[native, pointers]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Extends FFI::attach_function
|
72
|
+
#
|
73
|
+
# 1. Allows us to only supply the aws_crt C name and removes
|
74
|
+
# the aws_crt.
|
75
|
+
# 2. Wraps the call in an error-raise checker (unless options[:raise]
|
76
|
+
# = false)
|
77
|
+
# 3. Creates a bang method that does not do automatic error checking.
|
78
|
+
def self.attach_function(c_name, params, returns, options = {})
|
79
|
+
ruby_name = c_name.to_s.sub(/aws_crt_/, '').to_sym
|
80
|
+
raise_errors = options.fetch(:raise, true)
|
81
|
+
options.delete(:raise)
|
82
|
+
unless raise_errors
|
83
|
+
return super(ruby_name, c_name, params, returns, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
bang_name = "#{ruby_name}!"
|
87
|
+
|
88
|
+
super(ruby_name, c_name, params, returns, options)
|
89
|
+
alias_method(bang_name, ruby_name)
|
90
|
+
|
91
|
+
define_method(ruby_name) do |*args, &block|
|
92
|
+
res = public_send(bang_name, *args, &block)
|
93
|
+
# functions that return void cannot fail
|
94
|
+
return unless res
|
95
|
+
|
96
|
+
# for functions that return int, non-zero indicates failure
|
97
|
+
Errors.raise_last_error if res.is_a?(Integer) && res != 0
|
98
|
+
|
99
|
+
# for functions that return pointer, NULL indicates failure
|
100
|
+
Errors.raise_last_error if res.is_a?(FFI::Pointer) && res.null?
|
101
|
+
|
102
|
+
res
|
103
|
+
end
|
104
|
+
|
105
|
+
module_function ruby_name
|
106
|
+
module_function bang_name
|
107
|
+
end
|
108
|
+
|
109
|
+
# Core API
|
110
|
+
attach_function :aws_crt_init, [], :void, raise: false
|
111
|
+
attach_function :aws_crt_clean_up, [], :void
|
112
|
+
attach_function :aws_crt_last_error, [], :int, raise: false
|
113
|
+
attach_function :aws_crt_error_str, [:int], :string, raise: false
|
114
|
+
attach_function :aws_crt_error_name, [:int], :string, raise: false
|
115
|
+
attach_function :aws_crt_error_debug_str, [:int], :string, raise: false
|
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
|
124
|
+
|
125
|
+
typedef :pointer, :blob
|
126
|
+
|
127
|
+
# IO API
|
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
|
148
|
+
|
149
|
+
# Auth API
|
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
|
175
|
+
|
176
|
+
enum :signing_algorithm, %i[sigv4 sigv4a]
|
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
|
+
]
|
182
|
+
enum :signed_body_header_type, %i[sbht_none sbht_content_sha256]
|
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
|
217
|
+
|
218
|
+
# Internal testing API
|
219
|
+
attach_function :aws_crt_test_error, [:int], :int
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Maps OS name to crt binary name.
|
4
|
+
OS_BINARIES = {
|
5
|
+
'darwin' => 'libaws-crt-ffi.dylib',
|
6
|
+
'linux' => 'libaws-crt-ffi.so',
|
7
|
+
'mingw32' => 'aws-crt-ffi.dll'
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
DEFAULT_BINARY = 'libaws-crt-ffi.so'
|
11
|
+
|
12
|
+
# @return [String] returns Gem::Platform style name for the current system
|
13
|
+
# similar to Gem::Platform.local but will return systems host os/cpu
|
14
|
+
# for Jruby
|
15
|
+
def local_platform
|
16
|
+
Gem::Platform.new(host_string)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] return the file name for the CRT library for the platform
|
20
|
+
def crt_bin_name(platform)
|
21
|
+
OS_BINARIES[platform.os] || DEFAULT_BINARY
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] return the directory of the CRT library for the platform
|
25
|
+
def crt_bin_dir(platform)
|
26
|
+
File.expand_path("../../bin/#{platform.cpu}", File.dirname(__FILE__))
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String] return the path to the CRT library for the platform
|
30
|
+
def crt_bin_path(platform)
|
31
|
+
File.expand_path(crt_bin_name(platform), crt_bin_dir(platform))
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [String] generate a string that be used with Gem::Platform
|
35
|
+
def host_string
|
36
|
+
"#{host_cpu}-#{host_os}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [String] host cpu, even on jruby
|
40
|
+
def host_cpu
|
41
|
+
case RbConfig::CONFIG['host_cpu']
|
42
|
+
when /86_64/
|
43
|
+
'x86_64'
|
44
|
+
when /86/
|
45
|
+
'x86'
|
46
|
+
else
|
47
|
+
RbConfig::CONFIG['host_cpu']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [String] host os, even on jruby
|
52
|
+
def host_os
|
53
|
+
case RbConfig::CONFIG['host_os']
|
54
|
+
when /darwin/
|
55
|
+
'darwin'
|
56
|
+
when /linux/
|
57
|
+
'linux'
|
58
|
+
when /mingw|mswin/
|
59
|
+
'mingw32'
|
60
|
+
else
|
61
|
+
RbConfig::CONFIG['host_os']
|
62
|
+
end
|
63
|
+
end
|
@@ -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
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'aws-crt/platforms'
|
4
|
+
require_relative 'aws-crt/native'
|
5
|
+
require_relative 'aws-crt/errors'
|
6
|
+
require_relative 'aws-crt/managed_native'
|
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'
|
19
|
+
|
20
|
+
# Top level Amazon Web Services (AWS) namespace
|
21
|
+
module Aws
|
22
|
+
# Common runtime bindings
|
23
|
+
module Crt
|
24
|
+
GEM_VERSION = File.read(File.expand_path('../VERSION', __dir__)).strip
|
25
|
+
|
26
|
+
# Ensure native init() is called when gem loads
|
27
|
+
Aws::Crt::Native.init
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-crt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: x86_64-mingw32
|
6
|
+
authors:
|
7
|
+
- Amazon Web Services
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- CHANGELOG.md
|
48
|
+
- LICENSE.txt
|
49
|
+
- VERSION
|
50
|
+
- bin/x86_64/aws-crt-ffi.dll
|
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
|
58
|
+
- lib/aws-crt/errors.rb
|
59
|
+
- lib/aws-crt/http/headers.rb
|
60
|
+
- lib/aws-crt/http/message.rb
|
61
|
+
- lib/aws-crt/io/event_loop_group.rb
|
62
|
+
- lib/aws-crt/managed_native.rb
|
63
|
+
- lib/aws-crt/native.rb
|
64
|
+
- lib/aws-crt/platforms.rb
|
65
|
+
- lib/aws-crt/string_blob.rb
|
66
|
+
homepage: https://github.com/awslabs/aws-crt-ruby
|
67
|
+
licenses:
|
68
|
+
- Apache-2.0
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.5'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.7.6.3
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: AWS SDK for Ruby - Common Run Time
|
90
|
+
test_files: []
|