Class: Sessel::ReceiptRuleCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/sessel/receipt_rule_creator.rb

Overview

Takes care of creating the receipt rule and making sure all the prerequisites are in place

Instance Method Summary collapse

Constructor Details

#initialize(receipt_rule) ⇒ ReceiptRuleCreator

Returns a new instance of ReceiptRuleCreator.



8
9
10
11
12
13
14
# File 'lib/sessel/receipt_rule_creator.rb', line 8

def initialize(receipt_rule)
  @receipt_rule = receipt_rule
  @s3 = Aws::S3::Client.new(region: receipt_rule.region)
  @sts = Aws::STS::Client.new(region: receipt_rule.region)
  @ses = Aws::SES::Client.new(region: receipt_rule.region)
  @route53 = Aws::Route53::Client.new(region: receipt_rule.region)
end

Instance Method Details

#createObject

Creates the receipt rule in SES accorind to the paramteres passed when the object was initialised



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sessel/receipt_rule_creator.rb', line 21

def create()

  ensure_prerequsites

  rule = {
      rule: {
          recipients: @receipt_rule.email_addresses,
          actions: [
              {
                  s3_action: {
                      bucket_name: @receipt_rule.s3_bucket,
                      object_key_prefix: @receipt_rule.object_key_prefix,
                  },
              },
          ],
          enabled: true,
          name: @receipt_rule.rule_name,
          scan_enabled: false,
          tls_policy: 'Optional',
      },
      rule_set_name: @receipt_rule.rule_set_name,
  }
  begin
    @ses.create_receipt_rule(rule)
  rescue Aws::SES::Errors::AlreadyExists
    @ses.update_receipt_rule(rule)
  end
end

#receipt_ruleObject



16
17
18
# File 'lib/sessel/receipt_rule_creator.rb', line 16

def receipt_rule
  return @receipt_rule
end