Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ and types.
- [report-formats-url](#report-formats-url)
- [scan-configs-destination](#scan-configs-destination)
- [scan-configs-url](#scan-configs-url)
- [scan-config-jsons-destination](#scan-config-jsons-destination)
- [scan-config-jsons-url](#scan-config-jsons-url)
- [port-lists-destination](#port-lists-destination)
- [port-lists-url](#port-lists-url)
- [gvmd-lock-file](#gvmd-lock-file)
Expand Down Expand Up @@ -273,7 +275,7 @@ is only required for experts and testing purposes.
| Config Variable | |
| Environment Variable | |
| Default Value | all |
| Description | Specifies which feed data should be downloaded. Possible values are `all`, `nvt`/`nvts`, `gvmd-data`, `scap`, `cert`, `notus`, `nasl`, `report-format`/`report-formats`, `scan-config`/`scan-configs` or `port-list`/`port-lists`. |
| Description | Specifies which feed data should be downloaded. Possible values are `all`, `nvt`/`nvts`, `gvmd-data`, `scap`, `cert`, `notus`, `nasl`, `report-format`/`report-formats`, `scan-config`/`scan-configs`, `scan-config-json`/`scan-config-jsons` or `port-list`/`port-lists`. |

### feed-url

Expand Down Expand Up @@ -445,6 +447,26 @@ is only required for experts and testing purposes.
| Default Value | `$FEED_URL/data-feed/$FEED_VERSION/scan-configs` |
| Description | URL to download the scan config data from. |

### scan-config-jsons-destination

| Name | Value |
| -------------------- | --------------------------------------------------------------------------- |
| CLI Argument | `--scan-config-jsons-destination` |
| Config Variable | scan-config-jsons-destination |
| Environment Variable | `GREENBONE_FEED_SYNC_SCAN_CONFIG_JSONS_DESTINATION` |
| Default Value | `$DESTINATION_PREFIX/gvm/data-objects/gvmd/$FEED_VERSION/scan-configs-json` |
| Description | Destination of the downloaded scan config JSON data. |

### scan-config-jsons-url

| Name | Value |
| -------------------- | ----------------------------------------------------- |
| CLI Argument | `--scan-config-jsons-url` |
| Config Variable | scan-config-jsons-url |
| Environment Variable | `GREENBONE_FEED_SYNC_SCAN_CONFIG_JSONS_URL` |
| Default Value | `$FEED_URL/data-feed/$FEED_VERSION/scan-configs-json` |
| Description | URL to download the scan config JSON data from. |

### port-lists-destination

| Name | Value |
Expand Down
14 changes: 14 additions & 0 deletions greenbone/feed/sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,20 @@ def feed_url(self) -> str:
),
str,
),
DependentSetting(
"scan-config-jsons-destination",
"GREENBONE_FEED_SYNC_SCAN_CONFIG_JSONS_DESTINATION",
lambda values: f"{values['gvmd-data-destination']}/scan-configs-json",
Path,
),
DependentSetting(
"scan-config-jsons-url",
"GREENBONE_FEED_SYNC_SCAN_CONFIG_JSONS_URL",
lambda values: (
f"{values['feed-url']}/data-feed/{values['feed-release']}/scan-configs-json/"
),
str,
),
DependentSetting(
"port-lists-destination",
"GREENBONE_FEED_SYNC_PORT_LISTS_DESTINATION",
Expand Down
6 changes: 6 additions & 0 deletions greenbone/feed/sync/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ async def feed_sync(console: Console, error_console: Console) -> int:
url=args.scan_configs_url,
destination=args.scan_configs_destination,
),
Sync(
name="scan config JSONs",
types=("scan-config-json",),
url=args.scan_config_jsons_url,
destination=args.scan_config_jsons_destination,
),
Sync(
name="port lists",
types=("port-list"),
Expand Down
20 changes: 19 additions & 1 deletion greenbone/feed/sync/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ def feed_type(value: str) -> str:

value = value.replace("_", "-").lower()

if value in ("nvts", "report-formats", "port-lists", "scan-configs"):
if value in (
"nvts",
"report-formats",
"port-lists",
"scan-configs",
"scan-config-jsons",
):
return value[:-1]

return value
Expand Down Expand Up @@ -113,6 +119,7 @@ def __init__(self) -> None:
"nasl",
"report-format",
"scan-config",
"scan-config-json",
"port-list",
],
default="all",
Expand Down Expand Up @@ -212,6 +219,17 @@ def __init__(self) -> None:
help="URL to download the scan config data from. "
"(Default: %(default)s)",
)
data_objects_destination_group.add_argument(
"--scan-config-jsons-destination",
type=Path,
help="Destination of the downloaded scan config JSON data. "
"(Default: %(default)s)",
)
data_objects_url_group.add_argument(
"--scan-config-jsons-url",
help="URL to download the scan config JSON data from. "
"(Default: %(default)s)",
)
data_objects_destination_group.add_argument(
"--port-lists-destination",
type=Path,
Expand Down
26 changes: 25 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ConfigTestCase(unittest.TestCase):
def test_defaults(self):
values = Config.load()

self.assertEqual(len(values), 32)
self.assertEqual(len(values), 34)
self.assertEqual(
values["destination-prefix"], Path(DEFAULT_DESTINATION_PREFIX)
)
Expand Down Expand Up @@ -103,6 +103,18 @@ def test_defaults(self):
values["scan-configs-url"],
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs/",
)
self.assertEqual(
values["scan-config-jsons-destination"],
Path(DEFAULT_DESTINATION_PREFIX)
/ "gvm"
/ "data-objects"
/ "gvmd"
/ "scan-configs-json",
)
self.assertEqual(
values["scan-config-jsons-url"],
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs-json/",
)
self.assertEqual(
values["port-lists-destination"],
Path(DEFAULT_DESTINATION_PREFIX)
Expand Down Expand Up @@ -159,6 +171,8 @@ def test_config_file(self):
report-formats-url = "rsync://foo.bar/report-formats"
scan-configs-destination = "/usr/lib/scan-configs"
scan-configs-url = "rsync://foo.bar/scan-configs"
scan-config-jsons-destination = "/usr/lib/scan-configs-json"
scan-config-jsons-url = "rsync://foo.bar/scan-configs-json"
port-lists-destination = "/usr/lib/port-lists"
port-lists-url = "rsync://foo.bar/port-lists"
openvas-lock-file = "/usr/lib/openvas.lock"
Expand Down Expand Up @@ -218,6 +232,14 @@ def test_config_file(self):
self.assertEqual(
values["scan-configs-url"], "rsync://foo.bar/scan-configs"
)
self.assertEqual(
values["scan-config-jsons-destination"],
Path("/usr/lib/scan-configs-json"),
)
self.assertEqual(
values["scan-config-jsons-url"],
"rsync://foo.bar/scan-configs-json",
)
self.assertEqual(
values["port-lists-destination"],
Path("/usr/lib/port-lists"),
Expand Down Expand Up @@ -350,6 +372,8 @@ def test_feed_url(self):
"GREENBONE_FEED_SYNC_REPORT_FORMATS_URL": "rsync://foo.bar/report-formats",
"GREENBONE_FEED_SYNC_SCAN_CONFIGS_DESTINATION": "/usr/lib/scan-configs",
"GREENBONE_FEED_SYNC_SCAN_CONFIGS_URL": "rsync://foo.bar/scan-configs",
"GREENBONE_FEED_SYNC_SCAN_CONFIG_JSONS_DESTINATION": "/usr/lib/scan-configs-json",
"GREENBONE_FEED_SYNC_SCAN_CONFIG_JSONS_URL": "rsync://foo.bar/scan-configs-json",
"GREENBONE_FEED_SYNC_PORT_LISTS_DESTINATION": "/usr/lib/port-lists",
"GREENBONE_FEED_SYNC_PORT_LISTS_URL": "rsync://foo.bar/port-lists",
"GREENBONE_FEED_SYNC_OPENVAS_LOCK_FILE": "/usr/lib/openvas.lock",
Expand Down
63 changes: 62 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ def test_scan_config(self):
self.assertEqual("scan-config", feed_type("SCAN-CONFIG"))
self.assertEqual("scan-config", feed_type("SCAN-CONFIGS"))


def test_scan_config_json(self):
self.assertEqual("scan-config-json", feed_type("scan-config-json"))
self.assertEqual("scan-config-json", feed_type("scan-config-jsons"))
self.assertEqual("scan-config-json", feed_type("scan_config_json"))
self.assertEqual("scan-config-json", feed_type("scan_config_jsons"))
self.assertEqual("scan-config-json", feed_type("SCAN_CONFIG_JSON"))
self.assertEqual("scan-config-json", feed_type("SCAN_CONFIG_JSONS"))
self.assertEqual("scan-config-json", feed_type("SCAN-CONFIG-JSON"))
self.assertEqual("scan-config-json", feed_type("SCAN-CONFIG-JSONS"))

def test_gvmd_data(self):
self.assertEqual("gvmd-data", feed_type("gvmd-data"))
self.assertEqual("gvmd-data", feed_type("gvmd_data"))
Expand Down Expand Up @@ -172,6 +183,18 @@ def test_defaults(self):
args.scan_configs_url,
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs/",
)
self.assertEqual(
args.scan_config_jsons_destination,
Path(DEFAULT_DESTINATION_PREFIX)
/ "gvm"
/ "data-objects"
/ "gvmd"
/ "scan-configs-json",
)
self.assertEqual(
args.scan_config_jsons_url,
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs-json/",
)
self.assertEqual(
args.port_lists_destination,
Path(DEFAULT_DESTINATION_PREFIX)
Expand Down Expand Up @@ -390,7 +413,24 @@ def test_scan_configs_url(self):
)
self.assertEqual(args.scan_configs_url, "rsync://foo.bar/scan-configs")

def test_port_lists_destination(self):
def test_scan_config_jsons_destination(self):
parser = CliParser()
args = parser.parse_arguments(
["--scan-config-jsons-destination", "foo/bar"]
)
self.assertEqual(args.scan_config_jsons_destination, Path("foo/bar"))

def test_scan_config_jsons_url(self):
parser = CliParser()
args = parser.parse_arguments(
["--scan-config-jsons-url", "rsync://foo.bar/scan-configs-json"]
)
self.assertEqual(
args.scan_config_jsons_url,
"rsync://foo.bar/scan-configs-json",
)

def test_port_lists_destinatßion(self):
parser = CliParser()
args = parser.parse_arguments(["--port-lists-destination", "foo/bar"])
self.assertEqual(args.port_lists_destination, Path("foo/bar"))
Expand Down Expand Up @@ -678,6 +718,19 @@ def test_type(self):
args = parser.parse_arguments(["--type", "SCAN_CONFIGS"])
self.assertEqual(args.type, "scan-config")

args = parser.parse_arguments(["--type", "scan-config-json"])
self.assertEqual(args.type, "scan-config-json")
args = parser.parse_arguments(["--type", "SCAN-CONFIG-JSON"])
self.assertEqual(args.type, "scan-config-json")
args = parser.parse_arguments(["--type", "scan_config_json"])
self.assertEqual(args.type, "scan-config-json")
args = parser.parse_arguments(["--type", "SCAN_CONFIG_JSON"])
self.assertEqual(args.type, "scan-config-json")
args = parser.parse_arguments(["--type", "scan-config-jsons"])
self.assertEqual(args.type, "scan-config-json")
args = parser.parse_arguments(["--type", "SCAN_CONFIG_JSONS"])
self.assertEqual(args.type, "scan-config-json")

args = parser.parse_arguments(["--type", "port-list"])
self.assertEqual(args.type, "port-list")
args = parser.parse_arguments(["--type", "PORT-LIST"])
Expand Down Expand Up @@ -751,6 +804,10 @@ def test_feed_url_from_enterprise_feed_key(self):
args.scan_configs_url,
f"ssh://a_user@some.feed.server/enterprise/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs/",
)
self.assertEqual(
args.scan_config_jsons_url,
f"ssh://a_user@some.feed.server/enterprise/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs-json/",
)
self.assertEqual(
args.notus_url,
f"ssh://a_user@some.feed.server/enterprise/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/notus/",
Expand Down Expand Up @@ -793,6 +850,10 @@ def test_ignore_non_existing_enterprise_feed_key(self):
args.scan_configs_url,
f"rsync://feed.community.greenbone.net/community/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs/",
)
self.assertEqual(
args.scan_config_jsons_url,
f"rsync://feed.community.greenbone.net/community/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs-json/",
)
self.assertEqual(
args.notus_url,
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/notus/",
Expand Down
Loading