Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Allow use of different AWS regions using an atttribute #2

Merged
merged 2 commits into from
Oct 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
site :opscode
source "https://supermarket.chef.io"

metadata
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sendmail-ses cookbook

Integrates sendmail with Amazon SES. This cookbooks duplicates this [doc](http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sendmail.html) except rather than adding the configurations directly to the sendmail.mc file. It is included as a seperate file.
Integrates sendmail with Amazon SES. This cookbooks duplicates this [doc](http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sendmail.html) except rather than adding the configurations directly to the sendmail.mc file. It is included as a separate file.

# Requirements

Expand All @@ -20,6 +20,7 @@ Populate the sendmail attribute and include the default recipe `recipe[sendmail-
* `port` tcp port. Default is 25
* `test_user` SES verified user to send from. IE <test_user>@<domain>
* `test_email` Send a test email to the given address.
* `aws_region` the AWS region to use - default is us-east-1

# Recipes

Expand Down
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default['sendmail_ses']['port']=25
default['sendmail_ses']['aws_region']='us-east-1'
18 changes: 10 additions & 8 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
source 'authinfo.ses.erb'
variables(
:username => node[:sendmail_ses][:username],
:password => node[:sendmail_ses][:password]
:password => node[:sendmail_ses][:password],
:aws_region => node[:sendmail_ses][:aws_region]
)
notifies :run, 'execute[add_ses_authinfo]', :immediately
end
Expand All @@ -37,11 +38,11 @@
action :nothing
end

file '/etc/mail/access.ses' do
content <<-CMD
Connect:email-smtp.us-east-1.amazonaws.com RELAY
Connect:ses-smtp-prod-335357831.us-east-1.elb.amazonaws.com RELAY
CMD
template '/etc/mail/access.ses' do
source 'access.ses.erb'
variables(
:aws_region => node[:sendmail_ses][:aws_region]
)
notifies :run, 'execute[add_ses_access]', :immediately
end

Expand Down Expand Up @@ -69,7 +70,8 @@
source 'ses.cf.erb'
variables(
:port => node[:sendmail_ses][:port] || '25',
:domain => node[:sendmail_ses][:domain]
:domain => node[:sendmail_ses][:domain],
:aws_region => node[:sendmail_ses][:aws_region]
)
notifies :run, 'ruby_block[add_include_to_sendmail_mc]'
end
Expand Down Expand Up @@ -101,4 +103,4 @@
only_if { node[:sendmail_ses][:test_user] }
only_if { node[:sendmail_ses][:test_email] }
end
end
end
6 changes: 3 additions & 3 deletions spec/defaul_spec.rb → spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

it 'create access.ses with content' do
expect(@chef_run).to create_file('/etc/mail/access.ses')
expect(@chef_run).to create_template('/etc/mail/access.ses')
expect(@chef_run).to render_file('/etc/mail/access.ses').with_content(<<-CMD
Connect:email-smtp.us-east-1.amazonaws.com RELAY
Connect:ses-smtp-prod-335357831.us-east-1.elb.amazonaws.com RELAY
Expand All @@ -50,8 +50,8 @@
end

it 'template access.ses should notify add_ses_access' do
f = @chef_run.file('/etc/mail/access.ses')
expect(f).to notify('execute[add_ses_access]')
t = @chef_run.template('/etc/mail/access.ses')
expect(t).to notify('execute[add_ses_access]')
end

it 'should create ses directory' do
Expand Down
2 changes: 2 additions & 0 deletions templates/default/access.ses.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Connect:email-smtp.<%= @aws_region %>.amazonaws.com RELAY
Connect:ses-smtp-prod-335357831.<%= @aws_region %>.elb.amazonaws.com RELAY
4 changes: 2 additions & 2 deletions templates/default/authinfo.ses.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AuthInfo:email-smtp.us-east-1.amazonaws.com "U:root" "I:<%= @username %>" "P:<%= @password %>" "M:LOGIN"
AuthInfo:ses-smtp-prod-335357831.us-east-1.elb.amazonaws.com "U:root" "I:<%= @username %>" "P:<%= @password %>" "M:LOGIN"
AuthInfo:email-smtp.<%= @aws_region %>.amazonaws.com "U:root" "I:<%= @username %>" "P:<%= @password %>" "M:LOGIN"
AuthInfo:ses-smtp-prod-335357831.<%= @aws_region %>.elb.amazonaws.com "U:root" "I:<%= @username %>" "P:<%= @password %>" "M:LOGIN"
4 changes: 2 additions & 2 deletions templates/default/ses.cf.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dnl #
dnl # Amazon SES integration
dnl #
define(`SMART_HOST', `email-smtp.us-east-1.amazonaws.com')dnl
define(`SMART_HOST', `email-smtp.<%= @aws_region %>.amazonaws.com')dnl
define(`RELAY_MAILER_ARGS', `TCP $h <%= @port %>')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl
FEATURE(`authinfo', `hash -o /etc/mail/authinfo.db')dnl
Expand All @@ -10,4 +10,4 @@ FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
dnl #
dnl # End Amazon SES integration
dnl #
dnl #