Permalink
Browse files

Replace hash with class

This makes access easier: key.id and key.secret instead of key[:id] and key[:secret]
  • Loading branch information...
pieter committed Jun 4, 2012
1 parent 7e0a7f3 commit aa6109e8f2c3f9ce01d677db71b9ee49c99a3a31
Showing with 11 additions and 1 deletion.
  1. +11 −1 lib/aws-keys.rb
View
@@ -1,6 +1,16 @@
module AwsKeys
class KeyNotFoundException < Exception; end
class Key
attr_accessor :id, :secret
def initialize (id, secret)
@id = id
@secret = secret
end
end
PATHS = [".ec2"]
PATHS.push(File.expand_path("~/.ec2")) if ENV["HOME"]
PATHS.push("/etc/ec2")
@@ -23,7 +33,7 @@ def self.keys (type)
data = File.read(path)
# Explicitly match with regex, to make sure our data is right
re = /AWSAccessKeyId=([A-Z0-9]+)\nAWSSecretKey=([^\n]+)\n?$/
return { :id => $1, :secret => $2 } if data =~ re
return Key.new($1, $2) if data =~ re
return
end

0 comments on commit aa6109e

Please sign in to comment.