Sha256: 852a8a6f678735bcc5bb1ca340fa5551b4b0d5e0095b795c7df9bbf83625d04c
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
module Gitolite #Models an SSH key within gitolite #provides support for multikeys # #Types of multi keys: # bob.pub => username: bob # bob@desktop.pub => username: bob, location: desktop # bob@email.com.pub => username: bob@email.com # bob@email.com@desktop.pub => username: bob@email.com, location: desktop class SSHKey attr_accessor :owner, :location, :type, :blob, :email def initialize(type, blob, email, owner = nil, location = "") @type = type @blob = blob @email = email @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 || "" #Get parts of the key type, blob, email = File.read(key).split #If the key didn't have an email, just use the owner if email.nil? email = owner end self.new(type, blob, email, owner, location) end def to_s [@type, @blob, @email].join(' ') end def to_file(filename) File.open(filename, "w") do |f| f.write (self.to_s) end end def filename file = @owner file += "@#{@location}" unless @location.empty? file += ".pub" end def ==(key) @type == key.type && @blob == key.blob && @email == key.email && @owner == key.owner && @location == key.location end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gitolite-0.0.1.alpha | lib/gitolite/ssh_key.rb |