troubadix 24.9.4__py3-none-any.whl → 24.10.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
troubadix/__version__.py CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  # THIS IS AN AUTOGENERATED FILE. DO NOT TOUCH!
4
4
 
5
- __version__ = "24.9.4"
5
+ __version__ = "24.10.1"
@@ -18,6 +18,7 @@
18
18
  from typing import Iterable, List
19
19
 
20
20
  from troubadix.plugin import FilePlugin, FilesPlugin, Plugin
21
+ from troubadix.plugins.spaces_before_dots import CheckSpacesBeforeDots
21
22
 
22
23
  from .badwords import CheckBadwords
23
24
  from .copyright_text import CheckCopyrightText
@@ -140,6 +141,7 @@ _FILE_PLUGINS = [
140
141
  CheckVTFilePermissions,
141
142
  CheckVTPlacement,
142
143
  CheckWrongSetGetKBCalls,
144
+ CheckSpacesBeforeDots,
143
145
  ]
144
146
 
145
147
  # plugins checking all files
@@ -64,7 +64,7 @@ class CheckScriptXrefUrl(FileContentPlugin):
64
64
  for match in matches:
65
65
  if match:
66
66
  if match.group("value") not in ALLOWED_URLS and not url(
67
- match.group("value")
67
+ match.group("value"), strict_query=False
68
68
  ):
