Skip to content

Refactor: split greenbone-scanner-framework and move into openvasd - #2306

Open
tsurai wants to merge 1 commit into
mainfrom
greenbone-scanner-framework-split
Open

Refactor: split greenbone-scanner-framework and move into openvasd#2306
tsurai wants to merge 1 commit into
mainfrom
greenbone-scanner-framework-split

Conversation

@tsurai

@tsurai tsurai commented Jul 29, 2026

Copy link
Copy Markdown

The greenbone-scanner-framework crate is being split into two parts. A models crate containing shared data used among the workspace and the API related code only used by openvasd. The later is moved directly into openvasd as a module.

This is an intermediate step in preperation of a major API rework towards axum.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 3 package(s) with unknown licenses.
See the Details below.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA b734746.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

License Issues

rust/Cargo.toml

PackageVersionLicenseIssue Type
futures-util>= 0.3.32, < 0.4.0NullUnknown License
signal-hook>= 0.4.4, < 0.5.0NullUnknown License
signal-hook-tokio>= 0.4.0, < 0.5.0NullUnknown License
Allowed Licenses: 0BSD, AGPL-3.0-or-later, Apache-2.0, BlueOak-1.0.0, BSD-2-Clause, BSD-3-Clause-Clear, BSD-3-Clause, BSL-1.0, bzip2-1.0.6, CAL-1.0, CC-BY-3.0, CC-BY-4.0, CC-BY-SA-4.0, CC0-1.0, EPL-2.0, GPL-1.0-or-later, GPL-2.0-only, GPL-2.0-or-later, GPL-2.0, GPL-3.0-only, GPL-3.0-or-later, GPL-3.0, ISC, LGPL-2.0-only, LGPL-2.0-or-later, LGPL-2.1-only, LGPL-2.1-or-later, LGPL-2.1, LGPL-3.0-only, LGPL-3.0, LGPL-3.0-or-later, MIT, MIT-CMU, MPL-1.1, MPL-2.0, OFL-1.1, PSF-2.0, Python-2.0, Python-2.0.1, Unicode-3.0, Unicode-DFS-2016, Unlicense, Zlib, ZPL-2.1

OpenSSF Scorecard

PackageVersionScoreDetails
cargo/futures-util >= 0.3.32, < 0.4.0 UnknownUnknown
cargo/signal-hook >= 0.4.4, < 0.5.0 UnknownUnknown
cargo/signal-hook-tokio >= 0.4.0, < 0.5.0 UnknownUnknown

Scanned Files

  • rust/Cargo.toml
  • rust/crates/greenbone-scanner-framework/Cargo.toml

@tsurai
tsurai force-pushed the greenbone-scanner-framework-split branch from 316d061 to fd17bc6 Compare July 29, 2026 07:42

@Tehforsch Tehforsch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a cleaner approach is to move models into scannerlib entirely and to expose it to openvasd.

The reason why greenbone-scanner-framework was a separate crate to begin with is that once upon a time we thought about using it in entirely different projects. This is not necessary anymore. The remaining advantage of the crate-split is incremental compile times, but we have decided some time ago that we would rather have a monolithic lib crate for the simplicity that it brings and sacrifice a bit of compile time in the process. I'd prefer if we could stick with this approach here too.

(Side note for the openvasd historians among us: This is the eternal cycle of life: models used to be a workspace crate, was turned into a scannerlib module, then moved into gsf and has now - although only temporarily - become a workspace crate again before (in my opinion hopefully) reaching its true form as a scannerlib module again)

@Tehforsch

Copy link
Copy Markdown
Contributor

On another note: I saw that src/openvasd/greenbone_scanner_framework exists. The naming really doesn't make sense anymore now that this isn't a separate crate usable by other projects. I figure you'll probably address this in a future PR and it might get deleted entirely, but just wanted to make sure you're aware.

@tsurai
tsurai force-pushed the greenbone-scanner-framework-split branch from fd17bc6 to b734746 Compare July 29, 2026 08:47
@tsurai

tsurai commented Jul 29, 2026

Copy link
Copy Markdown
Author

I've pulled models back into scannerlib as you suggested.

On another note: I saw that src/openvasd/greenbone_scanner_framework exists. The naming really doesn't make sense anymore now that this isn't a separate crate usable by other projects. I figure you'll probably address this in a future PR and it might get deleted entirely, but just wanted to make sure you're aware.

Yea, it was my intention to rename it to just api but decided to delay it until the axum PR since it's responsibilties are still a bit murky in its current state.

@tsurai
tsurai marked this pull request as ready for review July 29, 2026 11:06
@tsurai
tsurai requested a review from a team as a code owner July 29, 2026 11:06

@Tehforsch Tehforsch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - Looks good for the most part, but please check what happened to the snapshots.

If I run cargo insta --unreferenced=delete on this PR, I find three unused snapshots. One of them was created, not moved, but I haven't looked into what happened with the other two. I checked and found some missing tests, on main I get 689 tests in total, on this branch I get 686. This fits with the three unused snapshots.

Also linting still fails due to unused stuff.

