Skip to content

Commit

Permalink
Merge pull request #667 from signe/s3source-config-fix
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 authored Mar 25, 2021
2 parents 1ea8a45 + bb43e30 commit dd68fc6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ def download_validation_key(tempfile)

def s3_validation_key
@s3_validation_key ||= begin
Chef::Knife::S3Source.fetch(config[:validation_key_url])
Chef::Knife::S3Source.fetch(config[:validation_key_url], config)
end
end

def s3_secret
@s3_secret ||= begin
return false unless config[:s3_secret]

Chef::Knife::S3Source.fetch(config[:s3_secret])
Chef::Knife::S3Source.fetch(config[:s3_secret], config)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/chef/knife/helpers/s3_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
class Chef
class Knife
class S3Source
attr_accessor :url
attr_accessor :url, :config

def self.fetch(url)
def self.fetch(url, config)
source = Chef::Knife::S3Source.new
source.url = url
source.config = config
source.body
end

Expand Down
16 changes: 9 additions & 7 deletions spec/unit/s3_source_deps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@

it "lazy loads Aws::S3::Client without required config" do
begin
Chef::Knife::S3Source.fetch("test")
knife_config = {}
Chef::Knife::S3Source.fetch("test", knife_config)
rescue Exception => e
expect(e).to be_a_kind_of(NoMethodError)
expect(e).to be_a_kind_of(ArgumentError)
end
end

it "lazy loads Aws::S3::Client with required config" do
begin
Chef::Config[:knife][:aws_access_key_id] = "aws_access_key_id"
Chef::Config[:knife][:aws_secret_access_key] = "aws_secret_access_key"
Chef::Config[:knife][:region] = "test-region"
Chef::Knife::S3Source.fetch("test")
knife_config = {}
knife_config[:aws_access_key_id] = "aws_access_key_id"
knife_config[:aws_secret_access_key] = "aws_secret_access_key"
knife_config[:region] = "test-region"
Chef::Knife::S3Source.fetch("/test/testfile", knife_config)
rescue Exception => e
expect(e).to be_a_kind_of(ArgumentError)
expect(e).to be_a_kind_of(Aws::Errors::NoSuchEndpointError)
end
end
end

0 comments on commit dd68fc6

Please sign in to comment.