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

Filter active controls in profile by tags #5596

Merged
merged 3 commits into from Jul 28, 2021
Merged

Conversation

Nik08
Copy link
Contributor

@Nik08 Nik08 commented Jul 9, 2021

Signed-off-by: Nikita Mathur nikita.mathur@chef.io

Filtering active controls in profile by tags.

Description

Similar to the feature of filtering controls using --controls, a new option --tags was required which could be used for passing the tags names of controls and filtering them.

Solution

  1. --tags option is introduced.
  2. Fetched control tags using method control_tags.
  3. Filtered controls by using tags that are passed through option --tags to match with control tags using method tag_exist_in_control_tags?

Needs Suggestion (Code Refactoring)

The method introduced to get controls tags is using block of control which is in string format. Tags are fetched from this string using regex and string manipulation.

Though it works successfully on all the cases of ways and formats a tag can be used, as used in this testing control. A better solution could be easier to understand.

Related Issue

Closes #5447

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@Nik08 Nik08 self-assigned this Jul 9, 2021
@Nik08 Nik08 requested review from a team as code owners July 9, 2021 13:38
@netlify
Copy link

netlify bot commented Jul 9, 2021

✔️ Deploy Preview for chef-inspec canceled.

🔨 Explore the source changes: aeed833

🔍 Inspect the deploy log: https://app.netlify.com/sites/chef-inspec/deploys/60fe62f1e83d5000076fb902

@IanMadd
Copy link
Contributor

IanMadd commented Jul 13, 2021

Can tags be put in alphabetical order with the other items.

@@ -272,6 +272,8 @@ This subcommand has additional options:
Read configuration from JSON file (`-` reads from stdin).
* ``--controls=one two three``
A list of control names to run, or a list of /regexes/ to match against control names. Ignore all other tests.
* ``--tags=one two three``
A list of tags names that are part of controls to filter and run controls, or a list of /regexes/ to match against tags names of controls. Ignore all other tests. And when tag on the control is a hashmap, it only uses values of hashmap for filtering controls.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A list of tags names that are part of controls to filter and run controls, or a list of /regexes/ to match against tags names of controls. Ignore all other tests. And when tag on the control is a hashmap, it only uses values of hashmap for filtering controls.
A list of tags or a list of regular expressions that match tags. `exec` will run controls referenced by the listed or matching tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IanMadd I feel we should also include in doc that if tags are of type hash then it matches the value of an hash not a key to bring more clarity. I mentioned this sentence for that purpose "And when tag on the control is a hash map, it only uses values of hashmap for filtering controls." Can we put this in more clear way in doc ? What are your suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this:

A list of tags, a list of regular expressions that match tags, or a hash map where each value is a tag.
exec will run controls referenced by the listed or matching tags.

@@ -379,6 +381,8 @@ This subcommand has additional options:

* ``--controls=one two three``
A list of controls to include. Ignore all other tests.
* ``--tags=one two three``
A list of tags to filter controls and include only those. Ignore all other tests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A list of tags to filter controls and include only those. Ignore all other tests.
A list of tags that reference certain controls. Other controls are ignored.

@Nik08
Copy link
Contributor Author

Nik08 commented Jul 14, 2021

Can tags be put in alphabetical order with the other items.

@IanMadd I am a little confused can you elaborate this? What do you mean by putting it in alphabetical order?

@IanMadd
Copy link
Contributor

IanMadd commented Jul 15, 2021

On the cli page all the flags are in alphabetical order except the --tags that you're adding.

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
Copy link
Contributor

@IanMadd IanMadd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@IanMadd IanMadd added the Documentation ZH multi-repo label for the docs-team label Jul 19, 2021
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
@sonarcloud
Copy link

sonarcloud bot commented Jul 26, 2021

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
30.6% 30.6% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter Active Controls in Profile by Tag
3 participants