Skip to content

Commit

Permalink
Merge pull request #43 from scalefactory/20200304_pin_dry-equalizer
Browse files Browse the repository at this point in the history
Pin dry-equalizer to retain Ruby 2.3 compatbility
  • Loading branch information
mbevc1 committed Mar 4, 2020
2 parents 5f9a046 + 3604bd0 commit 46c7f1e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Expand Up @@ -4,6 +4,7 @@ AllCops:
DisplayCopNames: true
Exclude:
- 'lib/aws_assume_role/vendored/**/*.rb'
- 'vendor/**/*'

Metrics/MethodLength:
Enabled: false
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
@@ -1 +1 @@
2.3.5
2.3.8
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
## 1.2.3
* Pin dry-eualizer to keep support of Ruby 2.3

## 1.2.2
* Pin dry-types to keep support of object type

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -62,7 +62,7 @@ task :build_generic do
end

task :no_pry do
files = Dir.glob("**/**").reject { |x| x.match(/^spec|Gemfile|coverage|\.gemspec$|Rakefile/) || File.directory?(x) }
files = Dir.glob("**/**").reject { |x| x.match(/^spec|Gemfile|coverage|\.gemspec$|Rakefile|vendor/) || File.directory?(x) }
files.each do |file|
raise "Use of pry found in #{file}." if File.read(file) =~ /"pry"/
end
Expand Down
3 changes: 3 additions & 0 deletions aws_assume_role.gemspec
Expand Up @@ -18,13 +18,15 @@ Gem::Specification.new do |spec|
"Tom Haynes",
"Alan Ivey",
"David O'Rourke",
"Marko Bevc",
]
spec.email = [
"jon@scalefactory.com",
"jack@scalefactory.com",
"naadir@scalefactory.com",
"tim@scalefactory.com",
"david@scalefactory.com",
"marko@scalefactory.com",
]

spec.description = "Used to fetch multiple AWS Role Credential "\
Expand All @@ -45,6 +47,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "activesupport", "~> 4.2"
spec.add_runtime_dependency "aws-sdk", "~> 2.7"
spec.add_runtime_dependency "dry-configurable", "~> 0.5"
spec.add_runtime_dependency "dry-equalizer", "~> 0.2.2" # 0.3.0 requires Ruby 2.4
spec.add_runtime_dependency "dry-struct", "~> 0.5"
spec.add_runtime_dependency "dry-types", "~> 0.13", "< 0.15"
spec.add_runtime_dependency "dry-validation", "~> 0.11"
Expand Down
2 changes: 1 addition & 1 deletion lib/aws_assume_role/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module AwsAssumeRole
VERSION = "1.2.2".freeze
VERSION = "1.2.3".freeze
end
Expand Up @@ -77,6 +77,14 @@ module AwsAssumeRole
:get,
"http://169.254.169.254/latest/meta-data/iam/security-credentials/",
).to_return(status: 200, body: "profile-name\n")
stub_request(
:put,
"http://169.254.169.254/latest/api/token",
).with(headers: { 'Accept': "*/*",
'Accept-Encoding': "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'User-Agent': "aws-sdk-ruby2/2.11.458",
'X-Aws-Ec2-Metadata-Token-Ttl-Seconds': "21600" })
.to_return(status: 200, body: "", headers: {})
stub_request(
:get,
"http://169.254.169.254/latest/meta-data/iam/security-credentials/profile-name",
Expand Down Expand Up @@ -137,6 +145,14 @@ module AwsAssumeRole
describe "AWS_SDK_CONFIG_OPT_OUT set" do
before(:each) do
stub_const("ENV", {})
stub_request(
:put,
"http://169.254.169.254/latest/api/token",
).with(headers: { 'Accept': "*/*",
'Accept-Encoding': "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'User-Agent': "aws-sdk-ruby2/2.11.458",
'X-Aws-Ec2-Metadata-Token-Ttl-Seconds': "21600" })
.to_return(status: 200, body: "", headers: {})
Aws.shared_config.fresh(
config_enabled: false,
credentials_path: mock_credential_file,
Expand Down
Expand Up @@ -35,6 +35,14 @@ module AwsAssumeRole::Credentials::Factories
end

it "defaults to nil when credentials not set" do
stub_request(
:put,
"http://169.254.169.254/latest/api/token",
).with(headers: { 'Accept': "*/*",
'Accept-Encoding': "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'User-Agent': "aws-sdk-ruby2/2.11.458",
'X-Aws-Ec2-Metadata-Token-Ttl-Seconds': "21600" })
.to_return(status: 200, body: "", headers: {})
expect(credentials).to be(nil)
end

Expand Down Expand Up @@ -104,6 +112,14 @@ module AwsAssumeRole::Credentials::Factories
end

it "hydrates credentials from the instance profile service" do
stub_request(
:put,
"http://169.254.169.254/latest/api/token",
).with(headers: { 'Accept': "*/*",
'Accept-Encoding': "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'User-Agent': "aws-sdk-ruby2/2.11.458",
'X-Aws-Ec2-Metadata-Token-Ttl-Seconds': "21600" })
.to_return(status: 200, body: "", headers: {})
path = "/latest/meta-data/iam/security-credentials/"
resp = <<-JSON.strip
{
Expand Down Expand Up @@ -131,6 +147,14 @@ module AwsAssumeRole::Credentials::Factories
let(:config) { nil }

it "defaults to nil" do
stub_request(
:put,
"http://169.254.169.254/latest/api/token",
).with(headers: { 'Accept': "*/*",
'Accept-Encoding': "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'User-Agent': "aws-sdk-ruby2/2.11.458",
'X-Aws-Ec2-Metadata-Token-Ttl-Seconds': "21600" })
.to_return(status: 200, body: "", headers: {})
expect(credentials).to be(nil)
end
end
Expand All @@ -144,11 +168,27 @@ module AwsAssumeRole::Credentials::Factories
end

it "returns no credentials when the shared file is empty" do
stub_request(
:put,
"http://169.254.169.254/latest/api/token",
).with(headers: { 'Accept': "*/*",
'Accept-Encoding': "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'User-Agent': "aws-sdk-ruby2/2.11.458",
'X-Aws-Ec2-Metadata-Token-Ttl-Seconds': "21600" })
.to_return(status: 200, body: "", headers: {})
expect(File).to receive(:read).with(path).and_return("")
expect(chain.resolve).to be(nil)
end

it "returns no credentials when the shared file profile is missing" do
stub_request(
:put,
"http://169.254.169.254/latest/api/token",
).with(headers: { 'Accept': "*/*",
'Accept-Encoding': "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'User-Agent': "aws-sdk-ruby2/2.11.458",
'X-Aws-Ec2-Metadata-Token-Ttl-Seconds': "21600" })
.to_return(status: 200, body: "", headers: {})
no_default = <<-CREDS.strip
[fooprofile]
aws_access_key_id = ACCESS_KEY_1
Expand Down

0 comments on commit 46c7f1e

Please sign in to comment.