From 25a4be358fc69de10a2e3e33b5525bc7f2ace74e Mon Sep 17 00:00:00 2001 From: kitchen-porter Date: Tue, 12 Oct 2021 00:05:33 +0000 Subject: [PATCH 1/3] Cookstyle 7.25.6 Fixes Issues found and resolved with: resources/compile.rb - 72:1 refactor: Chef/Modernize/ClassEvalActionClass - In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block. https://docs.chef.io/workstation/cookstyle/chef_modernize_classevalactionclass Issues found and resolved with: resources/install.rb - 127:1 refactor: Chef/Modernize/ClassEvalActionClass - In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block. https://docs.chef.io/workstation/cookstyle/chef_modernize_classevalactionclass Issues found and resolved with: resources/rules.rb - 18:1 refactor: Chef/Modernize/ClassEvalActionClass - In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block. https://docs.chef.io/workstation/cookstyle/chef_modernize_classevalactionclass Issues found and resolved with: resources/service.rb - 5:26 refactor: Chef/Modernize/UseChefLanguageSystemdHelper - Chef Infra Client 15.5 and later include a systemd? helper for checking if a Linux system uses systemd. https://docs.chef.io/workstation/cookstyle/chef_modernize_usecheflanguagesystemdhelper - 18:77 refactor: Chef/Modernize/UseChefLanguageSystemdHelper - Chef Infra Client 15.5 and later include a systemd? helper for checking if a Linux system uses systemd. https://docs.chef.io/workstation/cookstyle/chef_modernize_usecheflanguagesystemdhelper - 30:26 refactor: Chef/Modernize/UseChefLanguageSystemdHelper - Chef Infra Client 15.5 and later include a systemd? helper for checking if a Linux system uses systemd. https://docs.chef.io/workstation/cookstyle/chef_modernize_usecheflanguagesystemdhelper - 44:77 refactor: Chef/Modernize/UseChefLanguageSystemdHelper - Chef Infra Client 15.5 and later include a systemd? helper for checking if a Linux system uses systemd. https://docs.chef.io/workstation/cookstyle/chef_modernize_usecheflanguagesystemdhelper - 48:1 refactor: Chef/Modernize/ClassEvalActionClass - In Chef Infra Client 12.9 and later it is no longer necessary to call the class_eval method on the action class block. https://docs.chef.io/workstation/cookstyle/chef_modernize_classevalactionclass - 50:8 refactor: Chef/Modernize/UseChefLanguageSystemdHelper - Chef Infra Client 15.5 and later include a systemd? helper for checking if a Linux system uses systemd. https://docs.chef.io/workstation/cookstyle/chef_modernize_usecheflanguagesystemdhelper Signed-off-by: kitchen-porter --- CHANGELOG.md | 9 +++++++++ resources/compile.rb | 2 +- resources/install.rb | 2 +- resources/rules.rb | 2 +- resources/service.rb | 12 ++++++------ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cde87dc..528cad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ This file is used to list changes made in each version of the snort cookbook. ## Unreleased +- resolved cookstyle error: resources/compile.rb:72:1 refactor: `Chef/Modernize/ClassEvalActionClass` +- resolved cookstyle error: resources/install.rb:127:1 refactor: `Chef/Modernize/ClassEvalActionClass` +- resolved cookstyle error: resources/rules.rb:18:1 refactor: `Chef/Modernize/ClassEvalActionClass` +- resolved cookstyle error: resources/service.rb:5:26 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` +- resolved cookstyle error: resources/service.rb:18:77 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` +- resolved cookstyle error: resources/service.rb:30:26 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` +- resolved cookstyle error: resources/service.rb:44:77 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` +- resolved cookstyle error: resources/service.rb:48:1 refactor: `Chef/Modernize/ClassEvalActionClass` +- resolved cookstyle error: resources/service.rb:50:8 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` ## 5.0.2 - *2021-08-30* - Standardise files with files in sous-chefs/repo-management diff --git a/resources/compile.rb b/resources/compile.rb index 01e46bd..d39714a 100644 --- a/resources/compile.rb +++ b/resources/compile.rb @@ -69,7 +69,7 @@ end end -action_class.class_eval do +action_class do def daq_path "#{Chef::Config[:file_cache_path]}/daq" end diff --git a/resources/install.rb b/resources/install.rb index d3b2081..b2f8cfe 100644 --- a/resources/install.rb +++ b/resources/install.rb @@ -124,6 +124,6 @@ end end -action_class.class_eval do +action_class do include SnortCookbook::Helpers end diff --git a/resources/rules.rb b/resources/rules.rb index ace3b6e..4dac265 100644 --- a/resources/rules.rb +++ b/resources/rules.rb @@ -15,7 +15,7 @@ end end -action_class.class_eval do +action_class do def rules_url return new_resource.override_url unless new_resource.override_url.nil? diff --git a/resources/service.rb b/resources/service.rb index d0413e9..a7a5ae3 100644 --- a/resources/service.rb +++ b/resources/service.rb @@ -2,7 +2,7 @@ action :start do create_init - cleanup_old_service if node['init_package'] == 'systemd' + cleanup_old_service if systemd? service svc_name do supports status: true, restart: true @@ -15,7 +15,7 @@ supports status: true action :stop only_if { ::File.exist?("/etc/init/#{svc_name}.conf") } if node['init_package'] == 'init' - only_if { ::File.exist?("/etc/systemd/system/#{svc_name}.service") } if node['init_package'] == 'systemd' + only_if { ::File.exist?("/etc/systemd/system/#{svc_name}.service") } if systemd? end end @@ -27,7 +27,7 @@ end action :enable do - cleanup_old_service if node['init_package'] == 'systemd' + cleanup_old_service if systemd? create_init service svc_name do @@ -41,13 +41,13 @@ supports status: true action :disable only_if { ::File.exist?("/etc/init/tomcat_#{new_resource.instance_name}.conf") } if node['init_package'] == 'init' - only_if { ::File.exist?("/etc/systemd/system/#{svc_name}.service") } if node['init_package'] == 'systemd' + only_if { ::File.exist?("/etc/systemd/system/#{svc_name}.service") } if systemd? end end -action_class.class_eval do +action_class do def create_init - if node['init_package'] == 'systemd' + if systemd? execute 'Load systemd unit file' do command 'systemctl daemon-reload' From ba9b79fad22f26990a97fb23408f1e220e6988ff Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 17 Feb 2022 11:20:05 +0000 Subject: [PATCH 2/3] Update tested platforms and add unified_mode Signed-off-by: Dan Webb --- .github/workflows/ci.yml | 51 ++++++++++++------------------------- .overcommit.yml | 4 --- CHANGELOG.md | 2 ++ kitchen.dokken.yml | 55 +++++++++++++++++++++++++++------------- kitchen.yml | 23 +++++++++++------ metadata.rb | 2 +- resources/compile.rb | 2 ++ resources/config.rb | 2 ++ resources/install.rb | 20 ++------------- resources/rules.rb | 2 ++ resources/service.rb | 2 ++ 11 files changed, 81 insertions(+), 84 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ebd11f..cd4a1e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,49 +4,30 @@ name: ci "on": pull_request: push: - branches: - - main + branches: [main] jobs: - delivery: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v2 - - name: Run Chef Delivery - uses: actionshub/chef-delivery@main - env: - CHEF_LICENSE: accept-no-persist - - yamllint: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v2 - - name: Run yaml Lint - uses: actionshub/yamllint@main - - mdl: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v2 - - name: Run Markdown Lint - uses: actionshub/markdownlint@main + lint-unit: + uses: sous-chefs/.github/.github/workflows/lint-unit.yml@0.0.3 integration: - needs: [mdl, yamllint, delivery] + needs: lint-unit runs-on: ubuntu-latest strategy: matrix: os: - - 'debian-8' - - 'debian-9' - - 'centos-7' - - 'ubuntu-1604' - - 'ubuntu-1804' - suite: - - 'default' + - almalinux-8 + - amazonlinux-2 + - centos-7 + - centos-stream-8 + - debian-10 + - debian-11 + - fedora-latest + - opensuse-leap-15 + - rockylinux-8 + - ubuntu-1804 + - ubuntu-2004 + suite: [default] fail-fast: false steps: diff --git a/.overcommit.yml b/.overcommit.yml index 1d27ed8..cd8682a 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -11,10 +11,6 @@ PreCommit: enabled: true required_executable: 'cookstyle' command: ["cookstyle"] - Delivery: - enabled: true - required_executable: 'delivery' - flags: ['local', 'all'] CommitMsg: HardTabs: enabled: true diff --git a/CHANGELOG.md b/CHANGELOG.md index ae2753a..974061f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ This file is used to list changes made in each version of the snort cookbook. - resolved cookstyle error: resources/service.rb:44:77 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` - resolved cookstyle error: resources/service.rb:48:1 refactor: `Chef/Modernize/ClassEvalActionClass` - resolved cookstyle error: resources/service.rb:50:8 refactor: `Chef/Modernize/UseChefLanguageSystemdHelper` +- Update tested platforms +- Enable unified_mode ## 5.0.3 - *2022-02-08* diff --git a/kitchen.dokken.yml b/kitchen.dokken.yml index 9803344..16b534c 100644 --- a/kitchen.dokken.yml +++ b/kitchen.dokken.yml @@ -2,46 +2,65 @@ driver: name: dokken privileged: true - chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> - env: [CHEF_LICENSE=accept] transport: name: dokken provisioner: name: dokken - deprecations_as_errors: true platforms: - - name: debian-8 + - name: almalinux-8 driver: - image: dokken/debian-8 + image: dokken/almalinux-8 + pid_one_command: /usr/lib/systemd/systemd + + - name: amazonlinux-2 + driver: + image: dokken/amazonlinux-2 + pid_one_command: /usr/lib/systemd/systemd + + - name: debian-10 + driver: + image: dokken/debian-10 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - name: debian-9 + - name: debian-11 driver: - image: dokken/debian-9 + image: dokken/debian-11 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - name: centos-7 driver: image: dokken/centos-7 pid_one_command: /usr/lib/systemd/systemd - - name: ubuntu-16.04 + - name: centos-stream-8 driver: - image: dokken/ubuntu-16.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update + image: dokken/centos-stream-8 + pid_one_command: /usr/lib/systemd/systemd + + - name: fedora-latest + driver: + image: dokken/fedora-latest + pid_one_command: /usr/lib/systemd/systemd - name: ubuntu-18.04 driver: image: dokken/ubuntu-18.04 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update + + - name: ubuntu-20.04 + driver: + image: dokken/ubuntu-20.04 + pid_one_command: /bin/systemd + + - name: opensuse-leap-15 + driver: + image: dokken/opensuse-leap-15 + pid_one_command: /usr/lib/systemd/systemd + + - name: rockylinux-8 + driver: + image: dokken/rockylinux-8 + pid_one_command: /usr/lib/systemd/systemd diff --git a/kitchen.yml b/kitchen.yml index 0310841..b642f28 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -3,22 +3,29 @@ driver: name: vagrant provisioner: - name: chef_zero + name: chef_infra + deprecations_as_errors: true + chef_license: accept product_name: chef product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> - install_strategy: once - deprecations_as_errors: true + install_strategy: always + chef_log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> verifier: name: inspec platforms: + - name: almalinux-8 + - name: amazonlinux-2 - name: centos-7 - - name: debian-8 - - name: debian-9 - - name: fedora-27 - - name: ubuntu-14.04 - - name: ubuntu-16.04 + - name: centos-stream-8 + - name: debian-10 + - name: debian-11 + - name: fedora-latest + - name: opensuse-leap-15 + - name: rockylinux-8 + - name: ubuntu-18.04 + - name: ubuntu-20.04 suites: - name: default diff --git a/metadata.rb b/metadata.rb index 8342bd6..c6b7980 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache-2.0' description 'Installs Snort IDS packages' version '5.0.3' -chef_version '>= 15.0' +chef_version '>= 15.5' source_url 'https://github.com/sous-chefs/snort' issues_url 'https://github.com/sous-chefs/snort/issues' diff --git a/resources/compile.rb b/resources/compile.rb index d39714a..1865bf3 100644 --- a/resources/compile.rb +++ b/resources/compile.rb @@ -1,3 +1,5 @@ +unified_mode true + property :daq_tar, String, required: true property :snort_tar, String, required: true property :snort_version, String, required: true diff --git a/resources/config.rb b/resources/config.rb index cf8781d..40f5e17 100644 --- a/resources/config.rb +++ b/resources/config.rb @@ -1,3 +1,5 @@ +unified_mode true + property :home_net, String, default: 'any' property :external_net, String, default: 'any' property :http_ports, String, default: '80,81,311,383,591,593,901,1220,1414,1741,1830,2301,2381,2809,3037,3128,3702,4343,4848,5250,6988,7000,7001,7144,7145,7510,7777,7779,8000,8008,8014,8028,8080,8085,8088,8090,8118,8123,8180,8181,8243,8280,8300,8800,8888,8899,9000,9060,9080,9090,9091,9443,9999,11371,34443,34444,41080,50002,55555' diff --git a/resources/install.rb b/resources/install.rb index b2f8cfe..4f47f66 100644 --- a/resources/install.rb +++ b/resources/install.rb @@ -1,21 +1,5 @@ -# -# Cookbook:: snort -# Resource:: install -# -# Copyright:: 2010-2017, Chef Software, Inc -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# +unified_mode true + property :database, String, equal_to: %w(none snort-mysql postgresql pgsql postgres), name_property: true property :home_net, [String, nil], default: lazy { case node['platform_family'] diff --git a/resources/rules.rb b/resources/rules.rb index 4dac265..1c11deb 100644 --- a/resources/rules.rb +++ b/resources/rules.rb @@ -1,3 +1,5 @@ +unified_mode true + property :oinkcode, [String, nil] # Supply this to download registered/subscriber rules property :tar_name, String, default: 'community-rules.tar.gz' # Override this if you have an Oink code and know the tar you want to download property :conf_dir, String, default: '/etc/snort' diff --git a/resources/service.rb b/resources/service.rb index a7a5ae3..adc9346 100644 --- a/resources/service.rb +++ b/resources/service.rb @@ -1,3 +1,5 @@ +unified_mode true + property :options, Array, default: ['-q'] action :start do From 1f3e09f36f0b4238b3501586e2e2b2ffaa466aca Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Thu, 17 Feb 2022 11:30:42 +0000 Subject: [PATCH 3/3] Cookstyle fix Signed-off-by: Dan Webb --- spec/unit/recipes/default_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index af6c847..c884a30 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe 'Snort Install on Debian 8' do - let(:runner) { ChefSpec::ServerRunner.new(platform: 'debian', version: '8', step_into: ['snort_install']) } + let(:runner) { ChefSpec::ServerRunner.new(platform: 'debian', step_into: ['snort_install']) } it 'converges successfully' do expect { :chef_run }.to_not raise_error