Class: VagrantPlugins::AWS::WinRM::Capability
- Inherits:
-
Object
- Object
- VagrantPlugins::AWS::WinRM::Capability
- Defined in:
- lib/vagrant-aws-winrm/capability.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Capability
constructor
A new instance of Capability.
Constructor Details
#initialize(app, env) ⇒ Capability
Returns a new instance of Capability.
8 9 10 11 |
# File 'lib/vagrant-aws-winrm/capability.rb', line 8 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_aws_winrm::capability::winrm_info") end |
Class Method Details
.winrm_info(machine) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vagrant-aws-winrm/capability.rb', line 13 def self.winrm_info(machine) if machine.config.winrm.password == :aws machine.ui.info('Getting WinRM password from AWS...') # Call the VagrantPlugins::AWS::Action::ConnectAWS # middleware so we can get acces to the Fog connection machine.env.action_runner.run( Vagrant::Action::Builder.new.tap do |b| b.use VagrantPlugins::AWS::Action::ConnectAWS b.use self end, { machine: machine, ui: machine.ui, } ) end return {} end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-aws-winrm/capability.rb', line 32 def call(env) machine = env[:machine] aws = env[:aws_compute] response = aws.get_password_data({ instance_id: machine.id }) password_data = response.body['passwordData'] password_data_bytes = Base64.decode64(password_data) # Try to decrypt the password data using each one of the private key files # set by the user until we hit one that decrypts successfully machine.config.ssh.private_key_path.each do |private_key_path| private_key_path = File. private_key_path @logger.info("Decrypting password data using #{private_key_path}") rsa = OpenSSL::PKey::RSA.new File.read private_key_path begin machine.config.winrm.password = rsa.private_decrypt password_data_bytes @logger.info("Successfully decrypted password data using #{private_key_path}") rescue OpenSSL::PKey::RSAError @logger.warn("Failed to decrypt password data using #{private_key_path}") next end break end end |