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

Updated get_hostnames function to ignore comments. #1169

Merged
merged 2 commits into from
May 31, 2024

Conversation

David-M-Berry
Copy link
Contributor

@David-M-Berry David-M-Berry commented May 28, 2024

host_search.py update

Updated get_hostnames function to ignore comments in hostname files.

  • Enhancement
  • Updated unit tests
  • Code sample

Unit test coverage

unit tests do not appear to currently cover samples

Bandit analysis

[main]	INFO	profile include tests: None
[main]	INFO	profile exclude tests: None
[main]	INFO	cli include tests: None
[main]	INFO	cli exclude tests: None
[main]	INFO	running on Python 3.11.7
Working... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
Run started:2024-05-28 17:32:34.545861

Test results:
	No issues identified.

Code scanned:
	Total lines of code: 66789
	Total lines skipped (#nosec): 0

Run metrics:
	Total issues (by severity):
		Undefined: 0
		Low: 0
		Medium: 0
		High: 0
	Total issues (by confidence):
		Undefined: 0
		Low: 0
		Medium: 0
		High: 0
Files skipped (0):

Formatting
--------------------------------------------------------
0

Code style and syntax
--------------------------------------------------------
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.BaseException' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.Exception' ?) instead.

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Docstring style and syntax
--------------------------------------------------------

Added features and functionality

  • the get_hostnames function will now ignore comments and whitespace that exist in any text file passed via the command line.

Issues resolved

  • Bug fix:

Other

  • Documentation:

This is a relatively simple change to the get_hostnames function. By splitting a line from any comment (in case a comment is included after a valid hostname entry on the same line), and removing any whitespace, we can ensure the output.csv file does not contain any unintended results.

            hostnames = []
            for line in host_file:
                line = line.split('#')[0].strip()  # Remove comments and strip whitespace
                if line:  # Ignore empty lines
                    hostnames.append(line)

Updated code is here for reference: https://github.com/David-M-Berry/falconpy/blob/main/samples/hosts/host_search.py

@jshcodes jshcodes added enhancement 🌟 New feature or request code samples Functioning sample code to get you started hosts Hosts or Host Groups issues and questions labels May 28, 2024
@jshcodes jshcodes added the bug 🐛 Something isn't working label May 28, 2024
Copy link
Member

@jshcodes jshcodes left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! 🙇 🚀

@jshcodes jshcodes merged commit bc3fbe8 into CrowdStrike:samples May 31, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working code samples Functioning sample code to get you started enhancement 🌟 New feature or request hosts Hosts or Host Groups issues and questions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants