From 77c76717bfc26fe7ba1641244164bc1cb5c38429 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 14 Nov 2017 19:44:08 +0000 Subject: [PATCH] Fix foodcritic warnings --- cookbooks/accounts/recipes/default.rb | 2 -- cookbooks/apt/resources/source.rb | 12 ++++---- cookbooks/imagery/resources/site.rb | 28 ++++++++--------- cookbooks/mediawiki/providers/extension.rb | 1 - cookbooks/mediawiki/providers/site.rb | 4 +-- cookbooks/mediawiki/providers/skin.rb | 1 - cookbooks/ssl/resources/certificate.rb | 36 +++++++++++----------- cookbooks/systemd/resources/path.rb | 14 ++++----- cookbooks/systemd/resources/service.rb | 20 ++++++------ cookbooks/taginfo/recipes/default.rb | 1 - cookbooks/tilelog/recipes/default.rb | 1 - 11 files changed, 57 insertions(+), 63 deletions(-) diff --git a/cookbooks/accounts/recipes/default.rb b/cookbooks/accounts/recipes/default.rb index 76c3a8460..feb57a5e9 100644 --- a/cookbooks/accounts/recipes/default.rb +++ b/cookbooks/accounts/recipes/default.rb @@ -42,13 +42,11 @@ search(:accounts, "*:*").each do |account| end group name.to_s do - action :create gid account["uid"].to_i members group_members & node[:etc][:passwd].keys end user name.to_s do - action :create uid account["uid"].to_i gid account["uid"].to_i comment account["comment"] if account["comment"] diff --git a/cookbooks/apt/resources/source.rb b/cookbooks/apt/resources/source.rb index 44bd100ae..f80b85d17 100644 --- a/cookbooks/apt/resources/source.rb +++ b/cookbooks/apt/resources/source.rb @@ -19,7 +19,7 @@ default_action :create -property :name, String, :name_property => true +property :source_name, String, :name_property => true property :source_template, String, :default => "default.list.erb" property :url, String, :required => true property :key, String @@ -43,13 +43,13 @@ action :create do execute "apt-key-#{key}-install" do command "/usr/bin/apt-key adv --fetch-keys #{key_url}" not_if "/usr/bin/apt-key adv --list-keys #{key}" - notifies :run, "execute[apt-update-#{new_resource.name}]" + notifies :run, "execute[apt-update-#{source_name}]" end else execute "apt-key-#{key}-install" do command "/usr/bin/apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys #{key}" not_if "/usr/bin/apt-key adv --list-keys #{key}" - notifies :run, "execute[apt-update-#{new_resource.name}]" + notifies :run, "execute[apt-update-#{source_name}]" end end end @@ -60,10 +60,10 @@ action :create do group "root" mode 0o644 variables :url => url - notifies :run, "execute[apt-update-#{new_resource.name}]" + notifies :run, "execute[apt-update-#{source_name}]" end - execute "apt-update-#{name}" do + execute "apt-update-#{source_name}" do action update ? :run : :nothing command "/usr/bin/apt-get update --no-list-cleanup -o Dir::Etc::sourcelist='#{source_path}' -o Dir::Etc::sourceparts='-'" end @@ -76,5 +76,5 @@ action :delete do end def source_path - "/etc/apt/sources.list.d/#{name}.list" + "/etc/apt/sources.list.d/#{source_name}.list" end diff --git a/cookbooks/imagery/resources/site.rb b/cookbooks/imagery/resources/site.rb index d6e2071cc..c2f0e47c5 100644 --- a/cookbooks/imagery/resources/site.rb +++ b/cookbooks/imagery/resources/site.rb @@ -21,33 +21,33 @@ require "yaml" default_action :create -property :name, String +property :site, String, :name_property => true property :title, String, :required => true property :aliases, [String, Array], :default => [] property :bbox, Array, :required => true action :create do - directory "/srv/#{name}" do + directory "/srv/#{site}" do user "root" group "root" mode 0o755 end - directory "/srv/imagery/layers/#{name}" do + directory "/srv/imagery/layers/#{site}" do user "root" group "root" mode 0o755 recursive true end - directory "/srv/imagery/overlays/#{name}" do + directory "/srv/imagery/overlays/#{site}" do user "root" group "root" mode 0o755 recursive true end - template "/srv/#{name}/index.html" do + template "/srv/#{site}/index.html" do source "index.html.erb" user "root" group "root" @@ -55,32 +55,32 @@ action :create do variables :title => title end - cookbook_file "/srv/#{name}/imagery.css" do + cookbook_file "/srv/#{site}/imagery.css" do source "imagery.css" user "root" group "root" mode 0o644 end - cookbook_file "/srv/#{name}/clientaccesspolicy.xml" do + cookbook_file "/srv/#{site}/clientaccesspolicy.xml" do source "clientaccesspolicy.xml" user "root" group "root" mode 0o644 end - cookbook_file "/srv/#{name}/crossdomain.xml" do + cookbook_file "/srv/#{site}/crossdomain.xml" do source "crossdomain.xml" user "root" group "root" mode 0o644 end - layers = Dir.glob("/srv/imagery/layers/#{name}/*.yml").collect do |path| + layers = Dir.glob("/srv/imagery/layers/#{site}/*.yml").collect do |path| YAML.safe_load(::File.read(path), [Symbol]) end - template "/srv/#{name}/imagery.js" do + template "/srv/#{site}/imagery.js" do source "imagery.js.erb" user "root" group "root" @@ -88,10 +88,10 @@ action :create do variables :bbox => bbox, :layers => layers end - base_domains = [name] + Array(aliases) + base_domains = [site] + Array(aliases) tile_domains = base_domains.flat_map { |d| [d, "a.#{d}", "b.#{d}", "c.#{d}"] } - ssl_certificate new_resource.name do + ssl_certificate site do domains tile_domains end @@ -99,9 +99,9 @@ action :create do IPAddr.new(resolver).ipv6? ? "[#{resolver}]" : resolver end - nginx_site new_resource.name do + nginx_site site do template "nginx_imagery.conf.erb" - directory "/srv/imagery/#{name}" + directory "/srv/imagery/#{site}" restart_nginx false variables new_resource.to_hash.merge(:resolvers => resolvers) end diff --git a/cookbooks/mediawiki/providers/extension.rb b/cookbooks/mediawiki/providers/extension.rb index e0eefa245..f32f581b4 100644 --- a/cookbooks/mediawiki/providers/extension.rb +++ b/cookbooks/mediawiki/providers/extension.rb @@ -69,7 +69,6 @@ action :create do extension_script = "#{extension_directory}/#{new_resource.name}.php" file "#{mediawiki_directory}/LocalSettings.d/Ext-#{new_resource.name}.inc.php" do - action :create content " true property :domains, [String, Array], :required => true action :create do - node.default[:letsencrypt][:certificates][name] = { + node.default[:letsencrypt][:certificates][certificate] = { :domains => Array(domains) } if letsencrypt - certificate = letsencrypt["certificate"] - key = letsencrypt["key"] + certificate_content = letsencrypt["certificate"] + key_content = letsencrypt["key"] end - if certificate - file "/etc/ssl/certs/#{name}.pem" do + if certificate_content + file "/etc/ssl/certs/#{certificate}.pem" do owner "root" group "root" mode 0o444 - content certificate + content certificate_content backup false manage_symlink_source false force_unlink true end - file "/etc/ssl/private/#{name}.key" do + file "/etc/ssl/private/#{certificate}.key" do owner "root" group "ssl-cert" mode 0o440 - content key + content key_content backup false manage_symlink_source false force_unlink true end else - template "/tmp/#{name}.ssl.cnf" do + template "/tmp/#{certificate}.ssl.cnf" do cookbook "ssl" source "ssl.cnf.erb" owner "root" group "root" mode 0o644 - variables :domains => Array(new_resource.domains) + variables :domains => Array(domains) not_if do - ::File.exist?("/etc/ssl/certs/#{new_resource.name}.pem") && ::File.exist?("/etc/ssl/private/#{new_resource.name}.key") + ::File.exist?("/etc/ssl/certs/#{certificate}.pem") && ::File.exist?("/etc/ssl/private/#{certificate}.key") end end - execute "/etc/ssl/certs/#{name}.pem" do - command "openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/private/#{new_resource.name}.key -out /etc/ssl/certs/#{new_resource.name}.pem -days 365 -nodes -config /tmp/#{new_resource.name}.ssl.cnf" + execute "/etc/ssl/certs/#{certificate}.pem" do + command "openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/private/#{certificate}.key -out /etc/ssl/certs/#{certificate}.pem -days 365 -nodes -config /tmp/#{certificate}.ssl.cnf" user "root" group "ssl-cert" not_if do - ::File.exist?("/etc/ssl/certs/#{new_resource.name}.pem") && ::File.exist?("/etc/ssl/private/#{new_resource.name}.key") + ::File.exist?("/etc/ssl/certs/#{certificate}.pem") && ::File.exist?("/etc/ssl/private/#{certificate}.key") end end end end action :delete do - file "/etc/ssl/certs/#{name}.pem" do + file "/etc/ssl/certs/#{certificate}.pem" do action :delete end - file "/etc/ssl/private/#{name}.key" do + file "/etc/ssl/private/#{certificate}.key" do action :delete end end def letsencrypt - @letsencrypt ||= search(:letsencrypt, "id:#{name}").first + @letsencrypt ||= search(:letsencrypt, "id:#{certificate}").first end diff --git a/cookbooks/systemd/resources/path.rb b/cookbooks/systemd/resources/path.rb index a2838e1b1..115ee9f6e 100644 --- a/cookbooks/systemd/resources/path.rb +++ b/cookbooks/systemd/resources/path.rb @@ -19,7 +19,7 @@ default_action :create -property :name, String +property :path, String, :name_property => true property :description, String, :required => true property :after, [String, Array] property :wants, [String, Array] @@ -35,7 +35,7 @@ property :directory_mode, Integer action :create do path_variables = new_resource.to_hash - template "/etc/systemd/system/#{name}.path" do + template "/etc/systemd/system/#{path}.path" do cookbook "systemd" source "path.erb" owner "root" @@ -44,25 +44,25 @@ action :create do variables path_variables end - execute "systemctl-reload-#{name}.path" do + execute "systemctl-reload-#{path}.path" do action :nothing command "systemctl daemon-reload" user "root" group "root" - subscribes :run, "template[/etc/systemd/system/#{name}.path]" + subscribes :run, "template[/etc/systemd/system/#{path}.path]" end end action :delete do - file "/etc/systemd/system/#{name}.path" do + file "/etc/systemd/system/#{path}.path" do action :delete end - execute "systemctl-reload-#{name}.path" do + execute "systemctl-reload-#{path}.path" do action :nothing command "systemctl daemon-reload" user "root" group "root" - subscribes :run, "file[/etc/systemd/system/#{name}.path]" + subscribes :run, "file[/etc/systemd/system/#{path}.path]" end end diff --git a/cookbooks/systemd/resources/service.rb b/cookbooks/systemd/resources/service.rb index e7779fae7..87dd05486 100644 --- a/cookbooks/systemd/resources/service.rb +++ b/cookbooks/systemd/resources/service.rb @@ -19,7 +19,7 @@ default_action :create -property :name, String +property :service, String, :name_property => true property :description, String, :required => true property :after, [String, Array] property :wants, [String, Array] @@ -61,7 +61,7 @@ action :create do service_variables = new_resource.to_hash if environment_file.is_a?(Hash) - template "/etc/default/#{name}" do + template "/etc/default/#{service}" do cookbook "systemd" source "environment.erb" owner "root" @@ -70,10 +70,10 @@ action :create do variables :environment => environment_file end - service_variables[:environment_file] = "/etc/default/#{name}" + service_variables[:environment_file] = "/etc/default/#{service}" end - template "/etc/systemd/system/#{name}.service" do + template "/etc/systemd/system/#{service}.service" do cookbook "systemd" source "service.erb" owner "root" @@ -82,30 +82,30 @@ action :create do variables service_variables end - execute "systemctl-reload-#{name}.service" do + execute "systemctl-reload-#{service}.service" do action :nothing command "systemctl daemon-reload" user "root" group "root" - subscribes :run, "template[/etc/systemd/system/#{name}.service]" + subscribes :run, "template[/etc/systemd/system/#{service}.service]" end end action :delete do - file "/etc/default/#{name}" do + file "/etc/default/#{service}" do action :delete only_if { environment_file.is_a?(Hash) } end - file "/etc/systemd/system/#{name}.service" do + file "/etc/systemd/system/#{service}.service" do action :delete end - execute "systemctl-reload-#{name}.service" do + execute "systemctl-reload-#{service}.service" do action :nothing command "systemctl daemon-reload" user "root" group "root" - subscribes :run, "file[/etc/systemd/system/#{name}.service]" + subscribes :run, "file[/etc/systemd/system/#{service}.service]" end end diff --git a/cookbooks/taginfo/recipes/default.rb b/cookbooks/taginfo/recipes/default.rb index cd3262c7f..e1a9c7225 100644 --- a/cookbooks/taginfo/recipes/default.rb +++ b/cookbooks/taginfo/recipes/default.rb @@ -168,7 +168,6 @@ node[:taginfo][:sites].each do |site| owner "taginfo" group "taginfo" mode "0755" - action :create end execute "compile-osmium" do diff --git a/cookbooks/tilelog/recipes/default.rb b/cookbooks/tilelog/recipes/default.rb index 6fef30343..675e3abc2 100644 --- a/cookbooks/tilelog/recipes/default.rb +++ b/cookbooks/tilelog/recipes/default.rb @@ -88,7 +88,6 @@ end # resources related to the output of the analysis and where it # can be publicly downloaded. directory tilelog_output_directory do - action :create user "www-data" group "www-data" mode 0o755 -- 2.43.2