Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(template): review PRs 212 & 223 (inc. preparing for propagation) #292

Merged
merged 4 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions ssf/config/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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] }}:
Expand Down Expand Up @@ -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 %}
Expand Down
6 changes: 3 additions & 3 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
11 changes: 11 additions & 0 deletions ssf/files/default/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ celerybeat-schedule
venv/
ENV/

# visual studio
.vs/

# Spyder project settings
.spyderproject
.spyproject
Expand Down Expand Up @@ -120,3 +123,11 @@ docs/*.md
Dockerfile.*_*
ignore/
tmp/

# `salt-formula` -- Vagrant Specific files
.vagrant
top.sls

# `suricata-formula` -- Platform binaries
*.rpm
*.deb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
126 changes: 0 additions & 126 deletions ssf/files/tofs_salt-formula/.gitignore

This file was deleted.

126 changes: 0 additions & 126 deletions ssf/files/tofs_suricata-formula/.gitignore

This file was deleted.

3 changes: 2 additions & 1 deletion ssf/formulas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down