Class: Automan::Beanstalk::Uploader

Inherits:
Automan::Base show all
Defined in:
lib/automan/beanstalk/uploader.rb

Constant Summary

Constants included from Mixins::AwsCaller

Mixins::AwsCaller::S3_PROTO

Instance Attribute Summary

Attributes inherited from Automan::Base

#logger, #wait

Attributes included from Mixins::AwsCaller

#as, #cfn, #eb, #ec, #ec2, #elb, #r53, #rds, #s3

Instance Method Summary collapse

Methods inherited from Automan::Base

add_option, #initialize, #log_options, #wait_until

Methods included from Mixins::AwsCaller

#account, #configure_aws, #looks_like_s3_path?, #parse_s3_path, #s3_object_exists?, #s3_read

Constructor Details

This class inherits a constructor from Automan::Base

Instance Method Details

#config_templatesObject



8
9
10
# File 'lib/automan/beanstalk/uploader.rb', line 8

def config_templates
  Dir.glob template_files
end

#config_templates_valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/automan/beanstalk/uploader.rb', line 16

def config_templates_valid?
  valid = true
  templates = config_templates

  if templates.empty?
    raise NoConfigurationTemplatesError, "No configuration template files found for #{template_files}"
  end

  templates.each do |template|
    raw = read_config_template template
    begin
      JSON.parse(raw)
    rescue Exception => e
      logger.warn "#{template} is invalid json: #{e.message}"
      valid = false
      next
    end
    logger.debug "#{template} is valid json"
  end

  valid
end

#read_config_template(file) ⇒ Object



12
13
14
# File 'lib/automan/beanstalk/uploader.rb', line 12

def read_config_template(file)
  File.read file
end

#upload_config_templatesObject



48
49
50
51
52
53
54
55
56
# File 'lib/automan/beanstalk/uploader.rb', line 48

def upload_config_templates
  unless config_templates_valid?
    raise InvalidConfigurationTemplateError, "There are invalid configuration templates. Halting upload."
  end

  config_templates.each do |template|
    upload_file(template)
  end
end

#upload_file(file) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/automan/beanstalk/uploader.rb', line 39

def upload_file(file)
  opts = {
    localfile: file,
    s3file:    "#{s3_path}/#{File.basename(file)}"
  }
  s = Automan::S3::Uploader.new opts
  s.upload
end