faraday_middleware-aws-sigv4 0.1.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77be7c8437a5ef3812aa134a7d8b6c988e011433
4
+ data.tar.gz: 912adfff8065f6f70a13d9e6939ee6509d7e79a8
5
+ SHA512:
6
+ metadata.gz: eef82188270d7967f5312b184c2e27e6e0e878ce472c3404a2442443eacdc12e0e617c94d03ee38e761bc81c1dec74a3ea1e48cee015b5ae336785090f9087e7
7
+ data.tar.gz: 1324e024f858869ef0a1d6c083bf2620dd5900d5fb09027fe64c818952befabbdf6948eaa0893682d379261ed055ded508258a9a6cd97521a941c361d505649d
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test.rb
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faraday_middleware-aws-sigv4.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Genki Sugawara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # FaradayMiddleware::AwsSigV4
2
+
3
+ [Faraday](https://github.com/lostisland/faraday) middleware for AWS Signature Version 4 using [aws-sigv4](https://rubygems.org/gems/aws-sigv4).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'faraday_middleware-aws-sigv4'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install faraday_middleware-aws-sigv4
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'faraday_middleware'
25
+ require 'faraday_middleware/aws_sigv4'
26
+ require 'pp'
27
+
28
+ conn = Faraday.new(url: 'https://apigateway.us-east-1.amazonaws.com') do |faraday|
29
+ faraday.request :aws_sigv4,
30
+ service: 'apigateway',
31
+ region: 'us-east-1',
32
+ access_key_id: ENV['AWS_ACCESS_KEY_ID'],
33
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
34
+ # see http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Sigv4/Signer.html
35
+
36
+ faraday.response :json, :content_type => /\bjson\b/
37
+ faraday.response :raise_error
38
+
39
+ faraday.adapter Faraday.default_adapter
40
+ end
41
+
42
+ res = conn.get '/account'
43
+
44
+ pp res.body
45
+ #=>{"_links"=>
46
+ # {"curies"=>
47
+ # {"href"=>
48
+ # "http://docs.aws.amazon.com/apigateway/latest/developerguide/account-apigateway-{rel}.html",
49
+ # "name"=>"account",
50
+ # "templated"=>true},
51
+ # "self"=>{"href"=>"/account"},
52
+ # "account:update"=>{"href"=>"/account"}},
53
+ # "throttleSettings"=>{"rateLimit"=>10000.0, "burstLimit"=>5000}}
54
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "faraday_middleware/aws/sigv4"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'faraday_middleware-aws-sigv4'
7
+ spec.version = '0.1.0.beta'
8
+ spec.authors = ['Genki Sugawara']
9
+ spec.email = ['sugawara@cookpad.com']
10
+
11
+ spec.summary = %q{Faraday middleware for AWS Signature Version 4 using aws-sigv4.}
12
+ spec.description = %q{Faraday middleware for AWS Signature Version 4 using aws-sigv4.}
13
+ spec.homepage = 'https://github.com/winebarrel/faraday_middleware-aws-sigv4'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'faraday', '~> 0.13'
24
+ spec.add_dependency 'aws-sigv4', '~> 1.0'
25
+
26
+ spec.add_development_dependency 'faraday_middleware'
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ end
@@ -0,0 +1,6 @@
1
+ require 'faraday'
2
+
3
+ module FaradayMiddleware
4
+ autoload :AwsSigV4, 'faraday_middleware/request/aws_sigv4'
5
+ Faraday::Request.register_middleware aws_sigv4: lambda { AwsSigV4 }
6
+ end
@@ -0,0 +1,53 @@
1
+ require 'aws-sigv4'
2
+ require 'faraday_middleware/request/aws_sigv4_util'
3
+
4
+ class FaradayMiddleware::AwsSigV4 < Faraday::Middleware
5
+ include FaradayMiddleware::AwsSigV4Util
6
+
7
+ def initialize(app, options = nil)
8
+ super(app)
9
+
10
+ # check options
11
+ build_signer(options)
12
+
13
+ @options = options
14
+ @is_net_http_adapter = app.is_a?(Faraday::Adapter::NetHttp)
15
+ end
16
+
17
+ def call(env)
18
+ sign!(env)
19
+ @app.call(env)
20
+ end
21
+
22
+ private
23
+
24
+ def sign!(env)
25
+ signer = build_signer(@options)
26
+
27
+ if net_http_adapter?
28
+ normalize_for_net_http!(env)
29
+ end
30
+
31
+ request = build_aws_sigv4_request(env)
32
+ signature = signer.sign_request(request)
33
+
34
+ env.request_headers.update(signature.headers)
35
+ end
36
+
37
+ def build_signer(options)
38
+ Aws::Sigv4::Signer.new(options)
39
+ end
40
+
41
+ def build_aws_sigv4_request(env)
42
+ {
43
+ http_method: env.method.to_s,
44
+ url: seahorse_encode_query(env.url),
45
+ headers: env.request_headers,
46
+ body: env.body,
47
+ }
48
+ end
49
+
50
+ def net_http_adapter?
51
+ @is_net_http_adapter
52
+ end
53
+ end
@@ -0,0 +1,43 @@
1
+ module FaradayMiddleware::AwsSigV4Util
2
+ def normalize_for_net_http!(env)
3
+ if Net::HTTP::HAVE_ZLIB
4
+ env.request_headers['Accept-Encoding'] ||= 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
5
+ end
6
+
7
+ env.request_headers['Accept'] ||= '*/*'
8
+ env
9
+ end
10
+
11
+ def seahorse_encode_query(url)
12
+ return url unless url.query
13
+
14
+ params = URI.decode_www_form(url.query)
15
+
16
+ if params.any? {|_, v| v[?\s] }
17
+ url = url.dup
18
+ url.query = URI.seahorse_encode_www_form(params)
19
+ end
20
+
21
+ url
22
+ end
23
+
24
+ def seahorse_encode_www_form(params)
25
+ params.map {|key, value|
26
+ encoded_key = URI.encode_www_form_component(key)
27
+
28
+ if value.nil?
29
+ encoded_key
30
+ elsif value.respond_to?(:to_ary)
31
+ value.to_ary.map {|v|
32
+ if v.nil?
33
+ encoded_key
34
+ else
35
+ encoded_key + '=' + Aws::Sigv::Signer.uri_escape(v)
36
+ end
37
+ }.join('&')
38
+ else
39
+ encoded_key + '=' + Aws::Sigv::Signer.uri_escape(value)
40
+ end
41
+ }.join('&')
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday_middleware-aws-sigv4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sigv4
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Faraday middleware for AWS Signature Version 4 using aws-sigv4.
98
+ email:
99
+ - sugawara@cookpad.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - faraday_middleware-aws-sigv4.gemspec
114
+ - lib/faraday_middleware/aws_sigv4.rb
115
+ - lib/faraday_middleware/request/aws_sigv4.rb
116
+ - lib/faraday_middleware/request/aws_sigv4_util.rb
117
+ homepage: https://github.com/winebarrel/faraday_middleware-aws-sigv4
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">"
133
+ - !ruby/object:Gem::Version
134
+ version: 1.3.1
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.6.13
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Faraday middleware for AWS Signature Version 4 using aws-sigv4.
141
+ test_files: []