Module: Common

Defined in:
lib/sensu-plugins-http/common.rb

Instance Method Summary collapse

Instance Method Details

#aws_configObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sensu-plugins-http/common.rb', line 9

def aws_config
  if config[:aws_access_key_id] && config[:aws_secret_access_key]
    Aws.config.update(
      credentials: Aws::Credentials.new(config[:aws_access_key_id], config[:aws_secret_access_key])
    )
  end

  Aws.config.update(
    region: config[:aws_region]
  )
end

#initializeObject



4
5
6
7
# File 'lib/sensu-plugins-http/common.rb', line 4

def initialize
  super()
  aws_config
end

#merge_s3_configObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sensu-plugins-http/common.rb', line 21

def merge_s3_config
  return if config[:s3_config_bucket].nil? || config[:s3_config_key].nil?

  aws_config

  s3 = Aws::S3::Client.new
  begin
    resp = s3.get_object(bucket: config[:s3_config_bucket], key: config[:s3_config_key])
    s3_config = JSON.parse(resp.body.read, symbolize_names: true)
    config.merge!(s3_config)
  rescue StandardError
    critical 'Error getting config file from s3'
  end
end