Module: Heirloom::CLI::Shared
- Included in:
- Authorize, Catalog, Cleanup, Destroy, Download, List, Rotate, Setup, Show, Tag, Teardown, Upload
- Defined in:
- lib/heirloom/cli/shared.rb
Instance Method Summary collapse
- #ensure_archive_domain_empty(args) ⇒ Object
- #ensure_archive_exists(args) ⇒ Object
- #ensure_buckets_available(args) ⇒ Object
- #ensure_buckets_exist(args) ⇒ Object
- #ensure_catalog_domain_exists(args) ⇒ Object
- #ensure_directory_is_writable(args) ⇒ Object
- #ensure_domain_exists(args) ⇒ Object
- #ensure_entry_does_not_exist_in_catalog(args) ⇒ Object
- #ensure_entry_exists_in_catalog(args) ⇒ Object
- #ensure_metadata_in_upload_region(args) ⇒ Object
- #ensure_path_is_directory(args) ⇒ Object
- #ensure_valid_bucket_prefix(args) ⇒ Object
- #ensure_valid_name(args) ⇒ Object
- #ensure_valid_options(args) ⇒ Object
- #ensure_valid_region(args) ⇒ Object
- #ensure_valid_regions(args) ⇒ Object
- #ensure_valid_secret(args) ⇒ Object
- #latest_id(args) ⇒ Object
- #load_config(args) ⇒ Object
- #read_secret(args) ⇒ Object
Instance Method Details
#ensure_archive_domain_empty(args) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/heirloom/cli/shared.rb', line 156 def ensure_archive_domain_empty(args) config = args[:config] archive = args[:archive] logger = config.logger unless archive.count.zero? logger.error "Not empty." exit 1 end end |
#ensure_archive_exists(args) ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/heirloom/cli/shared.rb', line 145 def ensure_archive_exists(args) archive = args[:archive] config = args[:config] logger = config.logger unless archive.exists? logger.error "Archive does not exist." exit 1 end end |
#ensure_buckets_available(args) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/heirloom/cli/shared.rb', line 195 def ensure_buckets_available(args) config = args[:config] regions = args[:regions] bucket_prefix = args[:bucket_prefix] logger = config.logger checker = Heirloom::Checker.new :config => config available = checker.bucket_name_available? :bucket_prefix => bucket_prefix, :regions => regions, :config => config if available true else logger.error "Bucket prefix #{bucket_prefix} not available across regions #{regions.join}." exit 1 end end |
#ensure_buckets_exist(args) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/heirloom/cli/shared.rb', line 114 def ensure_buckets_exist(args) config = args[:config] bucket_prefix = args[:bucket_prefix] name = args[:name] regions = args[:regions] logger = config.logger archive = Archive.new :name => name, :config => config unless archive.buckets_exist? :regions => regions, :bucket_prefix => bucket_prefix logger.error "Required buckets for '#{bucket_prefix}' do not exist." exit 1 end end |
#ensure_catalog_domain_exists(args) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/heirloom/cli/shared.rb', line 167 def ensure_catalog_domain_exists(args) config = args[:config] catalog = args[:catalog] continue_on_error = args[:continue_on_error] logger = config.logger region = config. unless catalog.catalog_domain_exists? return false if continue_on_error logger.error "Catalog does not exist in #{region}." exit 1 end true end |
#ensure_directory_is_writable(args) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/heirloom/cli/shared.rb', line 103 def ensure_directory_is_writable(args) config = args[:config] path = args[:path] logger = config.logger unless File.writable? path logger.error "You don't have permissions to write to #{path}." exit 1 end end |
#ensure_domain_exists(args) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/heirloom/cli/shared.rb', line 131 def ensure_domain_exists(args) config = args[:config] name = args[:name] logger = config.logger archive = Archive.new :name => name, :config => config unless archive.domain_exists? logger.error "'#{name}' metadata domain does not exist in '#{config.}'." exit 1 end end |
#ensure_entry_does_not_exist_in_catalog(args) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/heirloom/cli/shared.rb', line 214 def ensure_entry_does_not_exist_in_catalog(args) config = args[:config] catalog = args[:catalog] entry = args[:entry] force = args[:force] logger = config.logger region = config. if catalog.entry_exists_in_catalog?(entry) && !force logger.error "Entry #{entry} exists in catalog. Use --force to overwrite." exit 1 end end |
#ensure_entry_exists_in_catalog(args) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/heirloom/cli/shared.rb', line 182 def ensure_entry_exists_in_catalog(args) config = args[:config] catalog = args[:catalog] entry = args[:entry] logger = config.logger region = config. unless catalog.entry_exists_in_catalog? entry logger.error "Entry for #{entry} does not exist in #{region} catalog." exit 1 end end |
#ensure_metadata_in_upload_region(args) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/heirloom/cli/shared.rb', line 79 def (args) config = args[:config] regions = args[:regions] logger = config.logger unless regions.include? config. logger.error "Upload Regions: '#{regions.join(', ')}'." logger.error "Metadata Region: '#{config.}'." logger.error "Upload regions must include metadata region." exit 1 end end |
#ensure_path_is_directory(args) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/heirloom/cli/shared.rb', line 92 def ensure_path_is_directory(args) config = args[:config] path = args[:path] logger = config.logger unless File.directory? path logger.error "#{path} is not a directory." exit 1 end end |
#ensure_valid_bucket_prefix(args) ⇒ Object
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/heirloom/cli/shared.rb', line 238 def ensure_valid_bucket_prefix(args) config = args[:config] bucket_prefix = args[:bucket_prefix] logger = config.logger unless bucket_prefix =~ /^[0-9a-z\-]+$/ logger.error "Invalid bucket prefix '#{bucket_prefix}'. Can only contain lower case letters, numbers and dashes." exit 1 end end |
#ensure_valid_name(args) ⇒ Object
228 229 230 231 232 233 234 235 236 |
# File 'lib/heirloom/cli/shared.rb', line 228 def ensure_valid_name(args) config = args[:config] name = args[:name] logger = config.logger unless name =~ /^[0-9a-z\-\_]+$/ logger.error "Invalid name '#{name}'. Can only contain lower case letters, numbers, dashes and underscores." exit 1 end end |
#ensure_valid_options(args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/heirloom/cli/shared.rb', line 31 def (args) provided = args[:provided] required = args[:required] config = args[:config] logger = config.logger unless config.use_iam_profile required << :aws_access_key unless config.access_key required << :aws_secret_key unless config.secret_key end missing_opts = required.sort.map do |opt| case provided[opt] when nil, [] pretty_opt = opt.to_s.gsub('_', '-') "Option '#{pretty_opt}' required but not specified." end end missing_opts.compact! missing_opts.each {|missing_opt| logger.error missing_opt} exit 1 unless missing_opts.empty? end |
#ensure_valid_region(args) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/heirloom/cli/shared.rb', line 66 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 |
#ensure_valid_regions(args) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/heirloom/cli/shared.rb', line 57 def ensure_valid_regions(args) regions = args[:regions] config = args[:config] regions.each do |region| ensure_valid_region :region => region, :config => config end end |
#ensure_valid_secret(args) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/heirloom/cli/shared.rb', line 21 def ensure_valid_secret(args) config = args[:config] secret = args[:secret] logger = config.logger if secret && secret.length < 8 logger.error "Secret must be at least 8 characters long." exit 1 end end |
#latest_id(args) ⇒ Object
249 250 251 252 253 |
# File 'lib/heirloom/cli/shared.rb', line 249 def latest_id(args) archive = Archive.new :name => args[:name], :config => args[:config] archive.list(1).first end |
#load_config(args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/heirloom/cli/shared.rb', line 5 def load_config(args) opts = args[:opts] logger = args[:logger] config = Config.new :logger => logger, :environment => opts[:environment] 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. = opts[:metadata_region] if opts[:metadata_region] config.use_iam_profile = opts[:use_iam_profile] if opts[:use_iam_profile] if config.proxy logger.debug "Using proxy #{config.proxy} from https_proxy environment variable." else logger.debug "Proxy environment variable https_proxy not set." end config end |
#read_secret(args) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/heirloom/cli/shared.rb', line 255 def read_secret(args) opts = args[:opts] config = args[:config] logger = config.logger return nil unless opts[:secret] || opts[:secret_file] return opts[:secret] if opts[:secret] unless File.exists? opts[:secret_file] logger.error "Unable to read #{opts[:secret_file]}." exit 1 end (File.read opts[:secret_file]).chomp end |