Module: CemAcpt::Utils::NodeUtils
- Defined in:
- lib/cem_acpt/utils.rb
Class Method Summary collapse
- .ephemeral_ssh_key(type: 'ecdsa', bits: '521', comment: nil, keydir: '/tmp') ⇒ Object
- .random_instance_name(prefix: 'cem-acpt-', length: 24) ⇒ Object
Class Method Details
.ephemeral_ssh_key(type: 'ecdsa', bits: '521', comment: nil, keydir: '/tmp') ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cem_acpt/utils.rb', line 50 def self.ephemeral_ssh_key(type: 'ecdsa', bits: '521', comment: nil, keydir: '/tmp') raise ArgumentError, 'keydir does not exist' unless File.directory?(keydir) keyfile = "#{keydir}/#{SecureRandom.hex(16)}" keygen_cmd = [ 'ssh-keygen', "-t #{type}", "-b #{bits}", "-f #{keyfile}", '-N ""', '-q', ] keygen_cmd << "-C \"#{comment}\"" if comment _, stderr, status = Open3.capture3(keygen_cmd.join(' ')) raise "Failed to generate ephemeral SSH key: #{stderr}" unless status.success? [keyfile, "#{keyfile}.pub"] end |
.random_instance_name(prefix: 'cem-acpt-', length: 24) ⇒ Object
45 46 47 48 |
# File 'lib/cem_acpt/utils.rb', line 45 def self.random_instance_name(prefix: 'cem-acpt-', length: 24) rand_length = length - prefix.length "#{prefix}#{SecureRandom.hex(rand_length)}" end |