Class: Gisha::Commands::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/gisha/commands/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject (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

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/gisha/commands/key.rb', line 3

def id
  @id
end

#keyObject (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

#addObject



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

#delObject



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