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

Version Path
smartcloud-0.6.0 lib/smartcloud/user.rb
smartcloud-0.5.3 lib/smartcloud/user.rb
smartcloud-0.5.2 lib/smartcloud/user.rb
smartcloud-0.5.1 lib/smartcloud/user.rb
smartcloud-0.5.0 lib/smartcloud/user.rb
smartcloud-0.4.4 lib/smartcloud/user.rb
smartcloud-0.4.3 lib/smartcloud/user.rb
smartcloud-0.4.2 lib/smartcloud/user.rb
smartcloud-0.4.1 lib/smartcloud/user.rb
smartcloud-0.3.2 lib/smartcloud/user.rb
smartcloud-0.3.1 lib/smartcloud/user.rb
smartcloud-0.3.0 lib/smartcloud/user.rb
smartcloud-0.2.4 lib/smartcloud/user.rb
smartcloud-0.2.3 lib/smartcloud/user.rb
smartcloud-0.2.2 lib/smartcloud/user.rb
smartcloud-0.2.1 lib/smartcloud/user.rb
smartcloud-0.2.0 lib/smartcloud/user.rb