From b113d5bc485fbb51023f7ddf8fc4daf1d6061bea Mon Sep 17 00:00:00 2001 From: Sean OMeara Date: Mon, 4 Nov 2013 21:37:55 -0500 Subject: [PATCH] cutting rubocop offenses down to 32 --- attributes/default.rb | 90 +++++++++--------- files/default/tests/minitest/aliases_test.rb | 6 +- files/default/tests/minitest/client_test.rb | 6 +- files/default/tests/minitest/default_test.rb | 12 +-- .../default/tests/minitest/sasl_auth_test.rb | 6 +- files/default/tests/minitest/server_test.rb | 6 +- .../default/tests/minitest/support/helpers.rb | 5 +- metadata.rb | 91 ++++++++++--------- recipes/aliases.rb | 12 +-- recipes/client.rb | 10 +- recipes/default.rb | 36 ++++---- recipes/sasl_auth.rb | 29 +++--- recipes/server.rb | 3 +- 13 files changed, 157 insertions(+), 155 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 7851fe51..1473d754 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,4 +1,4 @@ -# +# encoding: utf-8 # Author:: Joshua Timberman # 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,69 +35,69 @@ 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']['alias_maps'] = [ "hash:#{node['postfix']['aliases_db']}" ] +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['postfix']['main']['sender_canonical_classes'] = nil -#default['postfix']['main']['recipient_canonical_classes'] = nil -#default['postfix']['main']['canonical_classes'] = nil -#default['postfix']['main']['sender_canonical_maps'] = nil -#default['postfix']['main']['recipient_canonical_maps'] = nil -#default['postfix']['main']['canonical_maps'] = nil +# # 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 +# default['postfix']['main']['sender_canonical_maps'] = nil +# default['postfix']['main']['recipient_canonical_maps'] = nil +# default['postfix']['main']['canonical_maps'] = nil # Master.cf attributes default['postfix']['master']['submission'] = false diff --git a/files/default/tests/minitest/aliases_test.rb b/files/default/tests/minitest/aliases_test.rb index 642afc64..11797daf 100644 --- a/files/default/tests/minitest/aliases_test.rb +++ b/files/default/tests/minitest/aliases_test.rb @@ -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 diff --git a/files/default/tests/minitest/client_test.rb b/files/default/tests/minitest/client_test.rb index d48cf84a..d9c3aaac 100644 --- a/files/default/tests/minitest/client_test.rb +++ b/files/default/tests/minitest/client_test.rb @@ -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 diff --git a/files/default/tests/minitest/default_test.rb b/files/default/tests/minitest/default_test.rb index a4613f18..e0bcf59b 100644 --- a/files/default/tests/minitest/default_test.rb +++ b/files/default/tests/minitest/default_test.rb @@ -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 diff --git a/files/default/tests/minitest/sasl_auth_test.rb b/files/default/tests/minitest/sasl_auth_test.rb index a63f2fb2..2563bcce 100644 --- a/files/default/tests/minitest/sasl_auth_test.rb +++ b/files/default/tests/minitest/sasl_auth_test.rb @@ -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 diff --git a/files/default/tests/minitest/server_test.rb b/files/default/tests/minitest/server_test.rb index 65b603c8..123c72ca 100644 --- a/files/default/tests/minitest/server_test.rb +++ b/files/default/tests/minitest/server_test.rb @@ -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 diff --git a/files/default/tests/minitest/support/helpers.rb b/files/default/tests/minitest/support/helpers.rb index 6ed3df61..2fa4407e 100644 --- a/files/default/tests/minitest/support/helpers.rb +++ b/files/default/tests/minitest/support/helpers.rb @@ -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 diff --git a/metadata.rb b/metadata.rb index 75ac330d..e570064c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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/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/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/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/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/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_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/use_procmail', +display_name: 'Postfix Use procmail?', +description: 'Whether procmail should be used as the local delivery agent for a server', +default: 'no' diff --git a/recipes/aliases.rb b/recipes/aliases.rb index 7e7839f0..667ebe09 100644 --- a/recipes/aliases.rb +++ b/recipes/aliases.rb @@ -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 diff --git a/recipes/client.rb b/recipes/client.rb index 8fffa753..493f4b81 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -1,4 +1,4 @@ -# +# encoding: utf-8 # Author:: Joshua Timberman() # Cookbook Name:: postfix # Recipe:: client @@ -24,19 +24,19 @@ end query = "role:#{node['postfix']['relayhost_role']}" -relayhost = "" +relayhost = '' results = [] if node.run_list.roles.include?(node['postfix']['relayhost_role']) relayhost << node['ipaddress'] elsif node['postfix']['multi_environment_relay'] results = search(:node, query) - relayhost = results.map {|n| n['ipaddress']}.first + relayhost = results.map { |n| n['ipaddress'] }.first else results = search(:node, "#{query} AND chef_environment:#{node.chef_environment}") - relayhost = results.map {|n| n['ipaddress']}.first + relayhost = results.map { |n| n['ipaddress'] }.first end node.set['postfix']['main']['relayhost'] = "[#{relayhost}]" -include_recipe "postfix" +include_recipe 'postfix' diff --git a/recipes/default.rb b/recipes/default.rb index 4a2497da..2bbdb263 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,4 +1,4 @@ -# +# encoding: utf-8 # Author:: Joshua Timberman() # 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 @@ %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 diff --git a/recipes/sasl_auth.rb b/recipes/sasl_auth.rb index 0aaef7e6..aca5c26b 100644 --- a/recipes/sasl_auth.rb +++ b/recipes/sasl_auth.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 # # Author:: Joshua Timberman() # 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 diff --git a/recipes/server.rb b/recipes/server.rb index 164f3257..63dc71d4 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 # # Author:: Joshua Timberman() # 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'