aws-signature-v4 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -3
- data/aws-signature-v4-0.1.0.gem +0 -0
- data/aws-signature-v4.gemspec +8 -8
- data/lib/aws/signature/v4.rb +4 -2
- data/lib/aws/signature/v4/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae3c1b489700dd2933f7f16c5a318dd9f98bd150
|
4
|
+
data.tar.gz: 41b9997c128e0ad30b69faef4b993cae5e9c5f3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 209e05eba460940b734f3261fa7f03f34257149a3d8910f7c4e6cfa5ca5515eb3521ce77614aaade3a411a3579d59a801d1abf2820896cbf450f033a398b7f83
|
7
|
+
data.tar.gz: adacbb3ebdb9ac25d6c1da132239f891744d800480d0f6f9ddb29d442e71a510fa555c56879046ec85dc30a4f55c4d3576f457151230ab3c714d9a5b53e351ea
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Aws::Signature::V4
|
2
2
|
|
3
|
-
|
3
|
+
Executes AWS Signature Version 4 Signing Process as explained at http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html.
|
4
4
|
|
5
|
-
|
5
|
+
The gem calculates AWS signature token and provides HTTP headers ready with authentication data.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,41 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
This example shows how to generate signature for DynamoDB Query API call:
|
26
|
+
|
27
|
+
```
|
28
|
+
payload = {
|
29
|
+
:TableName => 'my_table',
|
30
|
+
:IndexName => 'role-created_at-index',
|
31
|
+
:select => 'ALL_ATTRIBUTES',
|
32
|
+
'KeyConditionExpression': '#user_role = :user_role',
|
33
|
+
'ExpressionAttributeValues': {
|
34
|
+
':user_role': {'S': 'ADMIN'}
|
35
|
+
},
|
36
|
+
:ExpressionAttributeNames => { '#user_role' => 'role'},
|
37
|
+
:scan_index_forward => true,
|
38
|
+
:ReturnConsumedCapacity => 'TOTAL'
|
39
|
+
}
|
40
|
+
|
41
|
+
aws_region = 'ap-southeast-1'
|
42
|
+
aws_access_key_id = 'AKIAJVB3LAMUASP5JTUQ'
|
43
|
+
aws_secret_access_key = 'cD4kSv9XDZgFhb2Bps/63h4+oMPudnpRt4GDS9Rr'
|
44
|
+
aws_dynamodb_endpoint = 'https://dynamodb.ap-southeast-1.amazonaws.com'
|
45
|
+
|
46
|
+
# generate AWS Authorization header values
|
47
|
+
aws_signature = Aws::Signature::V4::Signature.new(aws_region, aws_access_key_id, aws_secret_access_key)
|
48
|
+
# parameters: service_name, amz_target, http_method, payload, host, uri
|
49
|
+
aws_signature.generate_signature('dynamodb', 'DynamoDB_20120810.Query', 'POST', payload, aws_dynamodb_endpoint, '/')
|
50
|
+
# Create HTTP object
|
51
|
+
uri = URI.parse(aws_dynamodb_endpoint)
|
52
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
53
|
+
http.use_ssl = true
|
54
|
+
# Alternatively use aws_signature.signature to get signature token value and construct headers yourself
|
55
|
+
request = Net::HTTP::Post.new(uri.request_uri, aws_signature.headers)
|
56
|
+
request.body = payload.to_json
|
57
|
+
# Send the request
|
58
|
+
res = http.request(request)
|
59
|
+
```
|
26
60
|
|
27
61
|
## Development
|
28
62
|
|
Binary file
|
data/aws-signature-v4.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['khaled@supahands.com']
|
11
11
|
|
12
12
|
spec.summary = 'Executes AWS Signature Version 4 Signing Process to add authentication information to AWS requests.'
|
13
|
-
spec.description = 'Executes AWS Signature Version 4 Signing Process as explained at http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
|
13
|
+
spec.description = 'Executes AWS Signature Version 4 Signing Process as explained at http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html. It calculates the signature token and provides HTTP headers with authentication data.'
|
14
14
|
spec.homepage = 'https://github.com/Supahands/aws-signature-v4.git'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
@@ -19,18 +19,18 @@ Gem::Specification.new do |spec|
|
|
19
19
|
if spec.respond_to?(:metadata)
|
20
20
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
21
|
else
|
22
|
-
raise
|
23
|
-
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
24
|
end
|
25
25
|
|
26
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
27
|
f.match(%r{^(test|spec|features)/})
|
28
28
|
end
|
29
|
-
spec.bindir =
|
29
|
+
spec.bindir = 'exe'
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = [
|
31
|
+
spec.require_paths = ['lib']
|
32
32
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
36
|
end
|
data/lib/aws/signature/v4.rb
CHANGED
@@ -7,6 +7,8 @@ module Aws
|
|
7
7
|
class Signature
|
8
8
|
|
9
9
|
require 'json'
|
10
|
+
require 'digest/md5'
|
11
|
+
require 'openssl'
|
10
12
|
|
11
13
|
# Your code goes here...
|
12
14
|
|
@@ -15,9 +17,9 @@ module Aws
|
|
15
17
|
# @param [String] region AWS region
|
16
18
|
# @param [String] key_id AWS user key id
|
17
19
|
# @param [String] secret_key AWS user secret key
|
18
|
-
def initialize (region, key_id, secret_key, algorithm
|
20
|
+
def initialize (region, key_id, secret_key, algorithm: 'AWS4-HMAC-SHA256', content_type: 'application/x-amz-json-1.0', content_type_sign_header: 'application/x-amz-json-1.0,application/x-www-form-urlencoded', t: nil)
|
19
21
|
# calculate date and time
|
20
|
-
@t = Time.now.utc
|
22
|
+
@t = t || Time.now.utc
|
21
23
|
@date = @t.strftime('%Y%m%d')
|
22
24
|
@time = @t.strftime('%Y%m%dT%H%M%SZ')
|
23
25
|
# mandatory fields
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-signature-v4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khaled83
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,8 +52,9 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description: Executes AWS Signature Version 4 Signing Process as explained at http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
|
56
|
-
calculates the signature token and provides HTTP headers with authentication
|
55
|
+
description: Executes AWS Signature Version 4 Signing Process as explained at http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html.
|
56
|
+
It calculates the signature token and provides HTTP headers with authentication
|
57
|
+
data.
|
57
58
|
email:
|
58
59
|
- khaled@supahands.com
|
59
60
|
executables: []
|
@@ -72,6 +73,7 @@ files:
|
|
72
73
|
- LICENSE.txt
|
73
74
|
- README.md
|
74
75
|
- Rakefile
|
76
|
+
- aws-signature-v4-0.1.0.gem
|
75
77
|
- aws-signature-v4.gemspec
|
76
78
|
- bin/console
|
77
79
|
- bin/setup
|