cutting rubocop offenses down to 32

This commit is contained in:
Sean OMeara 2013-11-04 21:37:55 -05:00
parent 4675d7736a
commit b113d5bc48
13 changed files with 151 additions and 149 deletions

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Author:: Joshua Timberman <joshua@opscode.com>
# Copyright:: Copyright (c) 2009, Opscode, Inc.
# License:: Apache License, Version 2.0
@ -16,13 +16,13 @@
# limitations under the License.
# Generic cookbook attributes
default['postfix']['mail_type'] = "client"
default['postfix']['relayhost_role'] = "relayhost"
default['postfix']['mail_type'] = 'client'
default['postfix']['relayhost_role'] = 'relayhost'
default['postfix']['multi_environment_relay'] = false
default['postfix']['use_procmail'] = false
default['postfix']['aliases'] = {}
default['postfix']['main_template_source'] = "postfix"
default['postfix']['master_template_source'] = "postfix"
default['postfix']['main_template_source'] = 'postfix'
default['postfix']['master_template_source'] = 'postfix'
default['postfix']['sender_canonical_map_entries'] = {}
case node['platform']
@ -35,63 +35,63 @@ else
end
# Non-default main.cf attributes
default['postfix']['main']['biff'] = "no"
default['postfix']['main']['append_dot_mydomain'] = "no"
default['postfix']['main']['biff'] = 'no'
default['postfix']['main']['append_dot_mydomain'] = 'no'
default['postfix']['main']['myhostname'] = (node['fqdn'] || node['hostname']).to_s.chomp('.')
default['postfix']['main']['mydomain'] = (node['domain'] || node['hostname']).to_s.chomp('.')
default['postfix']['main']['myorigin'] = "$myhostname"
default['postfix']['main']['mydestination'] = [ node['postfix']['main']['myhostname'], node['hostname'], "localhost.localdomain", "localhost" ].compact
default['postfix']['main']['smtpd_use_tls'] = "yes"
default['postfix']['main']['smtp_use_tls'] = "yes"
default['postfix']['main']['myorigin'] = '$myhostname'
default['postfix']['main']['mydestination'] = [node['postfix']['main']['myhostname'], node['hostname'], 'localhost.localdomain', 'localhost'].compact
default['postfix']['main']['smtpd_use_tls'] = 'yes'
default['postfix']['main']['smtp_use_tls'] = 'yes'
default['postfix']['main']['alias_maps'] = ["hash:#{node['postfix']['aliases_db']}"]
default['postfix']['main']['mailbox_size_limit'] = 0
default['postfix']['main']['recipient_delimiter'] = "+"
default['postfix']['main']['smtp_sasl_auth_enable'] = "no"
default['postfix']['main']['mynetworks'] = "127.0.0.0/8"
default['postfix']['main']['inet_interfaces'] = "loopback-only"
default['postfix']['main']['recipient_delimiter'] = '+'
default['postfix']['main']['smtp_sasl_auth_enable'] = 'no'
default['postfix']['main']['mynetworks'] = '127.0.0.0/8'
default['postfix']['main']['inet_interfaces'] = 'loopback-only'
# Conditional attributes
case node['platform']
when 'smartos'
default['postfix']['main']['smtpd_use_tls'] = "no"
default['postfix']['main']['smtp_use_tls'] = "no"
cafile = "/opt/local/etc/postfix/cacert.pem"
when "rhel"
cafile = "/etc/pki/tls/cert.pem"
default['postfix']['main']['smtpd_use_tls'] = 'no'
default['postfix']['main']['smtp_use_tls'] = 'no'
cafile = '/opt/local/etc/postfix/cacert.pem'
when 'rhel'
cafile = '/etc/pki/tls/cert.pem'
else
cafile = "/etc/postfix/cacert.pem"
cafile = '/etc/postfix/cacert.pem'
end
if node['postfix']['use_procmail']
default['postfix']['main']['mailbox_command'] = '/usr/bin/procmail -a "$EXTENSION"'
end
if node['postfix']['main']['smtpd_use_tls'] == "yes"
default['postfix']['main']['smtpd_tls_cert_file'] = "/etc/ssl/certs/ssl-cert-snakeoil.pem"
default['postfix']['main']['smtpd_tls_key_file'] = "/etc/ssl/private/ssl-cert-snakeoil.key"
if node['postfix']['main']['smtpd_use_tls'] == 'yes'
default['postfix']['main']['smtpd_tls_cert_file'] = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
default['postfix']['main']['smtpd_tls_key_file'] = '/etc/ssl/private/ssl-cert-snakeoil.key'
default['postfix']['main']['smtpd_tls_CAfile'] = cafile
default['postfix']['main']['smtpd_tls_session_cache_database'] = "btree:${data_directory}/smtpd_scache"
default['postfix']['main']['smtpd_tls_session_cache_database'] = 'btree:${data_directory}/smtpd_scache'
end
if node['postfix']['main']['smtp_use_tls'] == "yes"
if node['postfix']['main']['smtp_use_tls'] == 'yes'
default['postfix']['main']['smtp_tls_CAfile'] = cafile
default['postfix']['main']['smtp_tls_session_cache_database'] = "btree:${data_directory}/smtp_scache"
default['postfix']['main']['smtp_tls_session_cache_database'] = 'btree:${data_directory}/smtp_scache'
end
if node['postfix']['main']['smtp_sasl_auth_enable'] == "yes"
if node['postfix']['main']['smtp_sasl_auth_enable'] == 'yes'
default['postfix']['main']['smtp_sasl_password_maps'] = "hash:#{node['postfix']['conf_dir']}/postfix/sasl_passwd"
default['postfix']['main']['smtp_sasl_security_options'] = "noanonymous"
default['postfix']['sasl']['smtp_sasl_user_name'] = ""
default['postfix']['sasl']['smtp_sasl_passwd'] = ""
default['postfix']['main']['relayhost'] = ""
default['postfix']['main']['smtp_sasl_security_options'] = 'noanonymous'
default['postfix']['sasl']['smtp_sasl_user_name'] = ''
default['postfix']['sasl']['smtp_sasl_passwd'] = ''
default['postfix']['main']['relayhost'] = ''
end
# Default main.cf attributes according to `postconf -d`
#default['postfix']['main']['relayhost'] = ""
#default['postfix']['main']['milter_default_action'] = "tempfail"
#default['postfix']['main']['milter_protocol'] = "6"
#default['postfix']['main']['smtpd_milters'] = ""
#default['postfix']['main']['non_smtpd_milters'] = ""
# # Default main.cf attributes according to `postconf -d`
# default['postfix']['main']['relayhost'] = ''
# default['postfix']['main']['milter_default_action'] = 'tempfail'
# default['postfix']['main']['milter_protocol'] = '6'
# default['postfix']['main']['smtpd_milters'] = ''
# default['postfix']['main']['non_smtpd_milters'] = ''
# default['postfix']['main']['sender_canonical_classes'] = nil
# default['postfix']['main']['recipient_canonical_classes'] = nil
# default['postfix']['main']['canonical_classes'] = nil

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -16,11 +16,11 @@
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::aliases" do
describe 'postfix::aliases' do
include Helpers::Postfix
it 'manages /etc/aliases' do
file("/etc/aliases").must_match(/^# This file is generated by Chef for/)
file('/etc/aliases').must_match(/^# This file is generated by Chef for/)
end
end

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -16,9 +16,9 @@
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::client" do
describe 'postfix::client' do
include Helpers::Postfix
it 'doesnt configure postfix because solo is unsupported' do
skip "Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo"
skip 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo'
end
end

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -16,23 +16,23 @@
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::default" do
describe 'postfix::default' do
include Helpers::Postfix
it 'installs the postfix package' do
package("postfix").must_be_installed
package('postfix').must_be_installed
end
it 'enables the postfix service' do
service("postfix").must_be_enabled
service('postfix').must_be_enabled
end
it 'starts the postfix service' do
service("postfix").must_be_running
service('postfix').must_be_running
end
it 'configures postfix main.cf' do
file("/etc/postfix/main.cf").must_match(/^# Generated by Chef for /)
file('/etc/postfix/main.cf').must_match(/^# Generated by Chef for /)
end
end

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -15,11 +15,11 @@
#
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::sasl_auth" do
describe 'postfix::sasl_auth' do
include Helpers::Postfix
it 'manages /etc/postfix/sasl_passwd' do
file("/etc/postfix/sasl_passwd").must_match(/^# This file is generated by Chef for/)
file('/etc/postfix/sasl_passwd').must_match(/^# This file is generated by Chef for/)
end
end

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -15,9 +15,9 @@
#
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::server" do
describe 'postfix::server' do
include Helpers::Postfix
it 'doesnt configure postfix because solo is unsupported' do
skip "Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo"
skip 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo'
end
end

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -14,11 +14,12 @@
# limitations under the License.
#
# helpers
module Helpers
# postfix
module Postfix
include MiniTest::Chef::Assertions
include MiniTest::Chef::Context
include MiniTest::Chef::Resources
end
end

View File

@ -1,50 +1,51 @@
name "postfix"
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs and configures postfix for client or outbound relayhost, or to do SASL auth"
version "3.0.3"
recipe "postfix", "Installs and configures postfix"
recipe "postfix::sasl_auth", "Set up postfix to auth to a server with sasl"
recipe "postfix::aliases", "Manages /etc/aliases"
recipe "postfix::client", "Searches for the relayhost based on an attribute"
recipe "postfix::server", "Sets the mail_type attribute to master"
# encoding: utf-8
name 'postfix'
description 'Installs and configures postfix for client or outbound relayhost, or to do SASL auth'
maintainer 'Opscode, Inc.'
maintainer_email 'cookbooks@opscode.com'
license 'Apache 2.0'
version '3.0.3'
recipe 'postfix', 'Installs and configures postfix'
recipe 'postfix::sasl_auth', 'Set up postfix to auth to a server with sasl'
recipe 'postfix::aliases', 'Manages /etc/aliases'
recipe 'postfix::client', 'Searches for the relayhost based on an attribute'
recipe 'postfix::server', 'Sets the mail_type attribute to master'
%w{ubuntu debian redhat centos amazon scientific smartos}.each do |os|
supports os
end
attribute "postfix/main",
:display_name => "postfix/main",
:description => "Hash of Postfix main.cf attributes",
:type => "hash"
attribute 'postfix/main',
display_name: 'postfix/main',
description: 'Hash of Postfix main.cf attributes',
type: 'hash'
attribute "postfix/aliases",
:display_name => "Postfix Aliases",
:description => "Hash of Postfix aliases mapping a name to a value. Example 'root' => 'operator@example.com'. See aliases man page for details.",
:type => "hash"
attribute 'postfix/aliases',
display_name: 'Postfix Aliases',
description: "Hash of Postfix aliases mapping a name to a value. Example 'root' => 'operator@example.com'. See aliases man page for details.",
type: 'hash'
attribute "postfix/mail_type",
:display_name => "Postfix Mail Type",
:description => "Is this node a client or server?",
:default => "client"
attribute 'postfix/mail_type',
display_name: 'Postfix Mail Type',
description: 'Is this node a client or server?',
default: 'client'
attribute "postfix/smtp_sasl_user_name",
:display_name => "Postfix SMTP SASL Username",
:description => "User to auth SMTP via SASL",
:default => ""
attribute 'postfix/smtp_sasl_user_name',
display_name: 'Postfix SMTP SASL Username',
description: 'User to auth SMTP via SASL',
default: ''
attribute "postfix/smtp_sasl_passwd",
:display_name => "Postfix SMTP SASL Password",
:description => "Password for smtp_sasl_user_name",
:default => ""
attribute 'postfix/smtp_sasl_passwd',
display_name: 'Postfix SMTP SASL Password',
description: 'Password for smtp_sasl_user_name',
default: ''
attribute "postfix/relayhost_role",
:display_name => "Postfix Relayhost's role",
:description => "String containing the role name",
:default => "relayhost"
attribute 'postfix/relayhost_role',
display_name: "Postfix Relayhost's role",
description: 'String containing the role name',
default: 'relayhost'
attribute "postfix/use_procmail",
:display_name => "Postfix Use procmail?",
:description => "Whether procmail should be used as the local delivery agent for a server",
:default => "no"
attribute 'postfix/use_procmail',
display_name: 'Postfix Use procmail?',
description: 'Whether procmail should be used as the local delivery agent for a server',
default: 'no'

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Copyright:: Copyright (c) 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -14,14 +14,14 @@
# limitations under the License.
#
include_recipe "postfix"
include_recipe 'postfix'
execute "update-postfix-aliases" do
command "newaliases"
execute 'update-postfix-aliases' do
command 'newaliases'
action :nothing
end
template node['postfix']['aliases_db'] do
source "aliases.erb"
notifies :run, "execute[update-postfix-aliases]"
source 'aliases.erb'
notifies :run, 'execute[update-postfix-aliases]'
end

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Author:: Joshua Timberman(<joshua@opscode.com>)
# Cookbook Name:: postfix
# Recipe:: client
@ -24,7 +24,7 @@ if Chef::Config[:solo]
end
query = "role:#{node['postfix']['relayhost_role']}"
relayhost = ""
relayhost = ''
results = []
if node.run_list.roles.include?(node['postfix']['relayhost_role'])
@ -39,4 +39,4 @@ end
node.set['postfix']['main']['relayhost'] = "[#{relayhost}]"
include_recipe "postfix"
include_recipe 'postfix'

View File

@ -1,4 +1,4 @@
#
# encoding: utf-8
# Author:: Joshua Timberman(<joshua@opscode.com>)
# Cookbook Name:: postfix
# Recipe:: default
@ -18,35 +18,35 @@
# limitations under the License.
#
package "postfix"
package 'postfix'
if node['postfix']['use_procmail']
package "procmail"
package 'procmail'
end
case node['platform_family']
when "rhel", "fedora"
service "sendmail" do
when 'rhel', 'fedora'
service 'sendmail' do
action :nothing
end
execute "switch_mailer_to_postfix" do
command "/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix"
notifies :stop, "service[sendmail]"
notifies :start, "service[postfix]"
not_if "/usr/bin/test /etc/alternatives/mta -ef /usr/sbin/sendmail.postfix"
execute 'switch_mailer_to_postfix' do
command '/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix'
notifies :stop, 'service[sendmail]'
notifies :start, 'service[postfix]'
not_if '/usr/bin/test /etc/alternatives/mta -ef /usr/sbin/sendmail.postfix'
end
end
if !node['postfix']['sender_canonical_map_entries'].empty?
template "#{node['postfix']['conf_dir']}/sender_canonical" do
owner "root"
owner 'root'
group 0
mode '0644'
notifies :restart, "service[postfix]"
notifies :restart, 'service[postfix]'
end
if !node['postfix']['main'].has_key?('sender_canonical_maps')
if !node['postfix']['main'].key?('sender_canonical_maps')
node.set['postfix']['main']['sender_canonical_maps'] = "hash:#{node['postfix']['conf_dir']}/sender_canonical"
end
end
@ -54,16 +54,16 @@ end
%w{main master}.each do |cfg|
template "#{node['postfix']['conf_dir']}/#{cfg}.cf" do
source "#{cfg}.cf.erb"
owner "root"
owner 'root'
group 0
mode 00644
notifies :restart, "service[postfix]"
variables(:settings => node['postfix'][cfg])
notifies :restart, 'service[postfix]'
variables(settings: node['postfix'][cfg])
cookbook node['postfix']["#{cfg}_template_source"]
end
end
service "postfix" do
supports :status => true, :restart => true, :reload => true
service 'postfix' do
supports status: true, restart: true, reload: true
action [:enable, :start]
end

View File

@ -1,3 +1,4 @@
# encoding: utf-8
#
# Author:: Joshua Timberman(<joshua@opscode.com>)
# Cookbook Name:: postfix
@ -18,42 +19,40 @@
# limitations under the License.
#
include_recipe "postfix"
include_recipe 'postfix'
sasl_pkgs = []
# We use case instead of value_for_platform_family because we need
# version specifics for RHEL.
case node['platform_family']
when "debian"
when 'debian'
sasl_pkgs = %w{libsasl2-2 libsasl2-modules ca-certificates}
when "rhel"
when 'rhel'
if node['platform_version'].to_i < 6
sasl_pkgs = %w{cyrus-sasl cyrus-sasl-plain openssl}
else
sasl_pkgs = %w{cyrus-sasl cyrus-sasl-plain ca-certificates}
end
when "fedora"
when 'fedora'
sasl_pkgs = %w{cyrus-sasl cyrus-sasl-plain ca-certificates}
end
sasl_pkgs.each do |pkg|
package pkg
end
execute "postmap-sasl_passwd" do
command "postmap /etc/postfix/sasl_passwd"
execute 'postmap-sasl_passwd' do
command 'postmap /etc/postfix/sasl_passwd'
action :nothing
end
template "/etc/postfix/sasl_passwd" do
source "sasl_passwd.erb"
owner "root"
group "root"
template '/etc/postfix/sasl_passwd' do
source 'sasl_passwd.erb'
owner 'root'
group 'root'
mode 0400
notifies :run, "execute[postmap-sasl_passwd]", :immediately
notifies :restart, "service[postfix]"
variables(:settings => node['postfix']['sasl'])
notifies :run, 'execute[postmap-sasl_passwd]', :immediately
notifies :restart, 'service[postfix]'
variables(settings: node['postfix']['sasl'])
end

View File

@ -1,3 +1,4 @@
# encoding: utf-8
#
# Author:: Joshua Timberman(<joshua@opscode.com>)
# Cookbook Name:: postfix
@ -21,4 +22,4 @@
node.override['postfix']['mail_type'] = 'master'
node.override['postfix']['main']['inet_interfaces'] = 'all'
include_recipe "postfix"
include_recipe 'postfix'