Class: ForemanOpentofu::TofuKeyPair

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_opentofu/tofu_key_pair.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ TofuKeyPair

Returns a new instance of TofuKeyPair.



6
7
8
9
10
11
# File 'app/services/foreman_opentofu/tofu_key_pair.rb', line 6

def initialize(name)
  @name = name
  @keypair = KeyPair.find_by name: name
  @public_key = @keypair&.public
  @private_key = @keypair&.secret
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'app/services/foreman_opentofu/tofu_key_pair.rb', line 3

def name
  @name
end

#opentofu_executerObject

Returns the value of attribute opentofu_executer.



4
5
6
# File 'app/services/foreman_opentofu/tofu_key_pair.rb', line 4

def opentofu_executer
  @opentofu_executer
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



3
4
5
# File 'app/services/foreman_opentofu/tofu_key_pair.rb', line 3

def private_key
  @private_key
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



3
4
5
# File 'app/services/foreman_opentofu/tofu_key_pair.rb', line 3

def public_key
  @public_key
end

Instance Method Details

#destroyObject



19
20
21
22
# File 'app/services/foreman_opentofu/tofu_key_pair.rb', line 19

def destroy
  opentofu_executer.run_destroy_key(self)
  @keypair.try :destroy
end

#generateObject



13
14
15
16
17
# File 'app/services/foreman_opentofu/tofu_key_pair.rb', line 13

def generate
  key = OpenSSL::PKey::RSA.generate(Setting[:tofu_ssh_key_bits])
  @private_key = key.private_to_pem
  @public_key = "#{key.ssh_type} #{[key.to_blob].pack('m0')}"
end