From a08c8d97d5cd3666799fb3bef14618d4c7c23398 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 13 May 2021 19:16:30 +0100 Subject: [PATCH] Enable unified mode for custom resources --- .rubocop_todo.yml | 7 --- cookbooks/apache/resources/conf.rb | 2 + cookbooks/apache/resources/module.rb | 2 + cookbooks/apache/resources/site.rb | 2 + cookbooks/fail2ban/resources/filter.rb | 2 + cookbooks/fail2ban/resources/jail.rb | 2 + cookbooks/imagery/resources/layer.rb | 2 + cookbooks/imagery/resources/site.rb | 2 + cookbooks/mediawiki/resources/extension.rb | 2 + cookbooks/mediawiki/resources/site.rb | 54 ++++++++++--------- cookbooks/mediawiki/resources/skin.rb | 2 + cookbooks/munin/resources/plugin.rb | 2 + cookbooks/munin/resources/plugin_conf.rb | 2 + cookbooks/mysql/resources/database.rb | 2 + cookbooks/mysql/resources/user.rb | 2 + .../networking/resources/firewall_rule.rb | 2 + cookbooks/nginx/resources/site.rb | 2 + cookbooks/nodejs/resources/package.rb | 2 + cookbooks/ohai/resources/plugin.rb | 2 + cookbooks/passenger/resources/application.rb | 2 + cookbooks/php/resources/fpm.rb | 2 + cookbooks/postgresql/resources/database.rb | 2 + cookbooks/postgresql/resources/execute.rb | 2 + cookbooks/postgresql/resources/extension.rb | 2 + cookbooks/postgresql/resources/munin.rb | 2 + cookbooks/postgresql/resources/table.rb | 2 + cookbooks/postgresql/resources/tablespace.rb | 2 + cookbooks/postgresql/resources/user.rb | 2 + cookbooks/prometheus/resources/collector.rb | 2 + cookbooks/prometheus/resources/exporter.rb | 2 + cookbooks/python/resources/package.rb | 2 + cookbooks/python/resources/virtualenv.rb | 2 + cookbooks/squid/resources/fragment.rb | 2 + cookbooks/ssl/resources/certificate.rb | 2 + cookbooks/systemd/resources/path.rb | 2 + cookbooks/systemd/resources/service.rb | 2 + cookbooks/systemd/resources/timer.rb | 2 + cookbooks/systemd/resources/tmpfile.rb | 2 + cookbooks/web/resources/rails_port.rb | 2 + cookbooks/wordpress/resources/plugin.rb | 2 + cookbooks/wordpress/resources/site.rb | 2 + cookbooks/wordpress/resources/theme.rb | 2 + 42 files changed, 108 insertions(+), 33 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 98635660c..a92cef294 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 41 -# Cop supports --auto-correct. -# Configuration parameters: Include. -# Include: **/resources/*.rb -Chef/Deprecations/ResourceWithoutUnifiedTrue: - Enabled: false - # Offense count: 1124 # Cop supports --auto-correct. # Configuration parameters: . diff --git a/cookbooks/apache/resources/conf.rb b/cookbooks/apache/resources/conf.rb index 12daf87ab..9f1efb24f 100644 --- a/cookbooks/apache/resources/conf.rb +++ b/cookbooks/apache/resources/conf.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action [:create, :enable] property :conf, :kind_of => String, :name_property => true diff --git a/cookbooks/apache/resources/module.rb b/cookbooks/apache/resources/module.rb index 6658d52a6..5de2bfcaa 100644 --- a/cookbooks/apache/resources/module.rb +++ b/cookbooks/apache/resources/module.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action [:install, :enable] property :module, :kind_of => String, :name_property => true diff --git a/cookbooks/apache/resources/site.rb b/cookbooks/apache/resources/site.rb index e039e3ac5..598f841ff 100644 --- a/cookbooks/apache/resources/site.rb +++ b/cookbooks/apache/resources/site.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action [:create, :enable] property :site, :kind_of => String, :name_property => true diff --git a/cookbooks/fail2ban/resources/filter.rb b/cookbooks/fail2ban/resources/filter.rb index 3cd173eee..13a778295 100644 --- a/cookbooks/fail2ban/resources/filter.rb +++ b/cookbooks/fail2ban/resources/filter.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :filter, :kind_of => String, :name_property => true diff --git a/cookbooks/fail2ban/resources/jail.rb b/cookbooks/fail2ban/resources/jail.rb index 6ff5307e3..3af0960e9 100644 --- a/cookbooks/fail2ban/resources/jail.rb +++ b/cookbooks/fail2ban/resources/jail.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :jail, :kind_of => String, :name_property => true diff --git a/cookbooks/imagery/resources/layer.rb b/cookbooks/imagery/resources/layer.rb index 6affe4b80..dc1fd51bb 100644 --- a/cookbooks/imagery/resources/layer.rb +++ b/cookbooks/imagery/resources/layer.rb @@ -19,6 +19,8 @@ require "yaml" +unified_mode true + default_action :create property :layer, String, :name_property => true diff --git a/cookbooks/imagery/resources/site.rb b/cookbooks/imagery/resources/site.rb index c30c26d95..e64231a72 100644 --- a/cookbooks/imagery/resources/site.rb +++ b/cookbooks/imagery/resources/site.rb @@ -19,6 +19,8 @@ require "yaml" +unified_mode true + default_action :create property :site, String, :name_property => true diff --git a/cookbooks/mediawiki/resources/extension.rb b/cookbooks/mediawiki/resources/extension.rb index 9f477a53f..4e44f18c2 100644 --- a/cookbooks/mediawiki/resources/extension.rb +++ b/cookbooks/mediawiki/resources/extension.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :extension, :kind_of => String, :name_property => true diff --git a/cookbooks/mediawiki/resources/site.rb b/cookbooks/mediawiki/resources/site.rb index d3fd852ee..1931dc9e2 100644 --- a/cookbooks/mediawiki/resources/site.rb +++ b/cookbooks/mediawiki/resources/site.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :site, :kind_of => String, :name_property => true @@ -76,27 +78,6 @@ action :create do end end - execute "#{mediawiki_directory}/maintenance/install.php" do - action :nothing - # Use metanamespace as Site Name to ensure correct set namespace - command "php maintenance/install.php --server '#{name}' --dbtype 'mysql' --dbname '#{new_resource.database_name}' --dbuser '#{new_resource.database_user}' --dbpass '#{new_resource.database_password}' --dbserver 'localhost' --scriptpath /w --pass '#{new_resource.admin_password}' '#{new_resource.metanamespace}' '#{new_resource.admin_user}'" - cwd mediawiki_directory - user node[:mediawiki][:user] - group node[:mediawiki][:group] - not_if do - ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php") - end - notifies :run, "ruby_block[rename-installer-localsettings]", :immediately - end - - execute "#{mediawiki_directory}/maintenance/update.php" do - action :nothing - command "php maintenance/update.php --quick" - cwd mediawiki_directory - user node[:mediawiki][:user] - group node[:mediawiki][:group] - end - declare_resource :directory, site_directory do owner node[:mediawiki][:user] group node[:mediawiki][:group] @@ -121,6 +102,14 @@ action :create do notifies :run, "execute[#{mediawiki_directory}/maintenance/update.php]" end + template "#{mediawiki_directory}/composer.local.json" do + cookbook "mediawiki" + source "composer.local.json.erb" + owner node[:mediawiki][:user] + group node[:mediawiki][:group] + mode "664" + end + execute "#{mediawiki_directory}/composer.json" do action :nothing command "composer update --no-dev" @@ -130,12 +119,25 @@ action :create do environment "COMPOSER_HOME" => site_directory end - template "#{mediawiki_directory}/composer.local.json" do - cookbook "mediawiki" - source "composer.local.json.erb" - owner node[:mediawiki][:user] + execute "#{mediawiki_directory}/maintenance/install.php" do + action :nothing + # Use metanamespace as Site Name to ensure correct set namespace + command "php maintenance/install.php --server '#{name}' --dbtype 'mysql' --dbname '#{new_resource.database_name}' --dbuser '#{new_resource.database_user}' --dbpass '#{new_resource.database_password}' --dbserver 'localhost' --scriptpath /w --pass '#{new_resource.admin_password}' '#{new_resource.metanamespace}' '#{new_resource.admin_user}'" + cwd mediawiki_directory + user node[:mediawiki][:user] + group node[:mediawiki][:group] + not_if do + ::File.exist?("#{mediawiki_directory}/LocalSettings-install.php") + end + notifies :run, "ruby_block[rename-installer-localsettings]", :immediately + end + + execute "#{mediawiki_directory}/maintenance/update.php" do + action :nothing + command "php maintenance/update.php --quick" + cwd mediawiki_directory + user node[:mediawiki][:user] group node[:mediawiki][:group] - mode "664" end # Safety catch if git doesn't update but install.php hasn't run diff --git a/cookbooks/mediawiki/resources/skin.rb b/cookbooks/mediawiki/resources/skin.rb index f70ad6afe..3153fa91a 100644 --- a/cookbooks/mediawiki/resources/skin.rb +++ b/cookbooks/mediawiki/resources/skin.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :skin, :kind_of => String, :name_property => true diff --git a/cookbooks/munin/resources/plugin.rb b/cookbooks/munin/resources/plugin.rb index bc58bf975..10c149436 100644 --- a/cookbooks/munin/resources/plugin.rb +++ b/cookbooks/munin/resources/plugin.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :plugin, :kind_of => String, :name_property => true diff --git a/cookbooks/munin/resources/plugin_conf.rb b/cookbooks/munin/resources/plugin_conf.rb index 6105f0d2b..8306b046b 100644 --- a/cookbooks/munin/resources/plugin_conf.rb +++ b/cookbooks/munin/resources/plugin_conf.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :plugin_conf, :kind_of => String, :name_property => true diff --git a/cookbooks/mysql/resources/database.rb b/cookbooks/mysql/resources/database.rb index 65b6d2e22..69e4e795f 100644 --- a/cookbooks/mysql/resources/database.rb +++ b/cookbooks/mysql/resources/database.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :database, :kind_of => String, :name_property => true diff --git a/cookbooks/mysql/resources/user.rb b/cookbooks/mysql/resources/user.rb index 078316fc8..944cfcc6f 100644 --- a/cookbooks/mysql/resources/user.rb +++ b/cookbooks/mysql/resources/user.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :user, :kind_of => String, :name_property => true diff --git a/cookbooks/networking/resources/firewall_rule.rb b/cookbooks/networking/resources/firewall_rule.rb index e92681ec7..a3e2e7eb0 100644 --- a/cookbooks/networking/resources/firewall_rule.rb +++ b/cookbooks/networking/resources/firewall_rule.rb @@ -20,6 +20,8 @@ resource_name :firewall_rule provides :firewall_rule +unified_mode true + default_action :nothing property :rule, :kind_of => String, :name_property => true diff --git a/cookbooks/nginx/resources/site.rb b/cookbooks/nginx/resources/site.rb index 45422434a..b1a4b5970 100644 --- a/cookbooks/nginx/resources/site.rb +++ b/cookbooks/nginx/resources/site.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :site, :kind_of => String, :name_property => true diff --git a/cookbooks/nodejs/resources/package.rb b/cookbooks/nodejs/resources/package.rb index b5024147a..5279cc91a 100644 --- a/cookbooks/nodejs/resources/package.rb +++ b/cookbooks/nodejs/resources/package.rb @@ -19,6 +19,8 @@ require "json" +unified_mode true + default_action :install property :package, :kind_of => String, :name_property => true diff --git a/cookbooks/ohai/resources/plugin.rb b/cookbooks/ohai/resources/plugin.rb index 5d550371f..d5f1c42fe 100644 --- a/cookbooks/ohai/resources/plugin.rb +++ b/cookbooks/ohai/resources/plugin.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :plugin, :kind_of => String, :name_property => true diff --git a/cookbooks/passenger/resources/application.rb b/cookbooks/passenger/resources/application.rb index 3eef14c7f..5f5e2efbb 100644 --- a/cookbooks/passenger/resources/application.rb +++ b/cookbooks/passenger/resources/application.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :restart property :application, String, :name_property => true diff --git a/cookbooks/php/resources/fpm.rb b/cookbooks/php/resources/fpm.rb index abdc582c8..657f3b51b 100644 --- a/cookbooks/php/resources/fpm.rb +++ b/cookbooks/php/resources/fpm.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :pool, :kind_of => String, :name_property => true diff --git a/cookbooks/postgresql/resources/database.rb b/cookbooks/postgresql/resources/database.rb index c73250464..2d14cdfd1 100644 --- a/cookbooks/postgresql/resources/database.rb +++ b/cookbooks/postgresql/resources/database.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :database, :kind_of => String, :name_property => true diff --git a/cookbooks/postgresql/resources/execute.rb b/cookbooks/postgresql/resources/execute.rb index 3845546bc..4f7217ec8 100644 --- a/cookbooks/postgresql/resources/execute.rb +++ b/cookbooks/postgresql/resources/execute.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :run property :command, :kind_of => String, :name_property => true diff --git a/cookbooks/postgresql/resources/extension.rb b/cookbooks/postgresql/resources/extension.rb index 3adcfd62b..ec60fb975 100644 --- a/cookbooks/postgresql/resources/extension.rb +++ b/cookbooks/postgresql/resources/extension.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :extension, :kind_of => String, :name_property => true diff --git a/cookbooks/postgresql/resources/munin.rb b/cookbooks/postgresql/resources/munin.rb index 311325b0f..4b69d4224 100644 --- a/cookbooks/postgresql/resources/munin.rb +++ b/cookbooks/postgresql/resources/munin.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :munin, :kind_of => String, :name_property => true diff --git a/cookbooks/postgresql/resources/table.rb b/cookbooks/postgresql/resources/table.rb index ed2655932..f97417895 100644 --- a/cookbooks/postgresql/resources/table.rb +++ b/cookbooks/postgresql/resources/table.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :table, :kind_of => String, :name_property => true diff --git a/cookbooks/postgresql/resources/tablespace.rb b/cookbooks/postgresql/resources/tablespace.rb index 69e0ce2b0..bfa0c4b8c 100644 --- a/cookbooks/postgresql/resources/tablespace.rb +++ b/cookbooks/postgresql/resources/tablespace.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :tablespace, :kind_of => String, :name_property => true diff --git a/cookbooks/postgresql/resources/user.rb b/cookbooks/postgresql/resources/user.rb index ad8fed4d5..35ff5aa8b 100644 --- a/cookbooks/postgresql/resources/user.rb +++ b/cookbooks/postgresql/resources/user.rb @@ -19,6 +19,8 @@ require "shellwords" +unified_mode true + default_action :create property :user, :kind_of => String, :name_property => true diff --git a/cookbooks/prometheus/resources/collector.rb b/cookbooks/prometheus/resources/collector.rb index c9c28fc6e..4a0c22d9b 100644 --- a/cookbooks/prometheus/resources/collector.rb +++ b/cookbooks/prometheus/resources/collector.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :collector, :kind_of => String, :name_property => true diff --git a/cookbooks/prometheus/resources/exporter.rb b/cookbooks/prometheus/resources/exporter.rb index bab318a4a..df5304b3c 100644 --- a/cookbooks/prometheus/resources/exporter.rb +++ b/cookbooks/prometheus/resources/exporter.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :exporter, :kind_of => String, :name_property => true diff --git a/cookbooks/python/resources/package.rb b/cookbooks/python/resources/package.rb index 0679e87e3..0a3f49170 100644 --- a/cookbooks/python/resources/package.rb +++ b/cookbooks/python/resources/package.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :install property :package_name, :kind_of => String, :name_property => true diff --git a/cookbooks/python/resources/virtualenv.rb b/cookbooks/python/resources/virtualenv.rb index 6f07fd895..8b1391761 100644 --- a/cookbooks/python/resources/virtualenv.rb +++ b/cookbooks/python/resources/virtualenv.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :virtualenv_directory, :kind_of => String, :name_property => true diff --git a/cookbooks/squid/resources/fragment.rb b/cookbooks/squid/resources/fragment.rb index f4099ad7b..a418d6bcd 100644 --- a/cookbooks/squid/resources/fragment.rb +++ b/cookbooks/squid/resources/fragment.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :fragment, :kind_of => String, :name_property => true diff --git a/cookbooks/ssl/resources/certificate.rb b/cookbooks/ssl/resources/certificate.rb index 5fc33b61b..f2fb4784c 100644 --- a/cookbooks/ssl/resources/certificate.rb +++ b/cookbooks/ssl/resources/certificate.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :certificate, String, :name_property => true diff --git a/cookbooks/systemd/resources/path.rb b/cookbooks/systemd/resources/path.rb index 29bbfa51c..52f5576c6 100644 --- a/cookbooks/systemd/resources/path.rb +++ b/cookbooks/systemd/resources/path.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :path, String, :name_property => true diff --git a/cookbooks/systemd/resources/service.rb b/cookbooks/systemd/resources/service.rb index 62c959692..abfacb650 100644 --- a/cookbooks/systemd/resources/service.rb +++ b/cookbooks/systemd/resources/service.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :service, String, :name_property => true diff --git a/cookbooks/systemd/resources/timer.rb b/cookbooks/systemd/resources/timer.rb index 7dc4cab65..8ace5bfe9 100644 --- a/cookbooks/systemd/resources/timer.rb +++ b/cookbooks/systemd/resources/timer.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :timer, String, :name_property => true diff --git a/cookbooks/systemd/resources/tmpfile.rb b/cookbooks/systemd/resources/tmpfile.rb index 38538e15f..07c39d3a9 100644 --- a/cookbooks/systemd/resources/tmpfile.rb +++ b/cookbooks/systemd/resources/tmpfile.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :type, String, :required => [:create] diff --git a/cookbooks/web/resources/rails_port.rb b/cookbooks/web/resources/rails_port.rb index 90028e9f9..e0c9cad91 100644 --- a/cookbooks/web/resources/rails_port.rb +++ b/cookbooks/web/resources/rails_port.rb @@ -22,6 +22,8 @@ require "yaml" resource_name :rails_port provides :rails_port +unified_mode true + default_action :create property :site, String, :name_property => true diff --git a/cookbooks/wordpress/resources/plugin.rb b/cookbooks/wordpress/resources/plugin.rb index ccc8010d5..82c7ae5e2 100644 --- a/cookbooks/wordpress/resources/plugin.rb +++ b/cookbooks/wordpress/resources/plugin.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :plugin, :kind_of => String, :name_property => true diff --git a/cookbooks/wordpress/resources/site.rb b/cookbooks/wordpress/resources/site.rb index a00cd9cac..1d419c14e 100644 --- a/cookbooks/wordpress/resources/site.rb +++ b/cookbooks/wordpress/resources/site.rb @@ -18,6 +18,8 @@ require "securerandom" +unified_mode true + default_action :create property :site, :kind_of => String, :name_property => true diff --git a/cookbooks/wordpress/resources/theme.rb b/cookbooks/wordpress/resources/theme.rb index 3e8fabe94..994cf1223 100644 --- a/cookbooks/wordpress/resources/theme.rb +++ b/cookbooks/wordpress/resources/theme.rb @@ -17,6 +17,8 @@ # limitations under the License. # +unified_mode true + default_action :create property :theme, :kind_of => String, :name_property => true -- 2.43.2