summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--macir.rb21
1 files changed, 11 insertions, 10 deletions
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 )