Module: Stem::KeyPair

Extended by:
KeyPair
Includes:
Util
Included in:
KeyPair
Defined in:
lib/stem/key_pair.rb

Instance Method Summary collapse

Methods included from Util

#get_filter_opts, #swirl, #tags_to_filter, #tagset_to_hash

Instance Method Details

#create(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/stem/key_pair.rb', line 6

def create(name)
    swirl.call('CreateKeyPair', 'KeyName' => name)
    true
  rescue Swirl::InvalidRequest => e
    raise e unless e.message =~ /The keypair '\S+' already exists/
    false
end

#describe(names) ⇒ Object



28
29
30
# File 'lib/stem/key_pair.rb', line 28

def describe(names)
  swirl.call('DescribeKeyPairs', 'KeyName' => names)
end

#destroy(name) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/stem/key_pair.rb', line 14

def destroy(name)
    destroy!(name)
    true
  rescue Swirl::InvalidRequest => e
    puts "===> #{e.class}"
    puts "===> #{e.message}"
    puts "#{e.backtrace.join("\n")}"
    false
end

#destroy!(name) ⇒ Object



24
25
26
# File 'lib/stem/key_pair.rb', line 24

def destroy!(name)
  swirl.call('DeleteKeyPair', 'KeyName' => name)
end

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/stem/key_pair.rb', line 32

def exists?(name)
    true if describe(name)
  rescue Swirl::InvalidRequest => e
    raise e unless e.message.match(/does not exist$/)
    false
end

#import(name, key_string) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stem/key_pair.rb', line 39

def import(name, key_string)
    require 'base64'
    swirl.call('ImportKeyPair', {
      'KeyName' => name,
      'PublicKeyMaterial' => Base64.encode64(key_string)
    })
    true
  rescue Swirl::InvalidRequest => e
    raise e unless e.message =~ /The keypair '\S+' already exists/
    false
end