Skip to content

Commit 5d6788f

Browse files
committed
Change: use a json dict instead of an array of id-value pairs for scan_preferences
1 parent 093764d commit 5d6788f

File tree

7 files changed

+54
-47
lines changed

7 files changed

+54
-47
lines changed

rust/doc/openapi.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,8 @@ components:
415415
target:
416416
$ref: "#/components/schemas/Target"
417417
scan_preferences:
418-
description: "Overwrite the default settings of the Scanner."
419-
type: "array"
420-
items:
421-
$ref: "#/components/schemas/ScanPreference"
418+
description: "Overwrite the default settings for a scan. Setting are id-value pairs."
419+
type: "object"
422420
vts:
423421
type: "array"
424422
description: "A collection of VTs, which are run for the given target."
@@ -947,11 +945,11 @@ components:
947945
"reverse_lookup_only": false,
948946
},
949947
"scan_preferences":
950-
[
951-
{ "id": "target_port", "value": "443" },
952-
{ "id": "use_https", "value": "1" },
953-
{ "id": "profile", "value": "fast_scan" },
954-
],
948+
{
949+
"target_port": 443,
950+
"use_https": true,
951+
"cgi_path": "/cgi-bin:/scripts",
952+
},
955953
"vts":
956954
[
957955
{

rust/doc/reverse-sensor-openapi.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,8 @@ components:
229229
target:
230230
$ref: "#/components/schemas/Target"
231231
scan_preferences:
232-
description: "Overwrite the default settings of the Scanner."
233-
type: "array"
234-
items:
235-
$ref: "#/components/schemas/ScanPreference"
232+
description: "Overwrite the default settings for a scan. Setting are id-value pairs."
233+
type: "object"
236234
vts:
237235
type: "array"
238236
description: "A collection of VTs, which are run for the given target."
@@ -653,11 +651,11 @@ components:
653651
"reverse_lookup_only": false,
654652
},
655653
"scan_preferences":
656-
[
657-
{ "id": "target_port", "value": "443" },
658-
{ "id": "use_https", "value": "1" },
659-
{ "id": "profile", "value": "fast_scan" },
660-
],
654+
{
655+
"target_port": 443,
656+
"use_https": true,
657+
"cgi_path": "/cgi-bin:/scripts",
658+
},
661659
"vts":
662660
[
663661
{

rust/models/src/lib.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,11 @@ mod tests {
137137
"reverse_lookup_unify": true,
138138
"reverse_lookup_only": false
139139
},
140-
"scan_preferences": [
141-
{
142-
"id": "target_port",
143-
"value": "443"
144-
},
145-
{
146-
"id": "use_https",
147-
"value": "1"
148-
},
149-
{
150-
"id": "profile",
151-
"value": "fast_scan"
152-
}
153-
],
140+
"scan_preferences": {
141+
"target_port": 443,
142+
"use_https": true,
143+
"cgi_path": "/cgi-bin:/scripts"
144+
},
154145
"vts": [
155146
{
156147
"oid": "1.3.6.1.4.1.25623.1.0.10662",

rust/models/src/scan.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

5-
use super::{scan_preference::ScanPreference, target::Target, vt::VT};
5+
use std::collections::HashMap;
6+
7+
use super::{scan_preference::PreferenceValue, target::Target, vt::VT};
68

79
/// Struct for creating and getting a scan
810
#[derive(Default, Debug, Clone, PartialEq, Eq)]
@@ -22,7 +24,7 @@ pub struct Scan {
2224
serde(default, alias = "scanner_preferences")
2325
)]
2426
/// Configuration options for the scanner
25-
pub scan_preferences: Vec<ScanPreference>,
27+
pub scan_preferences: HashMap<String, PreferenceValue>,
2628
/// List of VTs to execute for the target
2729
pub vts: Vec<VT>,
2830
}

rust/models/src/scan_preference.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,33 @@
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

5-
/// Configuration preference for the scanner
6-
#[derive(Default, Debug, Clone, PartialEq, Eq)]
5+
use std::fmt::Display;
6+
7+
/// Preference value
8+
#[derive(Debug, Clone, PartialEq, Eq)]
79
#[cfg_attr(
810
feature = "serde_support",
9-
derive(serde::Serialize, serde::Deserialize)
11+
derive(serde::Serialize, serde::Deserialize),
12+
serde(untagged)
1013
)]
11-
pub struct ScanPreference {
12-
/// The ID of the scanner preference.
13-
pub id: String,
14-
/// The value of the scanner preference.
15-
pub value: String,
14+
pub enum PreferenceValue {
15+
Bool(bool),
16+
Int(i64),
17+
String(String),
18+
}
19+
20+
impl Default for PreferenceValue {
21+
fn default() -> Self {
22+
Self::Int(0)
23+
}
24+
}
25+
26+
impl Display for PreferenceValue {
27+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28+
match self {
29+
PreferenceValue::Bool(v) => write!(f, "{v}"),
30+
PreferenceValue::Int(v) => write!(f, "{v}"),
31+
PreferenceValue::String(v) => write!(f, "{v}"),
32+
}
33+
}
1634
}

rust/openvas/src/pref_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ where
342342
.scan_preferences
343343
.clone()
344344
.iter()
345-
.map(|x| format!("{}|||{}", x.id, x.value))
345+
.map(|x| format!("{}|||{}", x.0, x.1))
346346
.collect::<Vec<String>>();
347347

348348
if options.is_empty() {

rust/osp/src/commands.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ fn write_vts(scan: &Scan, writer: &mut Writer) -> Result<()> {
181181
})
182182
}
183183

184-
// In the openvasd API it is called scanner preferences while in the OSP side
184+
// In the openvasd API it is called scan preferences while in the OSP side
185185
// it is called scanner parameters.
186186
fn write_scanner_prefs(scan: &Scan, writer: &mut Writer) -> Result<()> {
187187
writer.write_event(Event::Start(BytesStart::new("scanner_params")))?;
188188
for p in &scan.scan_preferences {
189-
writer.write_event(Event::Start(BytesStart::new(&p.id)))?;
190-
writer.write_event(Event::Text(BytesText::new(&p.value)))?;
191-
writer.write_event(Event::End(BytesEnd::new(&p.id)))?;
189+
writer.write_event(Event::Start(BytesStart::new(p.0)))?;
190+
writer.write_event(Event::Text(BytesText::new(p.1.to_string().as_str())))?;
191+
writer.write_event(Event::End(BytesEnd::new(p.0)))?;
192192
}
193193

194194
writer.write_event(Event::End(BytesEnd::new("scanner_params")))?;

0 commit comments

Comments
 (0)