Comment on lines +1 to +80
// SPDX-FileCopyrightText: 2023 Greenbone AG
//
// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception

//! Defines time implementation for storage usages

/// Is an extension to add as_timestamp method for various types
pub trait AsUnixTimeStamp {
/// Returns a i64 unix time stamp when parsable otherwise None
fn as_timestamp(&self) -> Option<i64>;
}

use time::{OffsetDateTime, format_description};

// the function panics because the support formats are hardcoded and therefore the user cannot change anything
fn parse_or_panic(input: &str) -> Vec<time::format_description::FormatItem<'_>> {
match format_description::parse_borrowed::<1>(input) {
Ok(x) => x,
Err(e) => panic!("expected {input} to be parsable: {e:?}"),
}
}

// for more information see:
// https://time-rs.github.io/book/api/format-description.html
const SUPPORTED_FORMATS: &[&str] = &[
"[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour][offset_minute]",
"[weekday repr:short] [month repr:short] [day] [hour]:[minute]:[second] [year] [offset_hour][offset_minute]",
"[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second] [offset_hour][offset_minute]",
];

impl AsUnixTimeStamp for String {
fn as_timestamp(&self) -> Option<i64> {
(self as &str).as_timestamp()
}
}

impl AsUnixTimeStamp for &str {
fn as_timestamp(&self) -> Option<i64> {
let to_parse = {
// transforms `wanted (....)` to wanted
self.splitn(2, " (")
.find(|x| !x.is_empty())
.unwrap_or_default()
};

SUPPORTED_FORMATS
.iter()
.map(|x| parse_or_panic(x))
.filter_map(|x| OffsetDateTime::parse(to_parse, &x).ok())
.map(|x| x.unix_timestamp())
.next()
}
}

#[cfg(test)]
mod tests {
use super::AsUnixTimeStamp;

#[test]
fn date_string() {
let example = "2018-09-07 11:08:31 +0200 (Fri, 07 Sep 2018)";
assert_eq!(example.as_timestamp(), Some(1536311311));
}

#[test]
fn iso_orientated() {
let example = "2012-09-23 02:15:34 -0400";
assert_eq!(example.as_timestamp(), Some(1348380934));
let example = "2012-09-23 02:15:34 +0400";
assert_eq!(example.as_timestamp(), Some(1348352134));
}

#[test]
fn something_else() {
let example = "Fri Feb 10 16:09:30 2023 +0100";
assert_eq!(example.as_timestamp(), Some(1676041770));
let example = "Fri, 10 Feb 2023 16:09:30 +0100";
assert_eq!(example.as_timestamp(), Some(1676041770));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete, unused

Comment on lines +1 to +5
---
source: crates/greenbone-scanner-framework/src/get_scans.rs
expression: resp
---
[""]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete, unused

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get a test error when I remove this snap file. Do you mean greenbone_scanner_framework__get_scans__tests__get_scans.snap because that doesn't seem to be used?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, my bad. Didn't mentally parse the diff between the two file names :D

@tsurai

tsurai commented Jul 30, 2026

Copy link
Copy Markdown
Author

If I run cargo insta --unreferenced=delete on this PR, I find three unused snapshots. One of them was created, not moved, but I haven't looked into what happened with the other two. I checked and found some missing tests, on main I get 689 tests in total, on this branch I get 686. This fits with the three unused snapshots.

One of those was a copy-paste fail the other two are also unreferenced on main and I cannot trace back to when they actually last had running tests. The difference in numbers might be due to the time module now being unused and its three tests were skipped?

@Tehforsch

Copy link
Copy Markdown
Contributor

If I run cargo insta --unreferenced=delete on this PR, I find three unused snapshots. One of them was created, not moved, but I haven't looked into what happened with the other two. I checked and found some missing tests, on main I get 689 tests in total, on this branch I get 686. This fits with the three unused snapshots.

One of those was a copy-paste fail the other two are also unreferenced on main and I cannot trace back to when they actually last had running tests.

Haven't looked in detail but I dont get any unused snapshots running cargo insta test --review --unreferenced=delete on current main.

The difference in numbers might be due to the time module now being unused and its three tests were skipped?

But the time module still exists? It just temporarily existed twice, unless I'm missing something

@tsurai

tsurai commented Jul 30, 2026

Copy link
Copy Markdown
Author

Haven't looked in detail but I dont get any unused snapshots running cargo insta test --review --unreferenced=delete on current main.

For whatever reason running cargo insta test --review --unreferenced=delete doesn't seem to actually pickup the tests in rust/crates/greenbone-scanner-framework unless you run it from that directory.

So when run from /rust or /rust/src/openvasd I get no unused snapshots, but I do get them when run from /rust/crates/greenbone-scanner-framework on main

The greenbone-scanner-framework crate is being split into two parts.
A models crate containing shared data used among the workspace and the
API related code only used by openvasd. The later is moved directly into
openvasd as a module.

This is an intermediary step in preperation of a major API rework towards
axum.
@tsurai
tsurai force-pushed the greenbone-scanner-framework-split branch from 97e3052 to 57bd05d Compare July 31, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants