Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3Source does not extend any Chef classes, so config is not an inherited attribute #667

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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