Sha256: 390c9830e14eb599a8b251128f4baf1c6e19eeb773d70af0c56e5053bb39fbcd
Contents?: true
Size: 911 Bytes
Versions: 17
Compression:
Stored size: 911 Bytes
Contents
require 'yaml' require "base64" require 'bcrypt' # The main Smartcloud User driver module Smartcloud class User < Smartcloud::Base def initialize end def self.create_htpasswd_files htpasswd_dirpath = "#{Dir.pwd}/grids/grid-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 |hostname, 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/grid-nginx/htpasswd/#{hostname}", "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
17 entries across 17 versions & 1 rubygems