Sha256: 468dc328befa7574b11758a22b85c4171279bf449e82e7952147c02610c9ebae
Contents?: true
Size: 911 Bytes
Versions: 2
Compression:
Stored size: 911 Bytes
Contents
require 'yaml' require "base64" require 'bcrypt' # The main SmartMachine User driver module SmartMachine class User < SmartMachine::Base def initialize end def self.create_htpasswd_files htpasswd_dirpath = "#{Dir.pwd}/grids/nginx/htpasswd" # Remove existing htpasswd_dirpath FileUtils.rm_r htpasswd_dirpath if Dir.exist?(htpasswd_dirpath) # Create new htpasswd_dirpath FileUtils.mkdir htpasswd_dirpath # Add hostfiles to htpasswd_dirpath self.get_users_from_file.each do |domainname, users| next unless users file_data = "" users.each do |user, password| file_data += "#{user}:#{BCrypt::Password.create(password)}\n" end File.open("#{Dir.pwd}/grids/nginx/htpasswd/#{domainname}", "w") { |file| file.write(file_data) } end end private def self.get_users_from_file YAML.load_file("#{Dir.pwd}/config/users.yml") || Hash.new end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
smartmachine-0.8.0 | lib/smart_machine/user.rb |
smartmachine-0.7.0 | lib/smart_machine/user.rb |