Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-gb committed Jul 1, 2024
1 parent 61cc5f0 commit 564bd8b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
10 changes: 6 additions & 4 deletions tests/standalone_plugins/test_deprecate_vts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2024 Greenbone AG
# pylint: disable=line-too-long
# pylint: disable=protected-access
import unittest
from pathlib import Path
from tests.plugins import TemporaryDirectory
Expand All @@ -9,8 +10,8 @@
deprecate,
parse_args,
DeprecatedFile,
get_summary,
finalize_content,
_get_summary,
_finalize_content,
update_summary,
get_files,
)
Expand Down Expand Up @@ -123,7 +124,7 @@ def test_deprecate_kb_item(self):
)

def test_get_summary(self):
result = get_summary(NASL_CONTENT)
result = _get_summary(NASL_CONTENT)
expected = (
"The remote host is missing an update for the 'gd'\n package(s) "
"announced "
Expand All @@ -132,7 +133,8 @@ def test_get_summary(self):
self.assertEqual(result, expected)

def test_finalize_content(self):
result = finalize_content(NASL_CONTENT)

result = _finalize_content(NASL_CONTENT)
expected = (
'...if(description)\n{\n script_oid("1.3.6.1.4.1.25623.1.0.910673");\n '
'script_version("2024-03-12T14:15:13+0000");\n script_name("RedHat: Security Advisory for gd (RHSA-2020:5443-01)");\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");\n\n script_xref(name:"RHSA", value:"2020:5443-01");\n script_xref(name:"URL", value:"https://www.redhat.com/archives/rhsa-announce/2020-December/msg00044.html");\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");\n\n script_tag(name:"deprecated", value:TRUE);\n\nexit(0);\n}\n\nexit(66);\n'
Expand Down
40 changes: 24 additions & 16 deletions troubadix/standalone_plugins/deprecate_vts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path
from typing import Iterable, Optional

from troubadix.argparser import file_type
from troubadix.argparser import file_type, directory_type
from troubadix.helper.patterns import (
get_special_script_tag_pattern,
get_script_tag_pattern,
Expand Down Expand Up @@ -54,7 +54,7 @@ def update_summary(file: DeprecatedFile, deprecation_reason: str) -> str:
if deprecation_reason == "duplicate":
deprecate_text = "as a duplicate."

old_summary = get_summary(file.content)
old_summary = _get_summary(file.content)
if old_summary:
new_summary = old_summary + "\n" + deprecate_text
file.content = file.content.replace(old_summary, new_summary)
Expand Down Expand Up @@ -169,7 +169,7 @@ def deprecate(
)
continue
file.content = update_summary(file, deprecation_reason)
file.content = finalize_content(file.content)
file.content = _finalize_content(file.content)

# Drop any unnecessary script tags like script_dependencies(),
# script_require_udp_ports() or script_mandatory_keys()
Expand Down Expand Up @@ -211,19 +211,10 @@ def parse_args(args: Iterable[str] = None) -> Namespace:
"-o",
"--output-path",
metavar="<output_path>",
type=str,
type=directory_type,
required=True,
help="Path where the deprecated files should be written to.",
)
parser.add_argument(
"-f",
"--files",
metavar="<files>",
nargs="*",
default=None,
type=file_type,
help="Files to deprecate",
)
parser.add_argument(
"-i",
"--input-path",
Expand All @@ -244,7 +235,7 @@ def parse_args(args: Iterable[str] = None) -> Namespace:
"for example 'gb_rhsa_2021' to filter on the year",
)
parser.add_argument(
"-d",
"-r",
"--deprecation-reason",
metavar="<deprecation_reason>",
choices=["notus", "merged", "duplicate", "defunct"],
Expand All @@ -255,6 +246,24 @@ def parse_args(args: Iterable[str] = None) -> Namespace:
"a still active duplicate, 'defunct': The VT is no longer "
"functional.",
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
"-f",
"--files",
metavar="<files>",
nargs="*",
default=None,
type=file_type,
help="Files to deprecate",
)
group.add_argument(
"-i",
"--input-path",
metavar="<input_path>",
default=None,
type=directory_type,
help="Path to the existing nasl script directory",
)
return parser.parse_args(args)


Expand All @@ -263,8 +272,7 @@ def main():
output_path = Path(args.output_path)
input_path = Path(args.input_path) if args.input_path else None
single_file = Path(args.file) if args.file else None
deprecation_reason = args.deprecation_reason
filename_prefix = args.filename_prefix if args.filename_prefix else None
filename_prefix = args.filename_prefix

if not input_path and not single_file:
raise PathException(
Expand Down

0 comments on commit 564bd8b

Please sign in to comment.