Sha256: 1fa8c786a3e19278642e9403f57828f076ecdf66133bbee8b6d786cd537959b8

Contents?: true

Size: 979 Bytes

Versions: 2

Compression:

Stored size: 979 Bytes

Contents

require 'yaml'
require "base64"

# 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|
					salt = Base64.encode64((("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a).shuffle[0..7].join)
					file_data += "#{user}:#{password.crypt(salt)}\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

2 entries across 2 versions & 1 rubygems

Version Path
smartcloud-0.2.0.beta2 lib/smartcloud/user.rb
smartcloud-0.2.0.beta1 lib/smartcloud/user.rb