Module: PuppetX::Certs::Provider::Keystore
- Defined in:
- lib/puppet_x/certs/provider/keystore.rb
Instance Method Summary collapse
- #create ⇒ Object
- #delete_keystore ⇒ Object
- #destroy ⇒ Object
- #exists? ⇒ Boolean
- #generate_keystore ⇒ Object
- #store ⇒ Object
- #type ⇒ Object
Instance Method Details
#create ⇒ Object
5 6 7 |
# File 'lib/puppet_x/certs/provider/keystore.rb', line 5 def create generate_keystore end |
#delete_keystore ⇒ Object
81 82 83 |
# File 'lib/puppet_x/certs/provider/keystore.rb', line 81 def delete_keystore FileUtils.rm_f(store) end |
#destroy ⇒ Object
9 10 11 |
# File 'lib/puppet_x/certs/provider/keystore.rb', line 9 def destroy delete_keystore end |
#exists? ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet_x/certs/provider/keystore.rb', line 13 def exists? return false unless File.exist?(store) begin keytool( '-list', '-keystore', store, '-storepass:file', resource[:password_file], '-J-Dcom.redhat.fips=false', ) rescue Puppet::ExecutionFailure => e if e..include?('java.security.UnrecoverableKeyException') || e..include?('keystore password was incorrect') Puppet.debug("Invalid password for #{store}") return false elsif e..include?('Keystore file exists, but is empty') Puppet.debug(e) return false else Puppet.log_exception(e, "Failed to read keystore '#{store}'") end end true end |
#generate_keystore ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet_x/certs/provider/keystore.rb', line 46 def generate_keystore temp_alias = 'temporary-entry' delete_keystore begin keytool( '-genkey', '-storetype', 'pkcs12', '-keystore', store, '-storepass:file', resource[:password_file], '-alias', temp_alias, '-dname', "CN=#{temp_alias}", '-J-Dcom.redhat.fips=false', '-keyalg', 'RSA' ) rescue Puppet::ExecutionFailure => e Puppet.err("Failed to generate new #{type} with temporary entry: #{e}") return nil end begin keytool( '-delete', '-keystore', store, '-storepass:file', resource[:password_file], '-alias', temp_alias, '-J-Dcom.redhat.fips=false' ) rescue Puppet::ExecutionFailure => e Puppet.err("Failed to delete temporary entry when generating empty #{type}: #{e}") return nil end end |
#store ⇒ Object
38 39 40 |
# File 'lib/puppet_x/certs/provider/keystore.rb', line 38 def store resource[:keystore] end |
#type ⇒ Object
42 43 44 |
# File 'lib/puppet_x/certs/provider/keystore.rb', line 42 def type 'keystore' end |