This repository has been archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Aws | ||
module EC2 | ||
class Instance | ||
# instance_id Provide an instance ID | ||
# @option options [Client] :client Optionally provide an existing EC2 client | ||
def initialize(instance_id = nil, options = {}) | ||
@instance_id = instance_id | ||
fail "Instance ID is required" if @instance_id.nil? | ||
@client = options[:client] || Aws::EC2::Client.new | ||
end | ||
|
||
def decrypted_windows_password(key_pair_path) | ||
password_data = client.get_password_data instance_id: instance_id | ||
decoded = Base64.decode64 password_data.strip | ||
pem_bytes = Pathname.new(key_pair_path).read | ||
private_key = OpenSSL::PKey::RSA.new pem_bytes | ||
private_key.private_decrypt decoded | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'spec_helper' | ||
|
||
module Aws | ||
module EC2 | ||
describe Instance do | ||
before (:each) do | ||
Aws.config[:ec2] = { | ||
region: 'us-east-1', | ||
credentials: Credentials.new( | ||
"AKIAIOSFODNN7EXAMPLE", | ||
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"), | ||
retry_limit: 0 | ||
} | ||
end | ||
|
||
after(:each) do | ||
Aws.config = {} | ||
end | ||
|
||
let(:client) { Aws::EC2::Client.new } | ||
|
||
describe '#initialize' do | ||
it 'accepts an injected EC2 client' do | ||
pre = Instance.new('i-abcd1234', client: client) | ||
expect(pre.class).to eq(Aws::EC2::Instance) | ||
end | ||
|
||
it 'can be constructed without a client' do | ||
pre = Instance.new('i-abcd1234') | ||
expect(pre.class).to eq(Aws::EC2::Instance) | ||
end | ||
|
||
it 'throws if instance ID is missing' do | ||
expect { Instance.new }.to raise_error(RuntimeError) | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |