lib/gitolite/ssh_key.rb in gitolite-0.0.3.alpha vs lib/gitolite/ssh_key.rb in gitolite-1.0.0

- old
+ new

@@ -19,19 +19,33 @@ @owner = owner || email @location = location end def self.from_file(key) - raise "#{key} does not exist!" unless File.exists?(key) #Get our owner and location File.basename(key) =~ /^([\w\.-]+(?:@(?:[\w-]+\.)+\D{2,4})?)(?:@(\w+))?.pub$/i owner = $1 location = $2 || "" + # Use string key constructor + self.from_string(File.read(key), owner, location) + end + + # Construct a SSHKey from a string + def self.from_string(key_string, owner, location = "") + if owner.nil? + raise ArgumentError, "owner was nil, you must specify an owner" + end + #Get parts of the key - type, blob, email = File.read(key).split + type, blob, email = key_string.split + + # We need at least a type or blob + if type.nil? || blob.nil? + raise ArgumentError, "'#{key_string}' is not a valid SSH key string" + end #If the key didn't have an email, just use the owner if email.nil? email = owner end