From c018e9e9e73fc21a5f4b9fa80e116c1be4ba5120 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Fri, 12 Apr 2024 15:05:43 +0200 Subject: [PATCH 1/9] fix: properly set name of downloaded sbom --- genealogos-frontend/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genealogos-frontend/index.html b/genealogos-frontend/index.html index c960b94..b4d6688 100644 --- a/genealogos-frontend/index.html +++ b/genealogos-frontend/index.html @@ -259,7 +259,7 @@ // Create a temporary anchor element const anchor = document.createElement("a"); anchor.href = URL.createObjectURL(blob); - anchor.download = `${installable}.sbom.json`; + anchor.download = `${decodeURIComponent(latestInstallable)}.sbom.json`; // Programmatically click the anchor element to trigger the download anchor.click(); From 3be2036a9d073bb97cad7ac944dd5822e35317dd Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Fri, 12 Apr 2024 15:06:00 +0200 Subject: [PATCH 2/9] feat: statically serve index.html when accessing / --- genealogos-api/src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/genealogos-api/src/main.rs b/genealogos-api/src/main.rs index ef37fdf..c1e6254 100644 --- a/genealogos-api/src/main.rs +++ b/genealogos-api/src/main.rs @@ -4,7 +4,7 @@ use genealogos::args::BomArg; use genealogos::backend::Backend; use genealogos::bom::Bom; use rocket::http::Status; -use rocket::response::status; +use rocket::response::{content, status}; use rocket::serde::json::Json; use rocket::tokio::sync::Mutex; use rocket::Request; @@ -22,6 +22,14 @@ fn handle_errors(req: &Request) -> status::Custom { ) } +#[rocket::get("/")] +fn index() -> status::Custom> { + status::Custom( + Status::Ok, + content::RawHtml(include_str!("../../genealogos-frontend/index.html")), + ) +} + #[rocket::get("/analyze?&")] fn analyze(installable: &str, bom_format: Option) -> Result { let start_time = std::time::Instant::now(); @@ -63,6 +71,7 @@ fn rocket() -> _ { )); }) })) + .mount("/", rocket::routes![index]) .mount("/api", rocket::routes![analyze]) .register("/api", rocket::catchers![handle_errors]) .mount( From 4f52e3537e320924cf5f2b6b906e6e4b5f031757 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Fri, 12 Apr 2024 15:15:52 +0200 Subject: [PATCH 3/9] feat: hide fancy frontend behind a feature flag --- genealogos-api/Cargo.toml | 5 +++++ genealogos-api/src/main.rs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/genealogos-api/Cargo.toml b/genealogos-api/Cargo.toml index 0067aa7..7730789 100644 --- a/genealogos-api/Cargo.toml +++ b/genealogos-api/Cargo.toml @@ -31,6 +31,11 @@ urlencoding.workspace = true pretty_assertions.workspace = true [features] +default = [ "frontend" ] + # This feature should be enabled when running tests in a Nix environment. # It disables all tests that require a working internet connection. nix = [] + +# Enabling this feature makes Genealogos server a gui frontend at IP:PORT/ +frontend = [] diff --git a/genealogos-api/src/main.rs b/genealogos-api/src/main.rs index c1e6254..98c820c 100644 --- a/genealogos-api/src/main.rs +++ b/genealogos-api/src/main.rs @@ -23,6 +23,7 @@ fn handle_errors(req: &Request) -> status::Custom { } #[rocket::get("/")] +#[cfg(feature = "frontend")] fn index() -> status::Custom> { status::Custom( Status::Ok, @@ -30,6 +31,15 @@ fn index() -> status::Custom> { ) } +#[rocket::get("/")] +#[cfg(not(feature = "frontend"))] +fn index() -> status::Custom> { + status::Custom( + Status::Ok, + content::RawHtml("

Genealogos is running

"), + ) +} + #[rocket::get("/analyze?&")] fn analyze(installable: &str, bom_format: Option) -> Result { let start_time = std::time::Instant::now(); From 59e0da9e72fbff1a15bec19ceff617d62b4e7575 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Fri, 12 Apr 2024 15:37:53 +0200 Subject: [PATCH 4/9] fix: change default package to genealogos --- nix/crane.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/crane.nix b/nix/crane.nix index e7b8b18..8981a6a 100644 --- a/nix/crane.nix +++ b/nix/crane.nix @@ -71,7 +71,7 @@ rec { packages = rust-packages // { - default = packages.genealogos; + default = packages.genealogos-cli; workspace = crane-lib.buildPackage workspace; From 180682d33a8cb352539c911d7abc2973d4698fa3 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Mon, 15 Apr 2024 08:35:07 +0200 Subject: [PATCH 5/9] chore: add .html to crane build --- nix/crane.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nix/crane.nix b/nix/crane.nix index e7b8b18..4da9cd0 100644 --- a/nix/crane.nix +++ b/nix/crane.nix @@ -8,7 +8,13 @@ let common-crane-args = { pname = "genealogos"; - src = crane-lib.cleanCargoSource (crane-lib.path ../.); + + # We need to also include the frontend .html file for the include_str macro in the api + src = pkgs.lib.cleanSourceWith { + src = crane-lib.path ../.; + filter = path: type: (crane-lib.filterCargoSources path type) || (builtins.match ".*/genealogos-frontend/index.html" path != null); + }; + strictDeps = true; cargoArtifacts = cargo-artifacts; From 91bd35b5c98cd0a273e1b72609724be768f7c880 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Mon, 15 Apr 2024 08:46:01 +0200 Subject: [PATCH 6/9] chore: update changelog, readme --- CHANGELOG.md | 1 + README.md | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45ee713..28c6b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [#38](https://github.com/tweag/genealogos/pull/38) display nixtract's status information when running - [#44](https://github.com/tweag/genealogos/pull/44) adds two functions to the `Backend` trait to set options - [#48](https://github.com/tweag/genealogos/pull/48) added a NixOS module to our flake +- [#50](https://github.com/tweag/genealogos/pull/50) included the frontend in rocket behind the `frontend` feature flag ### Changed - [#41](https://github.com/tweag/genealogos/pull/41) reworked the Genealogos fronend, paving the way for supporting other bom formats diff --git a/README.md b/README.md index 47320ed..38c1446 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,9 @@ Changing this default can be done using the settings button in the top of the we The Web UI currently only supports analyzing from a flake ref and attribute path, analyzing from a trace file is not yet supported. +The frontend can be opened by opening the `index.html`file in your favourite webbrowser. +Alternatively, if the `genealogos-api` was built with the `frontend` feature-flag, the frontend can be accessed at the root of wherever the api is hosted (e.g. `http://localhost:8000/`). + ### NixOS Module The flake in this project provides a NixOS Module to host Genealogos. Once the module has been added to your NixOS configuration, Genealogos can be enabled with: From 4c99a30b21550aa551e494f51801ceb828ecf862 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Mon, 15 Apr 2024 10:46:39 +0200 Subject: [PATCH 7/9] chore: fix typo in readme Co-authored-by: Yann Hamdaoui --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 38c1446..e5e5c98 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Changing this default can be done using the settings button in the top of the we The Web UI currently only supports analyzing from a flake ref and attribute path, analyzing from a trace file is not yet supported. -The frontend can be opened by opening the `index.html`file in your favourite webbrowser. +The frontend can be opened by opening the `index.html`file in your favourite web browser. Alternatively, if the `genealogos-api` was built with the `frontend` feature-flag, the frontend can be accessed at the root of wherever the api is hosted (e.g. `http://localhost:8000/`). ### NixOS Module From 23e4850bb660d48fd323845fefb7321c9a7e6f85 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Mon, 15 Apr 2024 16:17:51 +0200 Subject: [PATCH 8/9] feat: put -o back There existed an issue where passing -f and an output would interpret that output as the Installable, and not accept it. --- genealogos-cli/src/main.rs | 5 +++-- scripts/update-fixture-output-files.sh | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/genealogos-cli/src/main.rs b/genealogos-cli/src/main.rs index 39ffc9d..00650ae 100644 --- a/genealogos-cli/src/main.rs +++ b/genealogos-cli/src/main.rs @@ -14,14 +14,15 @@ use genealogos::backend::{Backend, BackendHandle}; #[command(author, version, about)] struct Args { /// Path to the input nixtract file - #[arg(short, long, required_unless_present = "installable")] + #[arg(short, long, required_unless_present = "installable", group = "input")] file: Option, /// Nix installable (e.g. `nixpkgs#hello`) - #[arg(required_unless_present = "file")] + #[arg(required_unless_present = "file", group = "input")] installable: Option, /// Optional path to the output CycloneDX file (default: stdout) + #[arg(long, short)] output_file: Option, /// Backend to use for Nix evaluation tracing diff --git a/scripts/update-fixture-output-files.sh b/scripts/update-fixture-output-files.sh index bc848ad..1d04acd 100755 --- a/scripts/update-fixture-output-files.sh +++ b/scripts/update-fixture-output-files.sh @@ -9,7 +9,7 @@ for input_file in ./genealogos/tests/fixtures/nixtract/trace-files/*.in; do output_file_1_4=${input_file%.in}.1_4.out # output_file_1_5=${input_file%.in}.1_5.out echo "Updating: $output_file_1_4" - GENEALOGOS_DETERMINISTIC=1 genealogos --file "$input_file" "$output_file_1_4" --bom cyclonedx_1.4_json + GENEALOGOS_DETERMINISTIC=1 genealogos --file "$input_file" -o "$output_file_1_4" --bom cyclonedx_1.4_json # TODO: Update to 1.5 # echo "Updating: $output_file_1_5" # GENEALOGOS_DETERMINISTIC=1 genealogos --file "$input_file" "$output_file_1_5" --cyclonedx-version 1.5 @@ -21,7 +21,7 @@ for input_file in ./genealogos/tests/fixtures/nixtract/flakes/*.in; do flake_ref=$(jq -r .flake_ref < "$input_file") attribute_path=$(jq -r .attribute_path < "$input_file") echo "Updating: $output_file_1_4" - GENEALOGOS_DETERMINISTIC=1 genealogos --flake-ref "$flake_ref" --attribute-path "$attribute_path" "$output_file_1_4" --bom cyclonedx_1.4_json + GENEALOGOS_DETERMINISTIC=1 genealogos --flake-ref "$flake_ref" --attribute-path "$attribute_path" -o "$output_file_1_4" --bom cyclonedx_1.4_json # echo "Updating: $output_file_1_5" # GENEALOGOS_DETERMINISTIC=1 genealogos --flake-ref "$flake_ref" --attribute-path "$attribute_path" "$output_file_1_5" --cyclonedx-version 1.5 done From 44723856f5c653d1cacf09ccbd6e776e6b65064a Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Tue, 16 Apr 2024 12:40:37 +0200 Subject: [PATCH 9/9] chore: fix broken links in readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e5e5c98..5d11bfe 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@

The Genealogos project is a tool that takes output from Nix evaluation tools and produces BOM files. -Currently, it takes input from [nixtract][nixtract] and produces json output compliant with the [CycloneDX][cyclonedx] 1.3 or 1.4 specification. +Currently, it takes input from [nixtract][nixtract-url] and produces json output compliant with the [CycloneDX][cyclonedx-url] 1.3 or 1.4 specification. Output from Genealogos can be used by various other tools to perform further analysis. Note Nix is mainly just suitable for Software, and so the BOM output by Genealogos is nearly always an SBOM. @@ -195,6 +195,8 @@ GitHub: [https://github.com/tweag/genealogos](https://github.com/tweag/genealogo [discord-url]: https://discord.gg/fFymRGGRDG [tweag-logo]: ./assets/tweag.png [tweag-url]: https://tweag.io +[nixtract-url]: https://github.com/tweag/nixtract +[cyclonedx-url]: https://cyclonedx.org/ [screenshot]: ./assets/screenshot.png [genealogos-logo]: ./assets/genealogos.png