diff --git a/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_darwin.rb b/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_darwin.rb index c7afb8d1..04425a79 100644 --- a/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_darwin.rb +++ b/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_darwin.rb @@ -27,7 +27,7 @@ def config_dir def configure return unless node['cpe_adobe_flash']['configure'] - configs = node['cpe_adobe_flash']['configs'].reject { |_k, v| v.nil? } + configs = node['cpe_adobe_flash']['configs'].compact # Until adobe removes this problematic naming convention, # we still have to use it. { @@ -47,14 +47,14 @@ def configure not_if { configs.empty? } owner 'root' group 'admin' - mode 0755 + mode '0755' action :create end template ::File.join(config_dir, 'mms.cfg') do # ~ FB016 source 'cpe_adobe_flash.erb' owner 'root' group 'admin' - mode 0644 + mode '0644' action configs.empty? ? :delete : :create notifies :restart, 'launchd[com.adobe.fpsaud]' end diff --git a/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_windows.rb b/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_windows.rb index 4b402d52..c8a0d59d 100644 --- a/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_windows.rb +++ b/itchef/cookbooks/cpe_adobe_flash/resources/configure_adobe_flash_windows.rb @@ -23,7 +23,7 @@ def configure return unless node['cpe_adobe_flash']['configure'] - configs = node['cpe_adobe_flash']['configs'].reject { |_k, v| v.nil? } + configs = node['cpe_adobe_flash']['configs'].compact node.default['cpe_adobe_flash']['_applied_configs'] = configs template ::File.join(config_dir, 'mms.cfg') do # ~FB031 diff --git a/itchef/cookbooks/cpe_bluetooth/resources/cpe_bluetooth.rb b/itchef/cookbooks/cpe_bluetooth/resources/cpe_bluetooth.rb index 830e4b60..14a5acaf 100644 --- a/itchef/cookbooks/cpe_bluetooth/resources/cpe_bluetooth.rb +++ b/itchef/cookbooks/cpe_bluetooth/resources/cpe_bluetooth.rb @@ -20,14 +20,14 @@ default_action :config action :config do - prefs = node['cpe_bluetooth'].reject { |_k, v| v.nil? } + prefs = node['cpe_bluetooth'].compact if prefs.empty? Chef::Log.info("#{cookbook_name}: No prefs found.") return end prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition profile = { 'PayloadIdentifier' => "#{prefix}.bluetooth", diff --git a/itchef/cookbooks/cpe_chrome/resources/cpe_chrome_posix.rb b/itchef/cookbooks/cpe_chrome/resources/cpe_chrome_posix.rb index f043bbdd..703d5d47 100755 --- a/itchef/cookbooks/cpe_chrome/resources/cpe_chrome_posix.rb +++ b/itchef/cookbooks/cpe_chrome/resources/cpe_chrome_posix.rb @@ -26,7 +26,7 @@ manage_chrome_extensions end -action_class do +action_class do # rubocop:disable Metrics/BlockLength def install_repos return unless node.linux? return unless node['cpe_chrome']['manage_repo'] @@ -69,7 +69,7 @@ def manage_chrome !node.installed?('com.google.Chrome') if node['cpe_chrome']['mp']['UseMasterPreferencesFile'] mprefs = - node['cpe_chrome']['mp']['FileContents'].reject { |_k, v| v.nil? } + node['cpe_chrome']['mp']['FileContents'].compact else mprefs = {} end @@ -142,7 +142,7 @@ def manage_chrome_linux(mprefs, prefs) def manage_chrome_macos(mprefs, prefs) prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition chrome_profile = { 'PayloadIdentifier' => "#{prefix}.browsers.chrome", 'PayloadRemovalDisallowed' => true, @@ -170,7 +170,7 @@ def manage_chrome_macos(mprefs, prefs) # Check for Chrome Canary if node.installed?('com.google.Chrome.canary') prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition canary_profile = { 'PayloadIdentifier' => "#{prefix}.browsers.chromecanary", 'PayloadRemovalDisallowed' => true, @@ -224,7 +224,7 @@ def manage_chrome_macos(mprefs, prefs) def manage_chrome_extensions_macos(extprefs) return if extprefs.empty? prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition extprefs.each do |k, v| chrome_ext_profile = { 'PayloadIdentifier' => "#{prefix}.browsers.chrome.extension.#{k}", @@ -238,7 +238,7 @@ def manage_chrome_extensions_macos(extprefs) 'PayloadContent' => [{ 'PayloadType' => "com.google.Chrome.extensions.#{k}", 'PayloadVersion' => 1, - 'PayloadIdentifier' => "#{prefix}.browsers.chrome.extension.settings.#{k}", + 'PayloadIdentifier' => "#{prefix}.browsers.chrome.extension.settings.#{k}", # rubocop:disable Layout/LineLength 'PayloadUUID' => v['payload_uuid'], 'PayloadEnabled' => true, 'PayloadDisplayName' => "Chrome Extension (#{v['display_name']})", @@ -247,16 +247,17 @@ def manage_chrome_extensions_macos(extprefs) v['profile'].each do |k_ext, v_ext| chrome_ext_profile['PayloadContent'][0][k_ext] = v_ext['value'] end - node.default['cpe_profiles']["#{prefix}.browsers.chrome.extension.#{k}"] = chrome_ext_profile + node.default['cpe_profiles']["#{prefix}.browsers.chrome.extension.#{k}"] = + chrome_ext_profile end # Check for Chrome Canary if node.installed?('com.google.Chrome.canary') prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition extprefs.each do |k, v| canary_ext_profile = { - 'PayloadIdentifier' => "#{prefix}.browsers.chromecanary.extension.#{k}", + 'PayloadIdentifier' => "#{prefix}.browsers.chromecanary.extension.#{k}", # rubocop:disable Layout/LineLength 'PayloadRemovalDisallowed' => true, 'PayloadScope' => 'System', 'PayloadType' => 'Configuration', @@ -267,16 +268,16 @@ def manage_chrome_extensions_macos(extprefs) 'PayloadContent' => [{ 'PayloadType' => "com.google.Chrome.canary.extensions.#{k}", 'PayloadVersion' => 1, - 'PayloadIdentifier' => "#{prefix}.browsers.chromecanary.extension.settings.#{k}", + 'PayloadIdentifier' => "#{prefix}.browsers.chromecanary.extension.settings.#{k}", # rubocop:disable Layout/LineLength 'PayloadUUID' => v['payload_uuid'], 'PayloadEnabled' => true, - 'PayloadDisplayName' => "Chrome Canary Extension (#{v['display_name']})", + 'PayloadDisplayName' => "Chrome Canary Extension (#{v['display_name']})", # rubocop:disable Layout/LineLength }], } v['profile'].each do |k_ext, v_ext| canary_ext_profile['PayloadContent'][0][k_ext] = v_ext['value'] end - node.default['cpe_profiles']["#{prefix}.browsers.chromecanary.extension.#{k}"] = canary_ext_profile + node.default['cpe_profiles']["#{prefix}.browsers.chromecanary.extension.#{k}"] = canary_ext_profile # rubocop:disable Layout/LineLength end end end @@ -318,6 +319,7 @@ def migrate_chromium_settings_linux ::File.directory?('/etc/chromium') && !::File.symlink?('/etc/chromium') end + # rubocop:disable Naming/HeredocDelimiterNaming code <<-EOH find /etc/chromium -type d -exec chmod 0755 {} \\; find /etc/chromium -type f -exec chmod 0644 {} \\; @@ -326,5 +328,6 @@ def migrate_chromium_settings_linux rm -rf /etc/chromium EOH end + # rubocop:enable Naming/HeredocDelimiterNaming end end diff --git a/itchef/cookbooks/cpe_munki/resources/cpe_munki_config.rb b/itchef/cookbooks/cpe_munki/resources/cpe_munki_config.rb index f6f06667..767f8e07 100644 --- a/itchef/cookbooks/cpe_munki/resources/cpe_munki_config.rb +++ b/itchef/cookbooks/cpe_munki/resources/cpe_munki_config.rb @@ -22,14 +22,14 @@ action :config do return unless node['cpe_munki']['configure'] - munki_prefs = node['cpe_munki']['preferences'].reject { |_k, v| v.nil? } + munki_prefs = node['cpe_munki']['preferences'].compact if munki_prefs.empty? Chef::Log.info("#{cookbook_name}: No prefs found.") return end prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition munki_profile = { 'PayloadIdentifier' => "#{prefix}.munki", diff --git a/itchef/cookbooks/cpe_munki/resources/cpe_munki_defaults_config.rb b/itchef/cookbooks/cpe_munki/resources/cpe_munki_defaults_config.rb index ec7a0caf..9585b497 100644 --- a/itchef/cookbooks/cpe_munki/resources/cpe_munki_defaults_config.rb +++ b/itchef/cookbooks/cpe_munki/resources/cpe_munki_defaults_config.rb @@ -22,7 +22,7 @@ return unless node['cpe_munki']['configure'] munki_prefs = node['cpe_munki'][ - 'defaults_preferences'].reject { |_k, v| v.nil? } + 'defaults_preferences'].compact if munki_prefs.empty? Chef::Log.info("#{cookbook_name}: No defaults prefs found.") diff --git a/itchef/cookbooks/cpe_nomad/resources/darwin.rb b/itchef/cookbooks/cpe_nomad/resources/darwin.rb index 717b482e..a09f1643 100644 --- a/itchef/cookbooks/cpe_nomad/resources/darwin.rb +++ b/itchef/cookbooks/cpe_nomad/resources/darwin.rb @@ -74,11 +74,11 @@ def configure_login def configure_profile nomad_prefs = - node['cpe_nomad']['prefs'].reject { |_k, v| v.nil? } + node['cpe_nomad']['prefs'].compact login_prefs = - node['cpe_nomad']['login']['prefs'].reject { |_k, v| v.nil? } + node['cpe_nomad']['login']['prefs'].compact actions_prefs = - node['cpe_nomad']['actions']['prefs'].reject { |_k, v| v.nil? } + node['cpe_nomad']['actions']['prefs'].compact if [ nomad_prefs, login_prefs, @@ -122,7 +122,7 @@ def configure_profile end prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition { 'NoMAD' => nomad_prefs, @@ -172,7 +172,7 @@ def log_vars(action, status) end def log_if(msg) - CPE::Log.if( + CPE::Log.if( # rubocop:disable Style/ExplicitBlockArgument msg, :type => @type, :action => @action, :status => @status ) { yield } end diff --git a/itchef/cookbooks/cpe_powermanagement/resources/cpe_powermanagement.rb b/itchef/cookbooks/cpe_powermanagement/resources/cpe_powermanagement.rb index ed75a637..12a0e159 100644 --- a/itchef/cookbooks/cpe_powermanagement/resources/cpe_powermanagement.rb +++ b/itchef/cookbooks/cpe_powermanagement/resources/cpe_powermanagement.rb @@ -21,7 +21,7 @@ default_action :config action :config do - pw_prefs = node['cpe_powermanagement'].reject { |_k, v| v.nil? } + pw_prefs = node['cpe_powermanagement'].compact if pw_prefs.empty? Chef::Log.debug("#{cookbook_name}: No prefs found.") return @@ -34,17 +34,17 @@ ident = "com.apple.EnergySaver.#{machine_type}" prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition energy_profile = { - 'PayloadIdentifier' => "#{prefix}.powermanagement", + 'PayloadIdentifier' => "#{prefix}.powermanagement", 'PayloadRemovalDisallowed' => true, - 'PayloadScope' => 'System', - 'PayloadType' => 'Configuration', - 'PayloadUUID' => 'd1207590-f93a-0133-92e4-4cc760f34b36', - 'PayloadOrganization' => organization, - 'PayloadVersion' => 1, - 'PayloadDisplayName' => 'Power Management', - 'PayloadContent' => [ + 'PayloadScope' => 'System', + 'PayloadType' => 'Configuration', + 'PayloadUUID' => 'd1207590-f93a-0133-92e4-4cc760f34b36', + 'PayloadOrganization' => organization, + 'PayloadVersion' => 1, + 'PayloadDisplayName' => 'Power Management', + 'PayloadContent' => [ { 'PayloadType' => 'com.apple.MCX', 'PayloadVersion' => 1, @@ -58,13 +58,13 @@ pm_prefs = { 'ACPower' => - node['cpe_powermanagement']['ACPower'].reject { |_k, v| v.nil? }, + node['cpe_powermanagement']['ACPower'].compact, 'Battery' => - node['cpe_powermanagement']['Battery'].reject { |_k, v| v.nil? }, + node['cpe_powermanagement']['Battery'].compact, } # Apply all settings to the profile - AC and/or Battery - pm_prefs.keys.each do |type| + pm_prefs.each_key do |type| next if pm_prefs[type].empty? energy_profile['PayloadContent'][0]["#{ident}.#{type}-ProfileNumber"] = -1 energy_profile['PayloadContent'][0]["#{ident}.#{type}"] = pm_prefs[type] diff --git a/itchef/cookbooks/cpe_preferencepanes/resources/default.rb b/itchef/cookbooks/cpe_preferencepanes/resources/default.rb index 881a46bb..d2ed65dd 100644 --- a/itchef/cookbooks/cpe_preferencepanes/resources/default.rb +++ b/itchef/cookbooks/cpe_preferencepanes/resources/default.rb @@ -21,10 +21,10 @@ # rubocop:disable Metrics/BlockLength action :config do - prefs = node['cpe_preferencepanes'].reject { |_k, v| v.nil? } + prefs = node['cpe_preferencepanes'].compact return if prefs.empty? prefix = node['cpe_profiles']['prefix'] - organization = node['organization'] ? node['organization'] : 'Facebook' + organization = node['organization'] ? node['organization'] : 'Facebook' # rubocop:disable Style/RedundantCondition pane_profile = { 'PayloadIdentifier' => "#{prefix}.prefpanes", 'PayloadRemovalDisallowed' => true, diff --git a/itchef/cookbooks/cpe_profiles_local/README.md b/itchef/cookbooks/cpe_profiles_local/README.md index e2308b98..f8cf039f 100644 --- a/itchef/cookbooks/cpe_profiles_local/README.md +++ b/itchef/cookbooks/cpe_profiles_local/README.md @@ -32,7 +32,7 @@ to `node.default['cpe_profiles_local']` For instance, add a hash to manage the loginwindow and use the default prefix: ``` -lw_prefs = node['cpe_loginwindow'].reject { |\_k, v| v.nil? } +lw_prefs = node['cpe_loginwindow'].compact if lw_prefs.empty? Chef::Log.debug("#{cookbook_name}: No prefs found.") return @@ -77,7 +77,7 @@ Or, if you want to customize the prefix and then add a profile, you would do: # Override the default prefix value of 'com.facebook.chef' node.default['cpe_profiles_local']['prefix'] = 'com.company.chef' # Use the specified prefix to name the configuration profile -lw_prefs = node['cpe_loginwindow'].reject { |\_k, v| v.nil? } +lw_prefs = node['cpe_loginwindow'].compact if lw_prefs.empty? Chef::Log.debug("#{cookbook_name}: No prefs found.") return