Skip to content

Commit 86488ff

Browse files
committedMar 20, 2024··
Chefstyle fixes
Signed-off-by: Ashique Saidalavi <Ashique.saidalavi@progress.com>
1 parent a098423 commit 86488ff

File tree

4 files changed

+45
-53
lines changed

4 files changed

+45
-53
lines changed
 

‎lib/chef/knife/ec2_server_create.rb

+15-21
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,11 @@ def default_bootstrap_template
495495
end
496496

497497
def validation_key_path
498-
@validation_key_path ||= begin
499-
if URI(config[:validation_key_url]).scheme == "file"
500-
URI(config[:validation_key_url]).path
501-
else
502-
validation_key_tmpfile.path
503-
end
504-
end
498+
@validation_key_path ||= if URI(config[:validation_key_url]).scheme == "file"
499+
URI(config[:validation_key_url]).path
500+
else
501+
validation_key_tmpfile.path
502+
end
505503
end
506504

507505
# @return [Tempfile]
@@ -521,9 +519,7 @@ def download_validation_key(tempfile)
521519
end
522520

523521
def s3_validation_key
524-
@s3_validation_key ||= begin
525-
Chef::Knife::S3Source.fetch(config[:validation_key_url], config)
526-
end
522+
@s3_validation_key ||= Chef::Knife::S3Source.fetch(config[:validation_key_url], config)
527523
end
528524

529525
def s3_secret
@@ -759,8 +755,8 @@ def ssl_config_user_data
759755
user = connection_user.split("\\")
760756
if (user[0] == ".") || (user[0] == "") || (user.length == 1)
761757
user_related_commands = <<~EOH
762-
net user /add #{connection_user.delete('.\\')} #{windows_password} #{@allow_long_password};
763-
net localgroup Administrators /add #{connection_user.delete('.\\')};
758+
net user /add #{connection_user.delete(".\\")} #{windows_password} #{@allow_long_password};
759+
net localgroup Administrators /add #{connection_user.delete(".\\")};
764760
EOH
765761
end
766762
<<~EOH
@@ -1141,15 +1137,13 @@ def connection_host
11411137
# Otherwise assign public DNS or public IP.
11421138
# @return [String]
11431139
def connect_attribute
1144-
@connect_attribute ||= begin
1145-
if !!config[:server_connect_attribute]
1146-
config[:server_connect_attribute]
1147-
elsif vpc_mode? && !(subnet_public_ip_on_launch? || config[:associate_public_ip] || config[:associate_eip])
1148-
"private_ip_address"
1149-
else
1150-
server.public_dns_name ? "public_dns_name" : "public_ip_address"
1151-
end
1152-
end
1140+
@connect_attribute ||= if !!config[:server_connect_attribute]
1141+
config[:server_connect_attribute]
1142+
elsif vpc_mode? && !(subnet_public_ip_on_launch? || config[:associate_public_ip] || config[:associate_eip])
1143+
"private_ip_address"
1144+
else
1145+
server.public_dns_name ? "public_dns_name" : "public_ip_address"
1146+
end
11531147
end
11541148

11551149
def create_tags(hashed_tags)

‎lib/chef/knife/helpers/ec2_base.rb

+5-7
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,11 @@ def validate_aws_config!(keys = %i{aws_access_key_id aws_secret_access_key})
234234
# if default location exists on disk fallback to that
235235
# @return [String, nil] location to aws credentials file or nil if none exists
236236
def aws_cred_file_location
237-
@cred_file ||= begin
238-
if !config[:aws_credential_file].nil?
239-
config[:aws_credential_file]
240-
else
241-
Chef::Util::PathHelper.home(".aws", "credentials") if ::File.exist?(Chef::Util::PathHelper.home(".aws", "credentials"))
242-
end
243-
end
237+
@cred_file ||= if !config[:aws_credential_file].nil?
238+
config[:aws_credential_file]
239+
else
240+
Chef::Util::PathHelper.home(".aws", "credentials") if ::File.exist?(Chef::Util::PathHelper.home(".aws", "credentials"))
241+
end
244242
end
245243

246244
# @return [String]

‎spec/spec_helper.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def self.from(system_exit)
2424
end
2525

2626
c.around(:example) do |ex|
27-
begin
28-
ex.run
29-
rescue SystemExit => e
30-
raise UnexpectedSystemExit.from(e)
31-
end
27+
28+
ex.run
29+
rescue SystemExit => e
30+
raise UnexpectedSystemExit.from(e)
31+
3232
end
3333
end

‎spec/unit/s3_source_deps_spec.rb

+20-20
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55

66
describe "Check Dependencies", exclude: Object.constants.include?(:Aws) do
77
it "should not load Aws::S3::Client by default" do
8-
begin
9-
Aws::S3::Client.new
10-
rescue Exception => e
11-
expect(e).to be_a_kind_of(NameError)
12-
end
8+
9+
Aws::S3::Client.new
10+
rescue Exception => e
11+
expect(e).to be_a_kind_of(NameError)
12+
1313
end
1414

1515
it "lazy loads Aws::S3::Client without required config" do
16-
begin
17-
knife_config = {}
18-
Chef::Knife::S3Source.fetch("test", knife_config)
19-
rescue Exception => e
20-
expect(e).to be_a_kind_of(ArgumentError)
21-
end
16+
17+
knife_config = {}
18+
Chef::Knife::S3Source.fetch("test", knife_config)
19+
rescue Exception => e
20+
expect(e).to be_a_kind_of(ArgumentError)
21+
2222
end
2323

2424
it "lazy loads Aws::S3::Client with required config" do
25-
begin
26-
knife_config = {}
27-
knife_config[:aws_access_key_id] = "aws_access_key_id"
28-
knife_config[:aws_secret_access_key] = "aws_secret_access_key"
29-
knife_config[:region] = "test-region"
30-
Chef::Knife::S3Source.fetch("/test/testfile", knife_config)
31-
rescue Exception => e
32-
expect(e).to be_a_kind_of(Aws::Errors::NoSuchEndpointError)
33-
end
25+
26+
knife_config = {}
27+
knife_config[:aws_access_key_id] = "aws_access_key_id"
28+
knife_config[:aws_secret_access_key] = "aws_secret_access_key"
29+
knife_config[:region] = "test-region"
30+
Chef::Knife::S3Source.fetch("/test/testfile", knife_config)
31+
rescue Exception => e
32+
expect(e).to be_a_kind_of(Aws::Errors::NoSuchEndpointError)
33+
3434
end
3535
end

0 commit comments

Comments
 (0)
Please sign in to comment.