Class: Capriza::AWS::S3Connect

Inherits:
Object
  • Object
show all
Defined in:
lib/capriza-aws-helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ S3Connect

Returns a new instance of S3Connect.



13
14
15
16
17
# File 'lib/capriza-aws-helper.rb', line 13

def initialize (config)
  @config = config
  self.validate
  ::AWS.config(@config)
end

Instance Method Details

#read_config_file(config_file) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/capriza-aws-helper.rb', line 39

def read_config_file(config_file)
  case File.extname(config_file)
    when '.yaml'
      @config = YAML.load(File.read(config_file))
    when '.json'
      @config = JSON.load(File.read(config_file))
    else
      raise "Unrecognized file extension. Currently only support json and yaml"
  end
end

#validateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/capriza-aws-helper.rb', line 19

def validate
  if @config.kind_of?(String) and File.exist?(config_file)
    if File.exist?(config_file)
      self.read_config_file(@config)
    else
      raise "Config file #{config_file} not found"
    end
  elsif @config.kind_of?(Hash)
    puts @config
    unless @config.has_key?('access_key_id') and @config.has_key?('secret_access_key') and @config.has_key?('s3_endpoint')
      raise "Configuration missing. need the following " +
                "access_key_id: YOUR_ACCESS_KEY_ID " +
                "secret_access_key: YOUR_SECRET_ACCESS_KEY " +
                "s3_endpoint: YOUR_S3_ENDPOINT "
    end
  else
    raise("Unrecognized Format. Config can be an filename or Hash.")
  end
end