Class: Gisha::Commands::Key
- Inherits:
-
Object
- Object
- Gisha::Commands::Key
- Defined in:
- lib/gisha/commands/key.rb
Instance Attribute Summary collapse
-
#auth_file ⇒ Object
readonly
Returns the value of attribute auth_file.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #add ⇒ Object
- #del ⇒ Object
-
#initialize(auth_file, id, key = nil) ⇒ Key
constructor
A new instance of Key.
Constructor Details
#initialize(auth_file, id, key = nil) ⇒ Key
Returns a new instance of Key.
5 6 7 8 9 |
# File 'lib/gisha/commands/key.rb', line 5 def initialize(auth_file, id, key = nil) @auth_file = auth_file @id = id @key = key end |
Instance Attribute Details
#auth_file ⇒ Object (readonly)
Returns the value of attribute auth_file.
3 4 5 |
# File 'lib/gisha/commands/key.rb', line 3 def auth_file @auth_file end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/gisha/commands/key.rb', line 3 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/gisha/commands/key.rb', line 3 def key @key end |
Instance Method Details
#add ⇒ Object
11 12 13 14 15 |
# File 'lib/gisha/commands/key.rb', line 11 def add lock do open(auth_file, 'a') { |file| file.puts(key_line) } end end |
#del ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gisha/commands/key.rb', line 17 def del lock do Tempfile.open('authorized_keys') do |temp| open(auth_file, 'r+') do |current| current.each do |line| temp.puts(line) unless line.include?("gisha receive key-#{id}") end end temp.close FileUtils.cp(temp.path, auth_file) end end end |