Module: Certman::Resource::SES

Included in:
Client
Defined in:
lib/certman/resource/ses.rb

Constant Summary collapse

REGIONS =
%w(us-east-1 us-west-2 eu-west-1)
RULE_SET_NAME_BY_CERTMAN =
'RuleSetByCertman'

Instance Method Summary collapse

Instance Method Details

#active_rule_set_exist?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/certman/resource/ses.rb', line 17

def active_rule_set_exist?
  @current_active_rule_set_name = nil
  res = ses.describe_active_receipt_rule_set
  @current_active_rule_set_name = res..name if res.
end

#check_domain_identity_verifiedObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/certman/resource/ses.rb', line 23

def check_domain_identity_verified
  is_break = false
  100.times do
    res = ses.get_identity_verification_attributes(
      identities: [
        email_domain
      ]
    )
    if res.verification_attributes[email_domain].verification_status == 'Success'
      # success
      is_break = true
      break
    end
    break if @do_rollback
    sleep 5
  end
  raise 'Can not check verified' unless is_break
end

#create_and_active_rule_setObject



46
47
48
49
# File 'lib/certman/resource/ses.rb', line 46

def create_and_active_rule_set
  ses.create_receipt_rule_set(rule_set_name: rule_set_name)
  ses.set_active_receipt_rule_set(rule_set_name: rule_set_name)
end

#create_domain_identityObject



12
13
14
15
# File 'lib/certman/resource/ses.rb', line 12

def create_domain_identity
  res = ses.verify_domain_identity(domain: email_domain)
  @token = res.verification_token
end

#create_ruleObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/certman/resource/ses.rb', line 51

def create_rule
  ses.create_receipt_rule(
    rule: {
      recipients: ["admin@#{email_domain}"],
      actions: [
        {
          s3_action: {
            bucket_name: bucket_name
          }
        }
      ],
      enabled: true,
      name: rule_name,
      scan_enabled: true,
      tls_policy: 'Optional'
    },
    rule_set_name: rule_set_name
  )
end

#delete_domain_identityObject



42
43
44
# File 'lib/certman/resource/ses.rb', line 42

def delete_domain_identity
  ses.delete_identity(identity: email_domain)
end

#delete_ruleObject



83
84
85
86
87
88
# File 'lib/certman/resource/ses.rb', line 83

def delete_rule
  ses.delete_receipt_rule(
    rule_name: rule_name,
    rule_set_name: rule_set_name
  )
end

#delete_rule_setObject



76
77
78
79
80
81
# File 'lib/certman/resource/ses.rb', line 76

def delete_rule_set
  res = ses.describe_active_receipt_rule_set
  return if res.rules && res.rules.length > 1
  ses.set_active_receipt_rule_set(rule_set_name: nil)
  ses.delete_receipt_rule_set(rule_set_name: rule_set_name)
end

#region_by_hashObject



7
8
9
10
# File 'lib/certman/resource/ses.rb', line 7

def region_by_hash
  key = Digest::SHA1.hexdigest(@domain).to_i(16) % REGIONS.length
  REGIONS[key]
end

#rule_exist?Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/certman/resource/ses.rb', line 71

def rule_exist?
  res = ses.describe_active_receipt_rule_set
  res.rules && !res.rules.empty?
end

#sesObject



90
91
92
# File 'lib/certman/resource/ses.rb', line 90

def ses
  @ses ||= Aws::SES::Client.new
end