lib/heirloom/cli/shared.rb in heirloom-0.5.0rc4 vs lib/heirloom/cli/shared.rb in heirloom-0.6.0rc1

- old
+ new

@@ -4,12 +4,13 @@ def load_config(args) opts = args[:opts] logger = args[:logger] config = Config.new :logger => logger - config.access_key = opts[:aws_access_key] if opts[:aws_access_key_given] - config.secret_key = opts[:aws_secret_key] if opts[:aws_secret_key_given] + config.access_key = opts[:aws_access_key] if opts[:aws_access_key] + config.secret_key = opts[:aws_secret_key] if opts[:aws_secret_key] + config.metadata_region = opts[:metadata_region] if opts[:metadata_region] config end def ensure_valid_secret(args) config = args[:config] @@ -43,10 +44,45 @@ missing_opts.each {|missing_opt| logger.error missing_opt} exit 1 unless missing_opts.empty? end + def ensure_valid_regions(args) + regions = args[:regions] + config = args[:config] + regions.each do |region| + ensure_valid_region :region => region, + :config => config + end + end + + def ensure_valid_region(args) + config = args[:config] + region = args[:region] + logger = config.logger + valid_regions = ['us-east-1', 'us-west-1', 'us-west-2'] + + unless valid_regions.include? region + logger.error "'#{region}' is not a valid region." + logger.error "Valid regions: #{valid_regions.join(', ')}" + exit 1 + end + end + + def ensure_metadata_in_upload_region(args) + config = args[:config] + regions = args[:regions] + logger = config.logger + + unless regions.include? config.metadata_region + logger.error "Upload Regions: '#{regions.join(', ')}'." + logger.error "Metadata Region: '#{config.metadata_region}'." + logger.error "Upload regions must include metadata region." + exit 1 + end + end + def ensure_directory(args) config = args[:config] path = args[:path] logger = config.logger @@ -54,19 +90,49 @@ logger.error "#{path} is not a directory." exit 1 end end + def ensure_buckets_exist(args) + config = args[:config] + base = args[:base] + name = args[:name] + regions = args[:regions] + logger = config.logger + + archive = Archive.new :name => name, + :config => config + + unless archive.buckets_exist? :regions => regions, + :bucket_prefix => base + logger.error "Required buckets for '#{base}' do not exist." + logger.error "Run 'heirloom setup -h' for help setting up new region." + exit 1 + end + end + def ensure_domain_exists(args) config = args[:config] - name = args[:name] + name = args[:name] logger = config.logger archive = Archive.new :name => name, :config => config unless archive.domain_exists? - logger.error "Heirloom domain does not exist." + logger.error "Metadata domain '#{name}' does not exist in '#{config.metadata_region}'." + logger.error "Run 'heirloom setup -h' for help setting up new region." + exit 1 + end + end + + def ensure_archive_exists(args) + config = args[:config] + archive = args[:archive] + logger = config.logger + + unless archive.exists? + logger.error "Archive does not exist." exit 1 end end end