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
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 )