Sha256: d675f4d4a7e20b8250c3f7c786b40eb1a30e16293827ba91b32bdc124fa22372
Contents?: true
Size: 1.57 KB
Versions: 10
Compression:
Stored size: 1.57 KB
Contents
require 'aws' require 'zlib' require 'insxsync' class ConfigFileCollection < ErrorHandlingIface # Collect all the config files present within the given directory and return the object # @param [String] dir The full path if the directory containing the config files. def initialize(dir) failValidation if not dir.is_a?(String) or not (File.exists?(dir) and File.directory?(dir)) @files = Array.new temp = Array.new # get all the subdirectories within the given folder temp = Dir.entries(dir).select{|x| File.directory?(File.join(dir, x)) and not (x =~ /\.\.?/)} # For each one, add the config file if it contains one temp.each do |folder| config_file = File.join(dir, folder, 'config.ini') @files.push(config_file) if File.exists?(config_file) end # if no config files were found, raise an errors raise if @files.count == 0 end # Scrubs and uploads config files to S3 # @param [Time] time the time of the sync point to archive to def archive(time) failValidation if time.nil? or not time.is_a?(Time) bucket = AWS::S3.new(:access_key_id=>$AWS_ID, :secret_access_key=>$AWS_SECRET).buckets[$SYNC_BUCKET] print "Uploading configuration synchronization data...\t\t" @files.each do |file| config = ConfigFile.new(file) subdomain = File.basename(File.dirname(file)) object = "#{time.to_i}/configs/#{subdomain}/config.ini.deflated" data = Zlib::Deflate.deflate(config.scrub) bucket.objects[object].write(data) end puts "Done." end end
Version data entries
10 entries across 10 versions & 1 rubygems