troubadix 25.6.1__py3-none-any.whl → 25.7.0__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 +1 -1
- troubadix/standalone_plugins/changed_creation_date.py +141 -0
- troubadix/standalone_plugins/util.py +27 -0
- {troubadix-25.6.1.dist-info → troubadix-25.7.0.dist-info}/METADATA +1 -1
- {troubadix-25.6.1.dist-info → troubadix-25.7.0.dist-info}/RECORD +8 -6
- {troubadix-25.6.1.dist-info → troubadix-25.7.0.dist-info}/entry_points.txt +1 -0
- {troubadix-25.6.1.dist-info → troubadix-25.7.0.dist-info}/LICENSE +0 -0
- {troubadix-25.6.1.dist-info → troubadix-25.7.0.dist-info}/WHEEL +0 -0
troubadix/__version__.py
CHANGED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
# SPDX-FileCopyrightText: 2025 Greenbone AG
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from argparse import ArgumentParser, Namespace
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from troubadix.argparser import file_type_existing
|
|
13
|
+
from troubadix.standalone_plugins.common import git
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
CREATION_DATE_BASE_PATTERN = (
|
|
18
|
+
r"\s*script_tag\s*\(\s*name\s*:\s*\"creation_date\"\s*,"
|
|
19
|
+
r"\s*value\s*:\s*\"(?P<creation_date>.*)\"\s*\)\s*;"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def parse_arguments() -> Namespace:
|
|
24
|
+
|
|
25
|
+
parser = ArgumentParser(
|
|
26
|
+
description="Check for changed creation date",
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"-c",
|
|
30
|
+
"--commit_range",
|
|
31
|
+
type=str,
|
|
32
|
+
required=True,
|
|
33
|
+
help=(
|
|
34
|
+
"Git commit range to check e.g. "
|
|
35
|
+
"2c87f4b6062804231fd508411510ca07fd270380..HEAD or"
|
|
36
|
+
"YOUR_BRANCH..main"
|
|
37
|
+
),
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"-f",
|
|
41
|
+
"--files",
|
|
42
|
+
nargs="+",
|
|
43
|
+
type=file_type_existing,
|
|
44
|
+
default=[],
|
|
45
|
+
help=(
|
|
46
|
+
"List of files to diff. "
|
|
47
|
+
"If empty use all files added or modified in the commit range."
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
args = parser.parse_args()
|
|
51
|
+
|
|
52
|
+
if not args.files:
|
|
53
|
+
args.files += [
|
|
54
|
+
Path(filename)
|
|
55
|
+
for filename in git(
|
|
56
|
+
"diff", "--name-only", "--diff-filter=d", args.commit_range
|
|
57
|
+
).splitlines()
|
|
58
|
+
if filename.endswith(".nasl")
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
return args
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def check_changed_creation_date(
|
|
65
|
+
commit_range: str, nasl_files: list[Path]
|
|
66
|
+
) -> bool:
|
|
67
|
+
"""
|
|
68
|
+
This script checks (via git diff) if the creation date of
|
|
69
|
+
passed VTs has changed, which is not allowed.
|
|
70
|
+
"""
|
|
71
|
+
creation_date_changed = False
|
|
72
|
+
|
|
73
|
+
for nasl_file in nasl_files:
|
|
74
|
+
|
|
75
|
+
if not nasl_file.exists():
|
|
76
|
+
continue
|
|
77
|
+
|
|
78
|
+
logger.info("Check file %s", nasl_file)
|
|
79
|
+
text = git(
|
|
80
|
+
"-c",
|
|
81
|
+
"color.status=false",
|
|
82
|
+
"--no-pager",
|
|
83
|
+
"diff",
|
|
84
|
+
commit_range,
|
|
85
|
+
nasl_file,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
creation_date_added = re.search(
|
|
89
|
+
r"^\+" + CREATION_DATE_BASE_PATTERN,
|
|
90
|
+
text,
|
|
91
|
+
re.MULTILINE,
|
|
92
|
+
)
|
|
93
|
+
if not creation_date_added or not (
|
|
94
|
+
added := creation_date_added.group("creation_date")
|
|
95
|
+
):
|
|
96
|
+
continue
|
|
97
|
+
|
|
98
|
+
creation_date_removed = re.search(
|
|
99
|
+
r"^\-" + CREATION_DATE_BASE_PATTERN,
|
|
100
|
+
text,
|
|
101
|
+
re.MULTILINE,
|
|
102
|
+
)
|
|
103
|
+
if not creation_date_removed or not (
|
|
104
|
+
removed := creation_date_removed.group("creation_date")
|
|
105
|
+
):
|
|
106
|
+
continue
|
|
107
|
+
|
|
108
|
+
if added != removed:
|
|
109
|
+
logger.error(
|
|
110
|
+
"The creation date of %s was changed, "
|
|
111
|
+
"which is not allowed.\nNew creation date: "
|
|
112
|
+
"%s\nOld creation date: %s",
|
|
113
|
+
nasl_file,
|
|
114
|
+
added,
|
|
115
|
+
removed,
|
|
116
|
+
)
|
|
117
|
+
creation_date_changed = True
|
|
118
|
+
|
|
119
|
+
return creation_date_changed
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def main() -> int:
|
|
123
|
+
|
|
124
|
+
try:
|
|
125
|
+
git_base = git("rev-parse", "--show-toplevel")
|
|
126
|
+
os.chdir(git_base.rstrip("\n"))
|
|
127
|
+
except subprocess.SubprocessError:
|
|
128
|
+
logger.error(
|
|
129
|
+
"Your current working directory doesn't belong to a git repository"
|
|
130
|
+
)
|
|
131
|
+
return 1
|
|
132
|
+
|
|
133
|
+
args = parse_arguments()
|
|
134
|
+
if check_changed_creation_date(args.commit_range, args.files):
|
|
135
|
+
return 2
|
|
136
|
+
|
|
137
|
+
return 0
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if __name__ == "__main__":
|
|
141
|
+
sys.exit(main())
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
# SPDX-FileCopyrightText: 2025 Greenbone AG
|
|
3
|
+
|
|
4
|
+
from contextlib import contextmanager
|
|
5
|
+
from os import chdir
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from tempfile import TemporaryDirectory
|
|
8
|
+
|
|
9
|
+
from troubadix.standalone_plugins.changed_creation_date import git
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@contextmanager
|
|
13
|
+
def temporary_git_directory():
|
|
14
|
+
|
|
15
|
+
cwd = Path.cwd()
|
|
16
|
+
|
|
17
|
+
with TemporaryDirectory() as tempdir:
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
chdir(tempdir)
|
|
21
|
+
git("init", "-b", "main")
|
|
22
|
+
git("config", "--local", "user.email", "max.mustermann@example.com")
|
|
23
|
+
git("config", "--local", "user.name", "Max Mustermann")
|
|
24
|
+
yield Path(tempdir)
|
|
25
|
+
|
|
26
|
+
finally:
|
|
27
|
+
chdir(cwd)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
troubadix/__init__.py,sha256=K7sIXXDrC7YRb7BvIpdQ6ZfG_QkT0qUH_wAlHROVRfM,716
|
|
2
|
-
troubadix/__version__.py,sha256=
|
|
2
|
+
troubadix/__version__.py,sha256=NHJb1vEGkcQk-Z5bMNSWvzqG9LNkP3WsVc67x8tw95w,103
|
|
3
3
|
troubadix/argparser.py,sha256=-H07Jhqh68_M4Mbjq9qJjTr3MShy_N2pxl2qHA6cfRU,7481
|
|
4
4
|
troubadix/codespell/codespell.additions,sha256=E62zoHJavUhcbMoyBqO2rOUe3OqIXikh7uAiGmNs5uw,524
|
|
5
5
|
troubadix/codespell/codespell.exclude,sha256=8blBv8KRrKU4KQhneHOPth1tSCYdrEoOCI5kYRfhOEA,147451
|
|
@@ -79,6 +79,7 @@ troubadix/results.py,sha256=PAe3n0A99XXNYeP8gLliuDFt0V9J5a7oPun_bKU4LG4,2599
|
|
|
79
79
|
troubadix/runner.py,sha256=RHyZe7YMBzJpCGBVfBUg2BMkVi13CmI9u0DVG2z4518,5195
|
|
80
80
|
troubadix/standalone_plugins/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
81
81
|
troubadix/standalone_plugins/allowed_rev_diff.py,sha256=5Zc8xTZlkMOPVNRdxNkosFFtwaQ6J8RiJYzaYXEuN40,4145
|
|
82
|
+
troubadix/standalone_plugins/changed_creation_date.py,sha256=6iaWnvWPlhkAM2FKtBVgEZOsMIctz3f6dgPR4k2LcTY,3518
|
|
82
83
|
troubadix/standalone_plugins/changed_cves.py,sha256=nEWwDa33QXekvpwcmnGMrdPHrJISz9p9j6lX09teDlk,2921
|
|
83
84
|
troubadix/standalone_plugins/changed_oid.py,sha256=9eLvuBuPgZYnHHst-Y-J0TgCcgwmlOWjszWJ57kG9cg,3934
|
|
84
85
|
troubadix/standalone_plugins/changed_packages/changed_packages.py,sha256=tyNwpJgaZS2o0X6xywXAQ_i7LB9HsEQYbDZ3Tcvtsdo,5742
|
|
@@ -100,10 +101,11 @@ troubadix/standalone_plugins/deprecate_vts.py,sha256=mLt2DV9Y1YAEuh6c4nFweZYIOpr
|
|
|
100
101
|
troubadix/standalone_plugins/file_extensions.py,sha256=fqswrhCcQqygIszcnobS9hFQmSpv3gDkvlufoaTckBg,2355
|
|
101
102
|
troubadix/standalone_plugins/last_modification.py,sha256=ROzwVzzYilXJ0llVt4Lv0w8b9BJKoahl6YxPDiub614,4338
|
|
102
103
|
troubadix/standalone_plugins/no_solution.py,sha256=p_-az9Igl4GH6HnhLLYbYlWIiEP64OTQLpX-z3JAshs,8760
|
|
104
|
+
troubadix/standalone_plugins/util.py,sha256=JTXGmi-_BJouTNe6QzEosLlXUt9jKW-3fz4db05RJJw,696
|
|
103
105
|
troubadix/standalone_plugins/version_updated.py,sha256=6YHF0OjL5NWszQdsSh7XzlSji1e6Uaqwu_Y6m3R0mvI,4203
|
|
104
106
|
troubadix/troubadix.py,sha256=5__Jz3bYSrya4aG6RCBWxqnsDepXfwXZ3v0bjCzEFi0,6039
|
|
105
|
-
troubadix-25.
|
|
106
|
-
troubadix-25.
|
|
107
|
-
troubadix-25.
|
|
108
|
-
troubadix-25.
|
|
109
|
-
troubadix-25.
|
|
107
|
+
troubadix-25.7.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
108
|
+
troubadix-25.7.0.dist-info/METADATA,sha256=SNdp7sZMqsY20qeT4_c7Cf-1JmBmwGoDOT7ufgfOiS0,4462
|
|
109
|
+
troubadix-25.7.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
110
|
+
troubadix-25.7.0.dist-info/entry_points.txt,sha256=ETEPBi4fKv3o7hzkzceX4838G6g5_5wRdEddYot8N6A,920
|
|
111
|
+
troubadix-25.7.0.dist-info/RECORD,,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
[console_scripts]
|
|
2
2
|
troubadix=troubadix.troubadix:main
|
|
3
3
|
troubadix-allowed-rev-diff=troubadix.standalone_plugins.allowed_rev_diff:main
|
|
4
|
+
troubadix-changed-creation-date=troubadix.standalone_plugins.changed_creation_date:main
|
|
4
5
|
troubadix-changed-cves=troubadix.standalone_plugins.changed_cves:main
|
|
5
6
|
troubadix-changed-oid=troubadix.standalone_plugins.changed_oid:main
|
|
6
7
|
troubadix-changed-packages=troubadix.standalone_plugins.changed_packages.changed_packages:main
|
|
File without changes
|
|
File without changes
|