Class: Shoryuken::AwsConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/shoryuken/aws_config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject



7
8
9
# File 'lib/shoryuken/aws_config.rb', line 7

def options
  @options ||= {}
end

Class Method Details

.setup(hash) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shoryuken/aws_config.rb', line 11

def setup(hash)
  # aws-sdk tries to load the credentials from the ENV variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  # when not explicit supplied
  return if hash.empty?

  self.options = hash

  shoryuken_keys = %w(
    account_id
    sns_endpoint
    sqs_endpoint
    receive_message
  ).map(&:to_sym)

  @aws_options = hash.reject do |k, _|
    shoryuken_keys.include?(k)
  end

  # assume credentials based authentication
  credentials = Aws::Credentials.new(
    @aws_options.delete(:access_key_id),
    @aws_options.delete(:secret_access_key)
  )

  # but only if the configuration options have valid values
  @aws_options.merge!(credentials: credentials) if credentials.set?

  if (callback = Shoryuken.aws_initialization_callback)
    Shoryuken.logger.info { 'Calling Shoryuken.on_aws_initialization block' }
    callback.call(@aws_options)
  end
end

.snsObject



44
45
46
# File 'lib/shoryuken/aws_config.rb', line 44

def sns
  Aws::SNS::Client.new(aws_client_options(:sns_endpoint))
end

.sqsObject



48
49
50
# File 'lib/shoryuken/aws_config.rb', line 48

def sqs
  Aws::SQS::Client.new(aws_client_options(:sqs_endpoint))
end