module RsyncConfig::UserManagement
Public Class Methods
included(base)
click to toggle source
# File lib/rsync_config/user_management.rb, line 5 def self.included base base.extend ClassMethods end
Public Instance Methods
load_secrets_file(file)
click to toggle source
# File lib/rsync_config/user_management.rb, line 66 def load_secrets_file(file) # fails silently if no parameter is found OR the file does not exist on disk return if file.nil? || !(File.exist? file) # fails is the file exists but cannot be read, since it's suspicious raise "Cannot load secrets file #{file}" unless File.readable?(file) File.open(file, 'r') do |file| self.users = self.class.parse_secrets_file(file.read) end end
local_user_list()
click to toggle source
# File lib/rsync_config/user_management.rb, line 44 def local_user_list # we need to output only what is related to this specific node local_users.keys.map do |user| "#{user}:#{local_users[user]}" end end
local_users()
click to toggle source
# File lib/rsync_config/user_management.rb, line 32 def local_users @users ||= {} end
user?(identifier)
click to toggle source
# File lib/rsync_config/user_management.rb, line 36 def user? identifier users.include? identifier end
users()
click to toggle source
# File lib/rsync_config/user_management.rb, line 27 def users return @parent_config.users if @parent_config && @users.nil? local_users end
users=(users_list)
click to toggle source
# File lib/rsync_config/user_management.rb, line 40 def users= (users_list) @users = users_list if users_list.is_a?(Hash) || users_list.nil? end
write_secrets_file(secrets_file)
click to toggle source
# File lib/rsync_config/user_management.rb, line 51 def write_secrets_file(secrets_file) return if secrets_file.nil? file = secrets_file.respond_to?(:output) ? secrets_file.output : secrets_file.to_s raise "Cannot write secrets file #{file}" if File.exists?(file) && ! File.writable?(file) raise "Cannot create secrets file #{file}" if !File.exist?(file) && ! ( Dir.exists?(File.dirname(file)) && File.writable?(File.dirname(file))) File.open(file, 'w') do |file| file.write local_user_list.join "\n" end correct_file_permissions file end
Private Instance Methods
correct_file_permissions(file)
click to toggle source
# File lib/rsync_config/user_management.rb, line 80 def correct_file_permissions(file) if File.world_readable?(file) || File.world_writable?(file) # reuse existing permissions but remove everything from world File.chmod (File.stat(file).mode & 0770), file end end