X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=macir.rb;fp=macir.rb;h=83f1917a39b107e8f9244718ad72f2c79198b39f;hb=096b365dec694df1a77114c38f39f072fd121774;hp=9523a0fdaf14c2be91aecf4ab65e833ae60da069;hpb=59e6bf30ba692061c6ee2617deb30b8556ffd07f;p=user%2Fhenk%2Fcode%2Fruby%2Fmacir.git diff --git a/macir.rb b/macir.rb index 9523a0f..83f1917 100644 --- a/macir.rb +++ b/macir.rb @@ -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 )