Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
229 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
AllCops: | ||
Exclude: | ||
- 'gemfiles/**/*' | ||
TargetRubyVersion: 2.4 | ||
NewCops: enable | ||
Bundler/OrderedGems: | ||
Include: | ||
- 'Appraisals' | ||
Metrics/BlockLength: | ||
Enabled: false | ||
Layout/LineLength: | ||
Enabled: false | ||
Metrics/MethodLength: | ||
Enabled: false | ||
Style/Documentation: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
SimpleCov.start do | ||
# exclude directories and files | ||
add_filter "/spec/" | ||
add_filter '/spec/' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
appraise 'faraday-0.15' do | ||
gem 'faraday', '~> 0.15.0' | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
require 'rubocop/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec | ||
RuboCop::RakeTask.new do |task| | ||
task.options = %w[-c .rubocop.yml] | ||
end | ||
|
||
task default: %i[rubocop spec] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'faraday' | ||
|
||
module FaradayMiddleware | ||
autoload :AwsSigV4, 'faraday_middleware/request/aws_sigv4' | ||
Faraday::Request.register_middleware aws_sigv4: lambda { AwsSigV4 } | ||
Faraday::Request.register_middleware aws_sigv4: -> { AwsSigV4 } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'aws-sigv4' | ||
require 'faraday_middleware/request/aws_sigv4_util' | ||
|
||
class FaradayMiddleware::AwsSigV4 < Faraday::Middleware | ||
include FaradayMiddleware::AwsSigV4Util | ||
module FaradayMiddleware | ||
class AwsSigV4 < Faraday::Middleware | ||
include FaradayMiddleware::AwsSigV4Util | ||
|
||
def initialize(app, options = nil) | ||
super(app) | ||
@signer = Aws::Sigv4::Signer.new(options) | ||
@options = options | ||
end | ||
def initialize(app, options = nil) | ||
super(app) | ||
@signer = Aws::Sigv4::Signer.new(options) | ||
@options = options | ||
end | ||
|
||
def call(env) | ||
sign!(env) | ||
@app.call(env) | ||
end | ||
def call(env) | ||
sign!(env) | ||
@app.call(env) | ||
end | ||
|
||
private | ||
private | ||
|
||
def sign!(env) | ||
request = build_aws_sigv4_request(env) | ||
signature = @signer.sign_request(request) | ||
def sign!(env) | ||
request = build_aws_sigv4_request(env) | ||
signature = @signer.sign_request(request) | ||
|
||
signature.headers.each do |name, value| | ||
env.request_headers[name] = value | ||
signature.headers.each do |name, value| | ||
env.request_headers[name] = value | ||
end | ||
end | ||
end | ||
|
||
def build_aws_sigv4_request(env) | ||
{ | ||
http_method: env.method.to_s, | ||
url: seahorse_encode_query(env.url), | ||
headers: env.request_headers, | ||
body: env.body, | ||
} | ||
def build_aws_sigv4_request(env) | ||
{ | ||
http_method: env.method.to_s, | ||
url: seahorse_encode_query(env.url), | ||
headers: env.request_headers, | ||
body: env.body | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
module FaradayMiddleware::AwsSigV4Util | ||
def seahorse_encode_query(url) | ||
return url unless url.query | ||
# frozen_string_literal: true | ||
|
||
params = URI.decode_www_form(url.query) | ||
module FaradayMiddleware | ||
module AwsSigV4Util | ||
def seahorse_encode_query(url) | ||
return url unless url.query | ||
|
||
if params.any? {|_, v| v[?\s] } | ||
url = url.dup | ||
url.query = seahorse_encode_www_form(params) | ||
end | ||
params = URI.decode_www_form(url.query) | ||
|
||
url | ||
end | ||
if params.any? { |_, v| v["\s"] } | ||
url = url.dup | ||
url.query = seahorse_encode_www_form(params) | ||
end | ||
|
||
def seahorse_encode_www_form(params) | ||
params.flat_map {|key, value| | ||
encoded_key = URI.encode_www_form_component(key) | ||
url | ||
end | ||
|
||
if value.nil? | ||
encoded_key | ||
else | ||
Array(value).map do |v| | ||
if v.nil? | ||
# nothing to do | ||
else | ||
encoded_key + '=' + Aws::Sigv4::Signer.uri_escape(v) | ||
def seahorse_encode_www_form(params) | ||
params.flat_map do |key, value| | ||
encoded_key = URI.encode_www_form_component(key) | ||
|
||
if value.nil? | ||
encoded_key | ||
else | ||
Array(value).map do |v| | ||
if v.nil? | ||
# nothing to do | ||
else | ||
"#{encoded_key}=#{Aws::Sigv4::Signer.uri_escape(v)}" | ||
end | ||
end | ||
end | ||
end | ||
}.join(?&) | ||
end.join('&') | ||
end | ||
end | ||
end |
Oops, something went wrong.