62 lines
1.1 KiB
Ruby
62 lines
1.1 KiB
Ruby
|
module EmacsCollab
|
||
|
class Project
|
||
|
attr_accessor :id, :path, :posixname, :users
|
||
|
attr_reader :keys
|
||
|
|
||
|
def initialize
|
||
|
@users = []
|
||
|
end
|
||
|
|
||
|
def to_s
|
||
|
"#{@id}, #{@path}"
|
||
|
end
|
||
|
|
||
|
def add_key(key)
|
||
|
@keys << key
|
||
|
end
|
||
|
|
||
|
def add_user(user)
|
||
|
@users << user
|
||
|
user.keys.each do |key|
|
||
|
add_key(key)
|
||
|
end
|
||
|
flush
|
||
|
refresh
|
||
|
end
|
||
|
|
||
|
def remove_user(user)
|
||
|
@user.delete(user)
|
||
|
flush
|
||
|
refresh
|
||
|
end
|
||
|
|
||
|
def refresh
|
||
|
@users = File.open("#{@path}/.ssh/users","r") do |f|
|
||
|
f.read.split("\n").map{|id| get_user_by_id(id)}
|
||
|
end
|
||
|
@keys = extract_ssh_pubkeys("#{@path}/.ssh/authorized_keys")
|
||
|
end
|
||
|
|
||
|
def flush
|
||
|
File.open("#{@path}/.ssh/users","w+") do |user_file|
|
||
|
@users.each do |u|
|
||
|
user_file << "#{u.id}\n"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
get_ssh_keyfile(self,"w+") do |key_file|
|
||
|
@users.each do |user|
|
||
|
user.keys.each do |key|
|
||
|
key_file << "#{key.to_s}\n"
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
class DuplicateProjectError < StandardError
|
||
|
end
|
||
|
|
||
|
end
|