Class: GitWit::AuthorizedKeys::File
- Inherits:
-
AuthorizedKeys::File
- Object
- AuthorizedKeys::File
- GitWit::AuthorizedKeys::File
- Defined in:
- lib/git_wit/authorized_keys.rb
Instance Attribute Summary collapse
-
#original_location ⇒ Object
Returns the value of attribute original_location.
Instance Method Summary collapse
- #clear(&block) ⇒ Object
- #keys ⇒ Object
- #modify(mode, &block) ⇒ Object
- #owned? ⇒ Boolean
- #owner(file = nil) ⇒ Object
- #remove(key) ⇒ Object
Instance Attribute Details
#original_location ⇒ Object
Returns the value of attribute original_location.
34 35 36 |
# File 'lib/git_wit/authorized_keys.rb', line 34 def original_location @original_location end |
Instance Method Details
#clear(&block) ⇒ Object
86 87 88 |
# File 'lib/git_wit/authorized_keys.rb', line 86 def clear(&block) modify "w", &block end |
#keys ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/git_wit/authorized_keys.rb', line 36 def keys list = [] modify "r" do |file| file.each do |line| list << Key.new(line.chomp) end end list end |
#modify(mode, &block) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/git_wit/authorized_keys.rb', line 68 def modify(mode, &block) return super if owned? || self.original_location contents = %x(sudo -u "##{owner}" cat "#{location}") unless mode.include? "w" original_owner = owner self.original_location = location tmp = Tempfile.new "git_wit_authorized_keys" self.location = tmp.path tmp.write contents unless mode.include? "w" tmp.close super self.location = original_location if mode != "r" %x(cat "#{tmp.path}" | sudo -u "##{owner}" tee "#{location}" >/dev/null) end tmp.unlink self.original_location = nil end |
#owned? ⇒ Boolean
56 57 58 |
# File 'lib/git_wit/authorized_keys.rb', line 56 def owned? owner == Process.uid end |
#owner(file = nil) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/git_wit/authorized_keys.rb', line 60 def owner(file = nil) file ||= location ::File.stat(file).uid rescue Errno::EACCES, Errno::ENOENT parent = ::File.dirname file owner parent unless file == parent end |
#remove(key) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/git_wit/authorized_keys.rb', line 46 def remove(key) key = Key.new(key) if key.is_a?(String) cached_keys = keys modify 'w' do |file| cached_keys.each do |k| file.puts k unless key == k end end end |