From 3c8202d0982705b28449c7f0e016610b5102291a Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 11 Feb 2021 09:33:52 +0000 Subject: [PATCH 1/4] feat(template): review PR 223 * https://github.com/saltstack-formulas/template-formula/pull/223 --- ssf/defaults.yaml | 4 ++-- ssf/files/default/.gitignore | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index 415a61a5..de0e30eb 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -62,8 +62,8 @@ ssf_node_anchors: # An alternative method could be to use: # `git describe --abbrev=0 --tags` # yamllint disable rule:line-length rule:quoted-strings - title: "chore: standardise structure [skip ci]" - body: '* Automated using https://github.com/myii/ssf-formula/pull/291' + title: "chore: standardise structure ('`'.gitignore'`' & '`'_mapdata.rb'`') [skip ci]" + body: '* Automated using https://github.com/myii/ssf-formula/pull/292' # yamllint enable rule:line-length rule:quoted-strings github: owner: 'saltstack-formulas' diff --git a/ssf/files/default/.gitignore b/ssf/files/default/.gitignore index 6995110e..499071a4 100644 --- a/ssf/files/default/.gitignore +++ b/ssf/files/default/.gitignore @@ -91,6 +91,9 @@ celerybeat-schedule venv/ ENV/ +# visual studio +.vs/ + # Spyder project settings .spyderproject .spyproject From 4b828db9a868648c07dbae143bce86b3e28f1d5e Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 11 Feb 2021 10:32:26 +0000 Subject: [PATCH 2/4] feat(gitignore): standardise across all formulas Use `:r! find ssf/files/ -name .gitignore` to locate all of the templates to merge. --- ssf/files/default/.gitignore | 8 ++ ssf/files/tofs_salt-formula/.gitignore | 126 --------------------- ssf/files/tofs_suricata-formula/.gitignore | 126 --------------------- 3 files changed, 8 insertions(+), 252 deletions(-) delete mode 100644 ssf/files/tofs_salt-formula/.gitignore delete mode 100644 ssf/files/tofs_suricata-formula/.gitignore diff --git a/ssf/files/default/.gitignore b/ssf/files/default/.gitignore index 499071a4..94f77a85 100644 --- a/ssf/files/default/.gitignore +++ b/ssf/files/default/.gitignore @@ -123,3 +123,11 @@ docs/*.md Dockerfile.*_* ignore/ tmp/ + +# `salt-formula` -- Vagrant Specific files +.vagrant +top.sls + +# `suricata-formula` -- Platform binaries +*.rpm +*.deb diff --git a/ssf/files/tofs_salt-formula/.gitignore b/ssf/files/tofs_salt-formula/.gitignore deleted file mode 100644 index 4b45182d..00000000 --- a/ssf/files/tofs_salt-formula/.gitignore +++ /dev/null @@ -1,126 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a packager -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.kitchen -.kitchen.local.yml -kitchen.local.yml -junit-*.xml - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# dotenv -.env - -# virtualenv -.venv -venv/ -ENV/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - -# Bundler -.bundle/ - -# copied `.md` files used for conversion to `.rst` using `m2r` -docs/*.md - -# Vim -*.sw? - -## Collected when centralising formulas (check and sort) -# `collectd-formula` -.pytest_cache/ -/.idea/ -Dockerfile.*_* -ignore/ -tmp/ - -#Vagrant Specific files -.vagrant -top.sls diff --git a/ssf/files/tofs_suricata-formula/.gitignore b/ssf/files/tofs_suricata-formula/.gitignore deleted file mode 100644 index db9cf846..00000000 --- a/ssf/files/tofs_suricata-formula/.gitignore +++ /dev/null @@ -1,126 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a packager -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.kitchen -.kitchen.local.yml -kitchen.local.yml -junit-*.xml - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# dotenv -.env - -# virtualenv -.venv -venv/ -ENV/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - -# Bundler -.bundle/ - -# copied `.md` files used for conversion to `.rst` using `m2r` -docs/*.md - -# Vim -*.sw? - -## Collected when centralising formulas (check and sort) -# `collectd-formula` -.pytest_cache/ -/.idea/ -Dockerfile.*_* -ignore/ -tmp/ - -# Platform binaries -*.rpm -*.deb From 5b5d679f5ee1a951a88f66df3994c34e561327fa Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 11 Feb 2021 10:36:46 +0000 Subject: [PATCH 3/4] feat(template): review PR 212 * https://github.com/saltstack-formulas/template-formula/pull/212 Use `:r! grep -riIn _mapdata_spec` to locate all of the lines to be adjusted. Then fix with `%s:_mapdata_spec.rb:_mapdata.rb:` (check changes carefully afterwards). Use `:r! find ssf/files/ -name _mapdata_spec.rb` to locate all of the templates to rename and adjust. --- pillar.example | 2 +- ssf/config/formulas.sls | 4 ++-- ssf/defaults.yaml | 2 +- .../default/inspec/controls/{_mapdata_spec.rb => _mapdata.rb} | 4 ++-- ssf/formulas.yaml | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) rename ssf/files/default/inspec/controls/{_mapdata_spec.rb => _mapdata.rb} (95%) diff --git a/pillar.example b/pillar.example index 9fedd5d2..a0c718be 100644 --- a/pillar.example +++ b/pillar.example @@ -182,7 +182,7 @@ ssf: - formula/_mapdata/init.sls - formula/libsaltcli.jinja - formula/libtofs.jinja - - inspec/controls/_mapdata_spec.rb + - inspec/controls/_mapdata.rb - inspec/libraries/system.rb - inspec/inspec.yml - inspec/README.md diff --git a/ssf/config/formulas.sls b/ssf/config/formulas.sls index 3cd6e1b2..c6cdb0bb 100644 --- a/ssf/config/formulas.sls +++ b/ssf/config/formulas.sls @@ -84,10 +84,10 @@ prepare-git-branch-for-{{ formula }}: {#- Do not manage the file in the following situations: #} {#- - If a matching test suite isn't found #} {#- - Or if `libraries/system.rb` and is not the `share` suite #} -{#- - Or if `controls/_mapdata_spec.rb` and is the `share` suite #} +{#- - Or if `controls/_mapdata.rb` and is the `share` suite #} {%- if (not matching_test_suite.found) or (dest_file == 'libraries/system.rb' and suite.name != 'share') or - (dest_file == 'controls/_mapdata_spec.rb' and suite.name == 'share') + (dest_file == 'controls/_mapdata.rb' and suite.name == 'share') %} {%- set dest_file = '' %} {%- else %} diff --git a/ssf/defaults.yaml b/ssf/defaults.yaml index de0e30eb..821c791f 100644 --- a/ssf/defaults.yaml +++ b/ssf/defaults.yaml @@ -25,7 +25,7 @@ ssf_node_anchors: - '/*/_mapdata/': '@saltstack-formulas/ssf' - '/*/libsaltcli.jinja': '@saltstack-formulas/ssf' - '/*/libtofs.jinja': '@saltstack-formulas/ssf' - - '/test/integration/**/_mapdata_spec.rb': '@saltstack-formulas/ssf' + - '/test/integration/**/_mapdata.rb': '@saltstack-formulas/ssf' - '/test/integration/**/libraries/system.rb': '@saltstack-formulas/ssf' - '/test/integration/**/inspec.yml': '@saltstack-formulas/ssf' - '/test/integration/**/README.md': '@saltstack-formulas/ssf' diff --git a/ssf/files/default/inspec/controls/_mapdata_spec.rb b/ssf/files/default/inspec/controls/_mapdata.rb similarity index 95% rename from ssf/files/default/inspec/controls/_mapdata_spec.rb rename to ssf/files/default/inspec/controls/_mapdata.rb index 64635323..e95298cc 100644 --- a/ssf/files/default/inspec/controls/_mapdata_spec.rb +++ b/ssf/files/default/inspec/controls/_mapdata.rb @@ -2,8 +2,8 @@ require 'yaml' -control '`map.jinja` YAML dump' do - title 'should match the comparison file' +control '{{ semrel_formula }}._mapdata' do + title '`map.jinja` should match the reference file' ### Method # The steps below for each file appear convoluted but they are both required diff --git a/ssf/formulas.yaml b/ssf/formulas.yaml index dc6c6c5a..01a0b695 100644 --- a/ssf/formulas.yaml +++ b/ssf/formulas.yaml @@ -745,8 +745,9 @@ ssf_node_anchors: formula/_mapdata/init.sls: &file__formula___mapdata___init--sls <<: *file_default template: 'mako' - inspec/controls/_mapdata_spec.rb: &file__inspec__controls___mapdata_spec--rb + inspec/controls/_mapdata.rb: &file__inspec__controls___mapdata--rb <<: *file_default + template: 'jinja' inspec/libraries/system.rb: &file__inspec__libraries__system--rb <<: *file_default From 327a29e1209e52c8431c022ca1867205ec3c34d3 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Thu, 11 Feb 2021 10:45:47 +0000 Subject: [PATCH 4/4] feat(formulas): remove file at previous location (`_mapdata_spec.rb`) --- ssf/config/formulas.sls | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ssf/config/formulas.sls b/ssf/config/formulas.sls index c6cdb0bb..c54f50fc 100644 --- a/ssf/config/formulas.sls +++ b/ssf/config/formulas.sls @@ -120,6 +120,22 @@ prepare-git-branch-for-{{ formula }}: {%- set add_or_rm = ['rm', 'remove', 'absent'] %} {%- endif %} +{#- Pre-Stage 2: Remove previous file location, where applicable #} +{#- Nothing to remove by default #} +{%- set prev_dest = '' %} +{#- Scenario 01: `_mapdata.rb` was originally `_mapdata_spec.rb` #} +{%- if semrel_file == 'inspec/controls/_mapdata.rb' %} +{%- set prev_dest = dest.replace('_mapdata.rb', '_mapdata_spec.rb') %} +{%- endif %} +{#- Only run this state if a `prev_dest` has been identified #} +{%- if prev_dest %} +remove-previous-file-location-for-{{ formula }}-{{ dest_file }}: + file.absent: + - name: {{ prev_dest }} + - require_in: + - file: {{ add_or_rm[1] }}-{{ formula }}-{{ dest_file }} +{%- endif %} + {#- Stage 2: Add or remove the file as necessary #} {{ add_or_rm[1] }}-{{ formula }}-{{ dest_file }}: file.{{ add_or_rm[2] }}: @@ -172,6 +188,11 @@ prepare-git-branch-for-{{ formula }}: {%- if ssf.git.states.add_rm.active %} cmd.run: - name: | + {#- `git` command for `Pre-Stage 2` #} + {%- if prev_dest %} + git rm {{ prev_dest }} + {%- endif %} + {#- `git` command for `Stage 2` #} git {{ add_or_rm[0] }} {{ dest_file }} - cwd: {{ ssf.formulas_path }}/{{ formula }}/ {%- if running_as_root %}