Class: ForemanOpentofu::TofuKeyPair
- Inherits:
-
Object
- Object
- ForemanOpentofu::TofuKeyPair
- Defined in:
- app/services/foreman_opentofu/tofu_key_pair.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opentofu_executer ⇒ Object
Returns the value of attribute opentofu_executer.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
Instance Method Summary collapse
- #destroy ⇒ Object
- #generate ⇒ Object
-
#initialize(name) ⇒ TofuKeyPair
constructor
A new instance of TofuKeyPair.
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
#name ⇒ Object (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_executer ⇒ Object
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_key ⇒ Object (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_key ⇒ Object (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
#destroy ⇒ Object
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 |
#generate ⇒ Object
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 |