diff options
author | Hendrik Jäger <gitcommit@henk.geekmail.org> | 2024-02-01 14:10:28 +0100 |
---|---|---|
committer | Hendrik Jäger <gitcommit@henk.geekmail.org> | 2024-02-01 14:10:28 +0100 |
commit | 096b365dec694df1a77114c38f39f072fd121774 (patch) | |
tree | a075ca39b52adc417161d7b504f277475845f603 | |
parent | 59e6bf30ba692061c6ee2617deb30b8556ffd07f (diff) |
change account key file handling to be more robust and shorter
-rw-r--r-- | macir.rb | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -16,9 +16,8 @@ def read_config( path = 'config.yaml' ) rescue Psych::SyntaxError $stderr.puts "Parsing configfile failed: " + $!.to_s raise - rescue Errno::ENOENT => ex + rescue Errno::ENOENT $stderr.puts "IO failed: " + $!.to_s - p ex end return config end @@ -26,17 +25,19 @@ end def read_account_key( path = 'pkey.pem' ) p "Reading account key from #{path}" if File.readable?( path ) - p "Key exists, trying to parse" - pkey_file = File.new( path ) - privatekey_string = pkey_file.read + p "File #{path} is readable, trying to parse" + privatekey_string = File.read( path ) private_key = OpenSSL::PKey::EC.new( privatekey_string ) else - p "Key does not exist, trying to create" - pkey_file = File.new( path, 'w' ) - private_key = OpenSSL::PKey::EC.generate( "prime256v1" ) - pkey_pem = private_key.private_to_pem - pkey_file.write( pkey_pem ) + if File.exists?( path ) + raise( "The file #{path} exists but is not readable. Make it readable or specify different path" ) + else + p "File #{path} does not exist, trying to create" + private_key = OpenSSL::PKey::EC.generate( "prime256v1" ) + File.write( path, private_key.private_to_pem ) + end end + return private_key end def deploy_dns01_challenge_token( domain, token, nameserver, config ) |