Class: Giticious::Service::Pubkey
- Inherits:
-
Object
- Object
- Giticious::Service::Pubkey
- Defined in:
- lib/giticious/service/pubkey.rb
Instance Method Summary collapse
- #add(user, pubkey) ⇒ Object
- #all ⇒ Object
- #delete(pubkey) ⇒ Object
- #exists?(pubkey) ⇒ Boolean
-
#initialize ⇒ Pubkey
constructor
A new instance of Pubkey.
- #user_pubkeys(user) ⇒ Object
Constructor Details
#initialize ⇒ Pubkey
Returns a new instance of Pubkey.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/giticious/service/pubkey.rb', line 5 def initialize @filename = "#{Dir.home}/.ssh/authorized_keys" if false == File.exists?(@filename) FileUtils.touch(@filename) end if false == File.owned?(@filename) raise RuntimeError, "File #{@filename} is not owned by the current user" end end |
Instance Method Details
#add(user, pubkey) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/giticious/service/pubkey.rb', line 27 def add(user, pubkey) if exists?(pubkey) raise RuntimeError, "This public key does already exist" end append_line('command="/usr/local/bin/giticious gitserve ' + user + '",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ' + pubkey) end |
#all ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/giticious/service/pubkey.rb', line 39 def all matches = {} File.open(@filename) do |file| file.each_line do |line| res = line.match(/gitserve ([A-Za-z0-9_]+)\".*no\-pty (.*)/) if res.nil? == false username = res[1] key = res[2] if matches.has_key?(username) == false matches[username] = [] end matches[username] << key end end end matches end |
#delete(pubkey) ⇒ Object
35 36 37 |
# File 'lib/giticious/service/pubkey.rb', line 35 def delete(pubkey) delete_matches(pubkey) end |
#exists?(pubkey) ⇒ Boolean
17 18 19 20 21 22 23 24 25 |
# File 'lib/giticious/service/pubkey.rb', line 17 def exists?(pubkey) File.open(@filename) do |file| file.each_line do |line| return true if line.include?(pubkey) end end false end |
#user_pubkeys(user) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/giticious/service/pubkey.rb', line 62 def user_pubkeys(user) pubkeys = all() if pubkeys.has_key?(user) return pubkeys[user] end return [] end |