-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add: standalone plugin for evaluating dependencies with a graph #774
base: main
Are you sure you want to change the base?
Conversation
Conventional Commits Report
🚀 Conventional commits found. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #774 +/- ##
==========================================
+ Coverage 79.82% 80.00% +0.17%
==========================================
Files 87 88 +1
Lines 3023 3215 +192
Branches 589 613 +24
==========================================
+ Hits 2413 2572 +159
- Misses 462 485 +23
- Partials 148 158 +10 ☔ View full report in Codecov by Sentry. |
Dependency ReviewThe following issues were found:
Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. License Issuespoetry.lock
pyproject.toml
Allowed Licenses: 0BSD, AGPL-3.0-or-later, Apache-2.0, BlueOak-1.0.0, BSD-2-Clause, BSD-3-Clause-Clear, BSD-3-Clause, BSL-1.0, CAL-1.0, CC-BY-3.0, CC-BY-4.0, CC-BY-SA-4.0, CC0-1.0, EPL-2.0, GPL-2.0-only, GPL-2.0-or-later, GPL-2.0, GPL-3.0-or-later, ISC, LGPL-2.0-only, LGPL-2.0-or-later, LGPL-2.1-only, LGPL-2.1-or-later, LGPL-2.1, LGPL-3.0-only, LGPL-3.0, LGPL-3.0-or-later, MIT, MIT-CMU, MPL-1.1, MPL-2.0, OFL-1.1, PSF-2.0, Python-2.0, Python-2.0.1, Unicode-DFS-2016, Unlicense OpenSSF Scorecard
Scanned Files
|
5c1c5e8
to
e3ab622
Compare
This reverts commit 2d9a86f.
f43bc1f
to
63c0f64
Compare
class Script: | ||
name: str | ||
feed: str | ||
dependencies: list[tuple[str, bool]] # (dependency_name, is_gated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dependencies: list[tuple[str, bool]] # (dependency_name, is_gated) | |
dependencies: set[tuple[str, bool]] # (dependency_name, is_gated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a set would interfere with the current check_duplicates. Would require checking for duplicate dependencies during setup, rather than afterwards with the other checks. Or store duplicates in some other way.
has_errors = any(result.has_errors() for result in results) | ||
has_warnings = any(result.has_warnings() for result in results) | ||
|
||
if has_errors: | ||
return 1 | ||
elif has_warnings: | ||
return 2 | ||
else: | ||
return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has_errors = any(result.has_errors() for result in results) | |
has_warnings = any(result.has_warnings() for result in results) | |
if has_errors: | |
return 1 | |
elif has_warnings: | |
return 2 | |
else: | |
return 0 | |
if any(result.has_errors() for result in results): | |
return 1 | |
elif any(result.has_warnings() for result in results): | |
return 2 | |
else: | |
return 0 |
Can be inlined
parser.add_argument( | ||
"--feed", | ||
choices=["21.04", "22.04", "common", "full"], | ||
default="full", | ||
help="feed", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/howto/enum.html#flag
Good example for Flags I think
parser.add_argument( | ||
"root", | ||
type=directory_type, | ||
help="directory that should be linted", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parser.add_argument( | |
"root", | |
type=directory_type, | |
help="directory that should be linted", | |
) | |
parser.add_argument( | |
"root", | |
type=directory_type, | |
help="directory that should be linted", | |
) |
can be defaulted to the VTDIR
environment variable, which is used by convention by nasl devs
VTCategory, | ||
) | ||
|
||
EXTENSIONS = (".nasl",) # not sure if inc files can also have dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think so, but worth a question to the core members I think
case _: | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case _: | |
return [] | |
case _: | |
raise <Some Exception> |
Should raise an Error, since none of the proper values were found
|
||
def get_scripts(directory) -> list[Script]: | ||
scripts = [] | ||
# use path glob? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an example in troubadix with glob
files = root.rglob("*.nasl") |
def split_dependencies(value: str) -> list[str]: | ||
""" | ||
removes blank lines, strips comments, cleans dependencies, | ||
splits them by commas, and excludes empty strings. | ||
""" | ||
return [ | ||
dep | ||
for line in value.splitlines() | ||
if line.strip() # Ignore blank or whitespace-only lines | ||
# ignore comment, clean line of unwanted chars, split by ',' | ||
for dep in re.sub(r'[\'"\s]', "", line.split("#", 1)[0]).split(",") | ||
if dep # Include only non-empty | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be encapsulated in the check_dependencies
check and then imported.
My original code isnt good to begin with, having it duplicated only increases the mess
checks for a script depending on a script multiple times | ||
""" | ||
warnings = [] | ||
for script in scripts: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to come back to this, reminder to myself
|
||
|
||
def cross_feed_dependencies(graph, gated_status: bool) -> list[tuple[str, str]]: | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to come back to this
What
Adds a standalone plugin for evaluating script dependencies with a directed networkx graph.
checks for:
included functionality of normal plugins
Output
python logging levels for system information (
error
,warning
,info
)normal additive verbosity up to
-vv
for result output.Feed options
example call:
poetry run troubadix-dependency-graph ~/gb/vulnerability-tests/nasl --feed full --log info -vv
Execution Time
locally ~13 seconds
Why
When checking dependencies, it makes sense to analyse the whole feed, rather than just working on changed scripts. And working on the whole feed is easier with a standalone plugin that doesn't have to adhere to the Troubadix structure.
References
Checklist