Skip to content

Commit

Permalink
Optimize our requires
Browse files Browse the repository at this point in the history
Avoid requiring things that are already defined. Rubygems is very slow at traversing the filesystem.

Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Aug 20, 2020
1 parent f44c5c5 commit f97485f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rescue LoadError
end

begin
require "yard"
require "yard" unless defined?(YARD)
YARD::Rake::YardocTask.new(:docs)
rescue LoadError
puts "yard is not available. bundle install first to make sure all dependencies are installed."
Expand Down
12 changes: 6 additions & 6 deletions lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Ec2ServerCreate < Chef::Knife::Bootstrap
include Knife::Ec2Base

deps do
require "tempfile"
require "uri"
require "net/ssh"
require "tempfile" unless defined?(Tempfile)
require "uri" unless defined?(URI)
require "net/ssh" unless defined?(Net::SSH)
require "net/ssh/gateway"
Chef::Knife::Bootstrap.load_deps
end
Expand Down Expand Up @@ -826,7 +826,7 @@ def process_user_data(script_lines)

# base64-encoded text
def encode_data(text)
require "base64"
require "base64" unless defined?(Base64)
Base64.encode64(text)
end

Expand Down Expand Up @@ -1321,8 +1321,8 @@ def tcp_test_ssh(hostname, ssh_port)
end

def decrypt_admin_password(encoded_password, key)
require "base64"
require "openssl"
require "base64" unless defined?(Base64)
require "openssl" unless defined?(OpenSSL)
private_key = OpenSSL::PKey::RSA.new(key)
encrypted_password = Base64.decode64(encoded_password)
private_key.private_decrypt(encrypted_password)
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/ec2_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@
end

describe "attach ssl config into user data when transport is ssl" do
require "base64"
require "base64" unless defined?(Base64)

before(:each) do
allow(knife_ec2_create).to receive(:validate_aws_config!)
Expand Down

0 comments on commit f97485f

Please sign in to comment.