Class: Kontena::Machine::Aws::KeypairProvisioner
- Inherits:
-
Object
- Object
- Kontena::Machine::Aws::KeypairProvisioner
- Defined in:
- lib/kontena/machine/aws/keypair_provisioner.rb
Instance Attribute Summary collapse
-
#ec2 ⇒ Object
readonly
Returns the value of attribute ec2.
-
#keypair_name ⇒ Object
readonly
Returns the value of attribute keypair_name.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
-
#initialize(access_key_id, secret_key, region) ⇒ KeypairProvisioner
constructor
A new instance of KeypairProvisioner.
- #run!(opts) ⇒ Object
- #validate_opts!(opts) ⇒ Object
Constructor Details
#initialize(access_key_id, secret_key, region) ⇒ KeypairProvisioner
Returns a new instance of KeypairProvisioner.
11 12 13 14 15 |
# File 'lib/kontena/machine/aws/keypair_provisioner.rb', line 11 def initialize(access_key_id, secret_key, region) @ec2 = ::Aws::EC2::Resource.new( region: region, credentials: ::Aws::Credentials.new(access_key_id, secret_key) ) end |
Instance Attribute Details
#ec2 ⇒ Object (readonly)
Returns the value of attribute ec2.
6 7 8 |
# File 'lib/kontena/machine/aws/keypair_provisioner.rb', line 6 def ec2 @ec2 end |
#keypair_name ⇒ Object (readonly)
Returns the value of attribute keypair_name.
6 7 8 |
# File 'lib/kontena/machine/aws/keypair_provisioner.rb', line 6 def keypair_name @keypair_name end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
6 7 8 |
# File 'lib/kontena/machine/aws/keypair_provisioner.rb', line 6 def public_key @public_key end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
6 7 8 |
# File 'lib/kontena/machine/aws/keypair_provisioner.rb', line 6 def region @region end |
Instance Method Details
#run!(opts) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/kontena/machine/aws/keypair_provisioner.rb', line 28 def run!(opts) validate_opts!(opts) ec2.import_key_pair( key_name: keypair_name, public_key_material: public_key, dry_run: false ) end |
#validate_opts!(opts) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/kontena/machine/aws/keypair_provisioner.rb', line 17 def validate_opts!(opts) if opts[:public_key] @public_key = opts[:public_key] else raise "Missing public key" end @keypair_name = opts[:keypair_name] || "kontena-#{SecureRandom.hex(4)}-#{Time.now.strftime '%Y-%m-%d'}" end |