69
69
  yield LinterError(
70
70
  f"{match.group(0)}: Invalid URL value",
@@ -0,0 +1,130 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ # SPDX-FileCopyrightText: 2024 Greenbone AG
3
+ import re
4
+ from collections.abc import Iterator
5
+ from pathlib import Path
6
+
7
+ from troubadix.helper import CURRENT_ENCODING
8
+ from troubadix.helper.helper import is_ignore_file
9
+ from troubadix.helper.patterns import (
10
+ ScriptTag,
11
+ get_script_tag_pattern,
12
+ )
13
+ from troubadix.plugin import (
14
+ FileContentPlugin,
15
+ LinterFix,
16
+ LinterResult,
17
+ LinterWarning,
18
+ )
19
+
20
+ TAGS = [
21
+ ScriptTag.SUMMARY,
22
+ ScriptTag.VULDETECT,
23
+ ScriptTag.INSIGHT,
24
+ ScriptTag.IMPACT,
25
+ ScriptTag.AFFECTED,
26
+ ScriptTag.SOLUTION,
27
+ ]
28
+
29
+ # Regex pattern to match:
30
+ # 1. A dot preceded and/or followed by any whitespace character (floating between words)
31
+ # 2. A dot preceded by any whitespace character at the end of the string
32
+ PATTERN = re.compile(r"\s+\.(\s|$)")
33
+ IGNORE = [
34
+ # 21.04 and 22.04 are generated and should not be touched manually
35
+ "21.04/",
36
+ "22.04/",
37
+ # uses dots for beginning of entry in enumeration
38
+ "common/2008/debian/deb_246.nasl",
39
+ "common/2008/debian/deb_266.nasl",
40
+ "common/2008/freebsd/freebsd_5e92e8a2.nasl",
41
+ "common/2008/freebsd/freebsdsa_cpio.nasl",
42
+ "common/2008/freebsd/freebsdsa_cvs2.nasl",
43
+ "common/2009/osc_photoGallery_sql_injection.nasl",
44
+ "common/2009/secpod_novell_edir_mult_vuln_jul09_lin.nasl",
45
+ "common/2009/secpod_novell_edir_mult_vuln_jul09_win.nasl",
46
+ "common/2010/freebsd/freebsd_3a7c5fc4.nasl",
47
+ "common/2012/freebsd/freebsd_a4a809d8.nasl",
48
+ "common/2015/amazon/alas-2014-455.nasl",
49
+ "common/2015/gb_mozilla_firefox_mult_vuln01_mar15_macosx.nasl",
50
+ "common/2015/gb_mozilla_firefox_mult_vuln01_mar15_win.nasl",
51
+ "common/2015/oracle/ELSA-2009-1619.nasl",
52
+ "common/2015/oracle/ELSA-2011-0586.nasl",
53
+ "common/2016/gb_perl_privilege_escalation_vuln_win.nasl",
54
+ "common/2021/dropbear/gb_dropbear_ssh_filename_vuln_may20.nasl",
55
+ "common/2021/eclipse/gb_jetty_GHSA-v7ff-8wcx-gmc5_lin.nasl",
56
+ "common/2021/eclipse/gb_jetty_GHSA-v7ff-8wcx-gmc5_win.nasl",
57
+ "common/gsf/2009/mandriva/gb_mandriva_MDVSA_2008_140.nasl",
58
+ "common/gsf/2009/mandriva/gb_mandriva_MDVSA_2008_141.nasl",
59
+ "common/gsf/2010/mandriva/gb_mandriva_MDVA_2010_173.nasl",
60
+ "common/gsf/2010/mandriva/gb_mandriva_MDVSA_2010_155.nasl",
61
+ "common/gsf/2010/mandriva/gb_mandriva_MDVSA_2010_155_1.nasl",
62
+ "common/gsf/2010/mandriva/gb_mandriva_MDVSA_2010_167.nasl",
63
+ "common/gsf/2020/f5/gb_f5_big_ip_K11315080.nasl",
64
+ "common/gsf/2020/f5/gb_f5_big_iq_K11315080.nasl",
65
+ "common/2022/opensuse/gb_opensuse_2022_1548_1.nasl",
66
+ "common/2024/opensuse/gb_opensuse_2023_3247_1.nasl",
67
+ "common/attic/debian/deb_232_1.nasl",
68
+ ]
69
+
70
+
71
+ class CheckSpacesBeforeDots(FileContentPlugin):
72
+ name = "check_spaces_before_dots"
73
+
74
+ def check_content(
75
+ self, nasl_file: Path, file_content: str
76
+ ) -> Iterator[LinterResult]:
77
+ """
78
+ This plugin checks for excess whitespace before a dot
79
+ in script_tags that have full sentence values
80
+ """
81
+ self.matches = []
82
+ if nasl_file.suffix == ".inc" or is_ignore_file(nasl_file, IGNORE):
83
+ return
84
+ for tag in TAGS:
85
+ pattern = get_script_tag_pattern(tag)
86
+ match = pattern.search(file_content)
87
+ if not match:
88
+ continue
89
+
90
+ value = match.group("value")
91
+ value_start = match.start("value")
92
+
93
+ for excess_match in PATTERN.finditer(value):
94
+ whitespace_pos = excess_match.start() + value_start
95
+ self.matches.append((whitespace_pos, excess_match.group()))
96
+ fullmatch = match.group()
97
+ yield LinterWarning(
98
+ f"value of script_tag {match.group('name')} has at least"
99
+ " one occurence of excess whitespace before a dot:"
100
+ f"\n '{fullmatch}'",
101
+ file=nasl_file,
102
+ plugin=self.name,
103
+ )
104
+
105
+ def fix(self) -> Iterator[LinterResult]:
106
+
107
+ if not self.matches:
108
+ return
109
+
110
+ # Sort matches by position, descending order to avoid messing up indices during replacement
111
+ self.matches.sort(reverse=True)
112
+
113
+ file_content = self.context.file_content
114
+ for pos, match_str in self.matches:
115
+ # Replace the match by removing the excess whitespace before the dot
116
+ fixed_str = re.sub(r"\s+\.", ".", match_str)
117
+ file_content = (
118
+ file_content[:pos]
119
+ + fixed_str
120
+ + file_content[pos + len(match_str) :]
121
+ )
122
+
123
+ with open(self.context.nasl_file, "w", encoding=CURRENT_ENCODING) as f:
124
+ f.write(file_content)
125
+
126
+ yield LinterFix(
127
+ "Excess spaces were removed",
128
+ file=self.context.nasl_file,
129
+ plugin=self.name,
130
+ )
@@ -2,12 +2,14 @@
2
2
  # SPDX-FileCopyrightText: 2024 Greenbone AG
3
3
 
4
4
  import re
5
- from argparse import ArgumentParser, Namespace
5
+ from argparse import ArgumentParser, ArgumentTypeError, Namespace
6
6
  from dataclasses import dataclass
7
7
  from enum import Enum
8
8
  from pathlib import Path
9
9
  from typing import Iterable, Optional
10
10
 
11
+ from pontos.terminal.terminal import ConsoleTerminal
12
+
11
13
  from troubadix.argparser import directory_type, file_type
12
14
  from troubadix.helper.patterns import (
13
15
  ScriptTag,
@@ -15,6 +17,7 @@ from troubadix.helper.patterns import (
15
17
  get_script_tag_pattern,
16
18
  get_special_script_tag_pattern,
17
19
  )
20
+ from troubadix.troubadix import from_file
18
21
 
19
22
 
20
23
  class Deprecations(Enum):
@@ -34,6 +37,15 @@ class DeprecatedFile:
34
37
  KB_ITEMS_PATTERN = re.compile(r"set_kb_item\(.+\);")
35
38
 
36
39
 
40
+ def existing_file_type(string: str) -> Path:
41
+ file_path = Path(string)
42
+ if not file_path.exists():
43
+ raise ArgumentTypeError(f'File "{string}" does not exist.')
44
+ if not file_path.is_file():
45
+ raise ArgumentTypeError(f'"{string}" is not a file.')
46
+ return file_path
47
+
48
+
37
49
  def update_summary(file: DeprecatedFile, deprecation_reason: str) -> str:
38
50
  """Update the summary of the nasl script by adding the information
39
51
  that the script has been deprecated, and if possible, the oid of
@@ -83,26 +95,18 @@ def get_files_from_path(dir_path: Path = None) -> list:
83
95
  return [file for file in dir_path.glob("**/*")]
84
96
 
85
97
 
86
- def filter_files(
87
- files: list, filename_prefix: str = None
88
- ) -> list[DeprecatedFile]:
89
- """Filter the files based on a provided prefix and convert them into
98
+ def parse_files(files: list) -> list[DeprecatedFile]:
99
+ """Convert filepaths into
90
100
  DeprecatedFile objects
91
101
 
92
102
  Args:
93
103
  files: a list of files to deprecate, should be .nasl VTs
94
- filename_prefix: an optional prefix to filter only specific files
95
104
 
96
105
  Returns:
97
106
  List of DeprecatedFile objects
98
107
 
99
108
  """
100
109
  to_deprecate = []
101
- if filename_prefix:
102
- filename_filter = re.compile(rf"{filename_prefix}")
103
- files[:] = [
104
- file for file in files if re.match(filename_filter, file.name)
105
- ]
106
110
 
107
111
  for file in files:
108
112
  with file.open("r", encoding="latin-1") as fh:
@@ -193,16 +197,6 @@ def parse_args(args: Iterable[str] = None) -> Namespace:
193
197
  required=True,
194
198
  help="Path where the deprecated files should be written to.",
195
199
  )
196
- parser.add_argument(
197
- "-p",
198
- "--filename-prefix",
199
- metavar="<filename_prefix>",
200
- nargs="?",
201
- default=None,
202
- type=str,
203
- help="The prefix of the files you would like to deprecate,"
204
- "for example 'gb_rhsa_2021' to filter on the year",
205
- )
206
200
  parser.add_argument(
207
201
  "-r",
208
202
  "--deprecation-reason",
@@ -214,16 +208,17 @@ def parse_args(args: Iterable[str] = None) -> Namespace:
214
208
  "been merged with another still active VT, 'duplicate': The VT has"
215
209
  "a still active duplicate, 'defunct': The VT is no longer "
216
210
  "functional.",
211
+ required=True,
217
212
  )
218
213
  group = parser.add_mutually_exclusive_group(required=True)
219
214
  group.add_argument(
220
215
  "-f",
221
- "--files",
222
- metavar="<files>",
216
+ "--file",
217
+ metavar="<file>",
223
218
  nargs="+",
224
219
  default=None,
225
220
  type=file_type,
226
- help="Files to deprecate",
221
+ help="File to deprecate",
227
222
  )
228
223
  group.add_argument(
229
224
  "-i",
@@ -231,20 +226,36 @@ def parse_args(args: Iterable[str] = None) -> Namespace:
231
226
  metavar="<input_path>",
232
227
  default=None,
233
228
  type=directory_type,
234
- help="Path to the existing nasl script directory",
229
+ help="Path to a directory where all files should be deprecated.",
230
+ )
231
+ group.add_argument(
232
+ "--from-file",
233
+ metavar="<from_file>",
234
+ default=None,
235
+ type=existing_file_type,
236
+ help=(
237
+ "Path to a single file that contains a list of files "
238
+ "to be deprecated, separated by new lines."
239
+ ),
235
240
  )
236
241
  return parser.parse_args(args)
237
242
 
238
243
 
239
244
  def main():
240
245
  args = parse_args()
246
+ terminal = ConsoleTerminal()
241
247
  input_path = args.input_path if args.input_path else None
242
- filename_prefix = args.filename_prefix
248
+ files = []
243
249
 
244
- files = args.files or get_files_from_path(input_path)
245
- filtered_files = filter_files(files, filename_prefix)
250
+ if input_path:
251
+ files = get_files_from_path(input_path)
252
+ elif args.from_file:
253
+ files = from_file(include_file=args.from_file, term=terminal)
254
+ elif args.file:
255
+ files = args.file
246
256
 
247
- deprecate(args.output_path, filtered_files, args.deprecation_reason)
257
+ to_be_deprecated = parse_files(files)
258
+ deprecate(args.output_path, to_be_deprecated, args.deprecation_reason)
248
259
 
249
260
 
250
261
  if __name__ == "__main__":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: troubadix
3
- Version: 24.9.4
3
+ Version: 24.10.1
4
4
  Summary: A linting and QA check tool for NASL files
5
5
  Home-page: https://github.com/greenbone/troubadix
6
6
  License: GPL-3.0-or-later
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
18
  Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
19
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
21
  Requires-Dist: chardet (>=4,<6)
21
22
  Requires-Dist: charset-normalizer (>=3.2.0,<4.0.0)
@@ -23,7 +24,7 @@ Requires-Dist: codespell (>=2.0.0,<3.0.0)
23
24
  Requires-Dist: gitpython (>=3.1.31,<4.0.0)
24
25
  Requires-Dist: pontos (>=22.7,<25.0)
25
26
  Requires-Dist: python-magic (>=0.4.25,<0.5.0)
26
- Requires-Dist: validators (==0.20.0)
27
+ Requires-Dist: validators (>=0.34.0,<0.35.0)
27
28
  Project-URL: Repository, https://github.com/greenbone/troubadix
28
29
  Description-Content-Type: text/markdown
29
30
 
@@ -1,5 +1,5 @@
1
1
  troubadix/__init__.py,sha256=K7sIXXDrC7YRb7BvIpdQ6ZfG_QkT0qUH_wAlHROVRfM,716
2
- troubadix/__version__.py,sha256=fCgh5yBoJNHBzdwMZ24n51N50H4g6MWpbLRDcZoIaZw,103
2
+ troubadix/__version__.py,sha256=QzxNhvE2FNP2xdsM9j8IJSuyjqWoBaVmQ_l5mtbnUWw,104
3
3
  troubadix/argparser.py,sha256=YAo8cGJt0k2GMICXrDj3Z124GrM8oRwgNm2Bn3J_gYI,7001
4
4
  troubadix/codespell/codespell.additions,sha256=OaHe66OE0Yx4VTkhIeITZqB7_ERiv0fsDnpikGUgZ-Q,488
5
5
  troubadix/codespell/codespell.exclude,sha256=6HEOtHrMBBdm4E4794W4g1H9nmGLlYbgZpQiJzKio-A,139033
@@ -9,7 +9,7 @@ troubadix/helper/helper.py,sha256=GXapYLii2rLKwkX2ok31YoAdUSizBnyPjWz-aPP6HM8,31
9
9
  troubadix/helper/linguistic_exception_handler.py,sha256=Bq7ULjDdWTKUpFNTUX6XMPdD4s4v8eIjZPyqBe8VLws,6811
10
10
  troubadix/helper/patterns.py,sha256=_ifRnwHsPee9B0yRYSCsyFms4StWVWJq7I9YnQwToa8,9174
11
11
  troubadix/plugin.py,sha256=3fQPj3Qe_hgwHerlYE4hbdzYMzRU557NxJ-UwtE9mOI,3525
12
- troubadix/plugins/__init__.py,sha256=McIt4ZDPLmFxr0WMi8FmRoV-bDLXxSP-6JbrYKR1RHc,7413
12
+ troubadix/plugins/__init__.py,sha256=V5fHMg2qVWIYKVZJqHKpzgrQ5x87Pz5u-h-CxOx7Dls,7511
13
13
  troubadix/plugins/badwords.py,sha256=C5Vuq6rzyeQkbEsg4t9ui9K05nQAh3Xy93sqV9K7aNw,4603
14
14
  troubadix/plugins/copyright_text.py,sha256=jYsLWmTbT_A78XQQxQFK-5kMMHkh3xdvlh7mEF2dZGU,3583
15
15
  troubadix/plugins/copyright_year.py,sha256=XzM9MHVzOXwNLwHpfuaWj8PUOmswr56SBVOLBdvxjd4,5478
@@ -52,11 +52,12 @@ troubadix/plugins/script_tag_whitespaces.py,sha256=2ZqiNufPIyr5Wmcuap3Wy8RXO_CHG
52
52
  troubadix/plugins/script_tags_mandatory.py,sha256=t9GiueHwCjWq-2jQszYNufWpfIKTLdUbbvXPyiw3HeY,2630
53
53
  troubadix/plugins/script_version_and_last_modification_tags.py,sha256=Yz9dQwrsRfIqXwPd8Re8aDu--SBjgufWOA6U7tW4JW4,7638
54
54
  troubadix/plugins/script_xref_form.py,sha256=5L1KPUHiKbe-71o-X0cUBT844XvIOsAJbB14gnYTod0,1848
55
- troubadix/plugins/script_xref_url.py,sha256=-IOzYTIINm8rZpI0CG94y_fdwJRW0FlRiGf3MnSj1O8,2875
55
+ troubadix/plugins/script_xref_url.py,sha256=qKeRgcZEka4Xm0EYYSq9_J_y8jVn6lrLPYan2FljN4E,2895
56
56
  troubadix/plugins/security_messages.py,sha256=EPu3-YB0iP5_hfbQjrfvvTrQRiPgDjC85GTz3V-by0Q,4629
57
57
  troubadix/plugins/set_get_kb_calls.py,sha256=WGu1CKLjn3VhbDo33IJ4TtWQ-kz9gInkJskTqOSMM6k,3415
58
58
  troubadix/plugins/solution_text.py,sha256=4Gs84Qsyg-1iTDP7Y7o8Bo5AH4hKlwGPW0NfwMpx2fU,5852
59
59
  troubadix/plugins/solution_type.py,sha256=6wq7lj0bCL6tTaZ-d_aGKq6a_jVlCD73GltHJsJhmm8,2602
60
+ troubadix/plugins/spaces_before_dots.py,sha256=83bVH4dxJPsNyd53kEX8fnDEge9R6kjAHdOnrDB7L9w,4852
60
61
  troubadix/plugins/spaces_in_filename.py,sha256=v8OqzzZSeI4_iXATHYzkf-HoAMxc_xb2Nj0HPAVevpk,611
61
62
  troubadix/plugins/spelling.py,sha256=3AW5sNtLL67OthKLaCH_y2HCVJ5YH_eyF9xjTJMIDG4,9593
62
63
  troubadix/plugins/tabs.py,sha256=7zXaTZe4cZoZvrLyqntVfTeNN_W3D8dfQl67QevXxtc,1319
@@ -86,14 +87,14 @@ troubadix/standalone_plugins/changed_packages/marker/dropped_architecture.py,sha
86
87
  troubadix/standalone_plugins/changed_packages/marker/marker.py,sha256=7uZXR2Ds_8soB_2wugCkOSz_3hoX03KMh2NAW0G5Dzg,1278
87
88
  troubadix/standalone_plugins/changed_packages/package.py,sha256=Pcr2tcwiPTzD3jB0iteqA7-TajL-dl5Onh1dvC_H9xk,2743
88
89
  troubadix/standalone_plugins/common.py,sha256=PkScV-lisNY4WyrzwjV3dK1DF26hJv5JXTcREblJ0v0,1028
89
- troubadix/standalone_plugins/deprecate_vts.py,sha256=kqWYfRO6Cr2E_zBnP3kJQoVznpRDcbIF6x6AiApYGBk,7661
90
+ troubadix/standalone_plugins/deprecate_vts.py,sha256=WjhJb9YkUp_5TScE9wKI856tfi7ZZ6mBQQdrE-BqQE0,7889
90
91
  troubadix/standalone_plugins/file_extensions.py,sha256=QLQt02WIc4SWLDTKKnG8q2g-atC7Mgus-opuXf_SX1A,2630
91
92
  troubadix/standalone_plugins/last_modification.py,sha256=oYzQq7xV3YzSvi6ZtuHuupXsJwBtO93tKfbwaIeqiJI,4616
92
93
  troubadix/standalone_plugins/no_solution.py,sha256=81r20kP8otRob2NTaCea-sgVRIM6ARvhddFdibsG6Ao,8877
93
94
  troubadix/standalone_plugins/version_updated.py,sha256=RlzVuXgFOvcjrRTOhiTYlmzV4vvcn7ntCz0lDTjePMU,4316
94
95
  troubadix/troubadix.py,sha256=foA7Loi67cCKieN3ea4s3QOfOWOkgwQVR1H-pNXtXn0,6041
95
- troubadix-24.9.4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
96
- troubadix-24.9.4.dist-info/METADATA,sha256=cy8Uc-BwHeiZuQABZkS1O_OmFEvFlSg7OG5pvAbvgLk,4357
97
- troubadix-24.9.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
98
- troubadix-24.9.4.dist-info/entry_points.txt,sha256=LplOk4nzKrS4B8Jz0SPkQLPlIDesdraCO8Vp_eoycpc,737
99
- troubadix-24.9.4.dist-info/RECORD,,
96
+ troubadix-24.10.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
97
+ troubadix-24.10.1.dist-info/METADATA,sha256=c7uJGlMtz-hbHkJJDpRsU-1kPAr8_QOjJvtyajMKK84,4417
98
+ troubadix-24.10.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
99
+ troubadix-24.10.1.dist-info/entry_points.txt,sha256=LplOk4nzKrS4B8Jz0SPkQLPlIDesdraCO8Vp_eoycpc,737
100
+ troubadix-24.10.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any