diff --git a/modules/analysis/src/endpoints.rs b/modules/analysis/src/endpoints.rs index 8cac7ae3..433be113 100644 --- a/modules/analysis/src/endpoints.rs +++ b/modules/analysis/src/endpoints.rs @@ -7,20 +7,16 @@ use actix_web::{get, web, HttpResponse, Responder}; use std::str::FromStr; use trustify_common::{db::query::Query, db::Database, model::Paginated, purl::Purl}; -pub const CONTEXT_PATH: &str = "/v1/analysis"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let analysis = AnalysisService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(analysis)) - .service(search_component_root_components) - .service(get_component_root_components) - .service(analysis_status) - .service(search_component_deps) - .service(get_component_deps), - ); + config + .app_data(web::Data::new(analysis)) + .service(search_component_root_components) + .service(get_component_root_components) + .service(analysis_status) + .service(search_component_deps) + .service(get_component_deps); } #[utoipa::path( @@ -30,7 +26,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 200, description = "Analysis status.", body = AnalysisStatus), ), )] -#[get("/status")] +#[get("/v1/analysis/status")] pub async fn analysis_status( service: web::Data, ) -> actix_web::Result { @@ -48,7 +44,7 @@ pub async fn analysis_status( (status = 200, description = "Search component(s) and return their root components.", body = AncestorSummary), ), )] -#[get("/root-component")] +#[get("/v1/analysis/root-component")] pub async fn search_component_root_components( service: web::Data, web::Query(search): web::Query, @@ -71,7 +67,7 @@ pub async fn search_component_root_components( (status = 200, description = "Retrieve component(s) root components by name or pURL.", body = AncestorSummary), ), )] -#[get("/root-component/{key}")] +#[get("/v1/analysis/root-component/{key}")] pub async fn get_component_root_components( service: web::Data, key: web::Path, @@ -104,7 +100,7 @@ pub async fn get_component_root_components( (status = 200, description = "Search component(s) and return their deps.", body = DepSummary), ), )] -#[get("/dep")] +#[get("/v1/analysis/dep")] pub async fn search_component_deps( service: web::Data, web::Query(search): web::Query, @@ -123,7 +119,7 @@ pub async fn search_component_deps( (status = 200, description = "Retrieve component(s) dep components by name or pURL.", body = DepSummary), ), )] -#[get("/dep/{key}")] +#[get("/v1/analysis/dep/{key}")] pub async fn get_component_deps( service: web::Data, key: web::Path, diff --git a/modules/fundamental/src/advisory/endpoints/label.rs b/modules/fundamental/src/advisory/endpoints/label.rs index 1f44b293..24526f7c 100644 --- a/modules/fundamental/src/advisory/endpoints/label.rs +++ b/modules/fundamental/src/advisory/endpoints/label.rs @@ -16,7 +16,7 @@ use trustify_entity::labels::Labels; (status = 404, description = "The advisory could not be found"), ), )] -#[put("/{id}/label")] +#[put("/v1/advisory/{id}/label")] pub async fn set( advisory: web::Data, id: web::Path, @@ -43,7 +43,7 @@ pub async fn set( (status = 404, description = "The advisory could not be found"), ), )] -#[patch("/{id}/label")] +#[patch("/v1/advisory/{id}/label")] pub async fn update( advisory: web::Data, id: web::Path, diff --git a/modules/fundamental/src/advisory/endpoints/mod.rs b/modules/fundamental/src/advisory/endpoints/mod.rs index b6e90274..66fbe323 100644 --- a/modules/fundamental/src/advisory/endpoints/mod.rs +++ b/modules/fundamental/src/advisory/endpoints/mod.rs @@ -27,8 +27,6 @@ use trustify_module_ingestor::service::{Format, IngestorService}; use trustify_module_storage::service::StorageBackend; use utoipa::IntoParams; -pub const CONTEXT_PATH: &str = "/v1/advisory"; - pub fn configure( config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database, @@ -37,19 +35,17 @@ pub fn configure( let advisory_service = AdvisoryService::new(db.clone()); let purl_service = PurlService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(advisory_service)) - .app_data(web::Data::new(purl_service)) - .app_data(web::Data::new(Config { upload_limit })) - .service(all) - .service(get) - .service(delete) - .service(upload) - .service(download) - .service(label::set) - .service(label::update), - ); + config + .app_data(web::Data::new(advisory_service)) + .app_data(web::Data::new(purl_service)) + .app_data(web::Data::new(Config { upload_limit })) + .service(all) + .service(get) + .service(delete) + .service(upload) + .service(download) + .service(label::set) + .service(label::update); } #[utoipa::path( @@ -64,7 +60,7 @@ pub fn configure( (status = 200, description = "Matching vulnerabilities", body = PaginatedResults), ), )] -#[get("")] +#[get("/v1/advisory")] /// List advisories pub async fn all( state: web::Data, @@ -90,7 +86,7 @@ pub async fn all( (status = 404, description = "Matching advisory not found"), ), )] -#[get("/{key}")] +#[get("/v1/advisory/{key}")] /// Get an advisory pub async fn get( state: web::Data, @@ -117,7 +113,7 @@ pub async fn get( (status = 404, description = "Matching advisory not found"), ), )] -#[delete("/{key}")] +#[delete("/v1/advisory/{key}")] /// Delete an advisory pub async fn delete( state: web::Data, @@ -166,7 +162,7 @@ struct UploadParams { (status = 400, description = "The file could not be parsed as an advisory"), ) )] -#[post("")] +#[post("/v1/advisory")] /// Upload a new advisory pub async fn upload( service: web::Data, @@ -194,7 +190,7 @@ pub async fn upload( (status = 404, description = "The document could not be found"), ) )] -#[get("/{key}/download")] +#[get("/v1/advisory/{key}/download")] /// Download an advisory document pub async fn download( ingestor: web::Data, diff --git a/modules/fundamental/src/ai/endpoints/mod.rs b/modules/fundamental/src/ai/endpoints/mod.rs index 1cc59415..3461f6ab 100644 --- a/modules/fundamental/src/ai/endpoints/mod.rs +++ b/modules/fundamental/src/ai/endpoints/mod.rs @@ -9,18 +9,14 @@ use actix_web::{get, post, web, HttpResponse, Responder}; use itertools::Itertools; use trustify_common::db::Database; -pub const CONTEXT_PATH: &str = "/v1/ai"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let service = AiService::new(db.clone()); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(service)) - .service(completions) - .service(flags) - .service(tools) - .service(tool_call), - ); + config + .app_data(web::Data::new(service)) + .service(completions) + .service(flags) + .service(tools) + .service(tool_call); } #[utoipa::path( @@ -33,7 +29,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 404, description = "The AI service is not enabled") ) )] -#[post("/completions")] +#[post("/v1/ai/completions")] pub async fn completions( service: web::Data, request: web::Json, @@ -50,7 +46,7 @@ pub async fn completions( (status = 404, description = "The AI service is not enabled") ) )] -#[get("/flags")] +#[get("/v1/ai/flags")] // Gets the flags for the AI service pub async fn flags(service: web::Data) -> actix_web::Result { Ok(HttpResponse::Ok().json(AiFlags { @@ -66,7 +62,7 @@ pub async fn flags(service: web::Data) -> actix_web::Result) -> actix_web::Result { let tools = &service @@ -94,7 +90,7 @@ pub async fn tools(service: web::Data) -> actix_web::Result, name: web::Path, diff --git a/modules/fundamental/src/license/endpoints/mod.rs b/modules/fundamental/src/license/endpoints/mod.rs index dea80267..15a433f2 100644 --- a/modules/fundamental/src/license/endpoints/mod.rs +++ b/modules/fundamental/src/license/endpoints/mod.rs @@ -17,20 +17,16 @@ use uuid::Uuid; pub mod spdx; -pub const CONTEXT_PATH: &str = "/v1/license"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let license_service = LicenseService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(license_service)) - .service(list_spdx_licenses) - .service(get_spdx_license) - .service(list_licenses) - .service(get_license) - .service(get_license_purls), - ); + config + .app_data(web::Data::new(license_service)) + .service(list_spdx_licenses) + .service(get_spdx_license) + .service(list_licenses) + .service(get_license) + .service(get_license_purls); } #[utoipa::path( @@ -44,7 +40,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 200, description = "Matching licenses", body = PaginatedResults), ), )] -#[get("")] +#[get("/v1/license")] /// List licenses pub async fn list_licenses( state: web::Data, @@ -61,7 +57,7 @@ pub async fn list_licenses( (status = 200, description = "The license", body = LicenseSummary), ), )] -#[get("/{uuid}")] +#[get("/v1/license/{uuid}")] /// Retrieve license details pub async fn get_license( state: web::Data, @@ -81,7 +77,7 @@ pub async fn get_license( (status = 200, description = "The versioned pURLs allowing the license", body = LicenseSummary), ), )] -#[get("/{uuid}/purl")] +#[get("/v1/license/{uuid}/purl")] /// Retrieve pURLs covered by a license pub async fn get_license_purls( state: web::Data, diff --git a/modules/fundamental/src/license/endpoints/spdx.rs b/modules/fundamental/src/license/endpoints/spdx.rs index 4b0d6248..582dd222 100644 --- a/modules/fundamental/src/license/endpoints/spdx.rs +++ b/modules/fundamental/src/license/endpoints/spdx.rs @@ -18,7 +18,7 @@ use trustify_common::{ (status = 200, description = "Matching licenses", body = PaginatedResults), ), )] -#[get("/spdx/license")] +#[get("/v1/license/spdx/license")] /// List SPDX licenses pub async fn list_spdx_licenses( state: web::Data, @@ -37,7 +37,7 @@ pub async fn list_spdx_licenses( (status = 200, description = "SPDX license details", body = SpdxLicenseDetails), ), )] -#[get("/spdx/license/{id}")] +#[get("/v1/license/spdx/license/{id}")] /// Get SPDX license details pub async fn get_spdx_license( state: web::Data, diff --git a/modules/fundamental/src/organization/endpoints/mod.rs b/modules/fundamental/src/organization/endpoints/mod.rs index b764245e..4f317213 100644 --- a/modules/fundamental/src/organization/endpoints/mod.rs +++ b/modules/fundamental/src/organization/endpoints/mod.rs @@ -12,16 +12,12 @@ use trustify_common::{ }; use uuid::Uuid; -pub const CONTEXT_PATH: &str = "/v1/organization"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let service = OrganizationService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(service)) - .service(all) - .service(get), - ); + config + .app_data(web::Data::new(service)) + .service(all) + .service(get); } #[utoipa::path( @@ -35,7 +31,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 200, description = "Matching organizations", body = OrganizationSummary), ), )] -#[get("")] +#[get("/v1/organization")] /// List organizations pub async fn all( state: web::Data, @@ -56,7 +52,7 @@ pub async fn all( (status = 404, description = "Matching organization not found"), ), )] -#[get("/{id}")] +#[get("/v1/organization/{id}")] /// Retrieve organization details pub async fn get( state: web::Data, diff --git a/modules/fundamental/src/product/endpoints/mod.rs b/modules/fundamental/src/product/endpoints/mod.rs index 3b171235..e8d49454 100644 --- a/modules/fundamental/src/product/endpoints/mod.rs +++ b/modules/fundamental/src/product/endpoints/mod.rs @@ -15,17 +15,13 @@ use trustify_common::{ }; use uuid::Uuid; -pub const CONTEXT_PATH: &str = "/v1/product"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let service = ProductService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(service)) - .service(all) - .service(delete) - .service(get), - ); + config + .app_data(web::Data::new(service)) + .service(all) + .service(delete) + .service(get); } #[utoipa::path( @@ -39,7 +35,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 200, description = "Matching products", body = PaginatedResults), ), )] -#[get("")] +#[get("/v1/product")] pub async fn all( state: web::Data, web::Query(search): web::Query, @@ -59,7 +55,7 @@ pub async fn all( (status = 404, description = "Matching product not found"), ), )] -#[get("/{id}")] +#[get("/v1/product/{id}")] pub async fn get( state: web::Data, id: web::Path, @@ -83,7 +79,7 @@ pub async fn get( (status = 404, description = "Matching product not found"), ), )] -#[delete("/{id}")] +#[delete("/v1/product/{id}")] pub async fn delete( state: web::Data, id: web::Path, diff --git a/modules/fundamental/src/purl/endpoints/base.rs b/modules/fundamental/src/purl/endpoints/base.rs index 9e1001db..564a15c2 100644 --- a/modules/fundamental/src/purl/endpoints/base.rs +++ b/modules/fundamental/src/purl/endpoints/base.rs @@ -19,7 +19,7 @@ use trustify_common::{db::query::Query, id::IdError, model::Paginated, purl::Pur (status = 200, description = "Details for the versionless base PURL", body = BasePurlDetails), ), )] -#[get("/base/{key}")] +#[get("/v1/purl/base/{key}")] /// Retrieve details about a base versionless pURL pub async fn get_base_purl( service: web::Data, @@ -45,7 +45,7 @@ pub async fn get_base_purl( (status = 200, description = "All relevant matching versionless base PURL", body = PaginatedResults), ), )] -#[get("/base")] +#[get("/v1/purl/base")] /// List base versionless pURLs pub async fn all_base_purls( service: web::Data, diff --git a/modules/fundamental/src/purl/endpoints/mod.rs b/modules/fundamental/src/purl/endpoints/mod.rs index 9f4098fe..3c3e9424 100644 --- a/modules/fundamental/src/purl/endpoints/mod.rs +++ b/modules/fundamental/src/purl/endpoints/mod.rs @@ -18,24 +18,20 @@ mod base; mod r#type; mod version; -pub const CONTEXT_PATH: &str = "/v1/purl"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let purl_service = PurlService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(purl_service)) - .service(r#type::all_purl_types) - .service(r#type::get_purl_type) - .service(r#type::get_base_purl_of_type) - .service(r#type::get_versioned_purl_of_type) - .service(base::get_base_purl) - .service(base::all_base_purls) - .service(version::get_versioned_purl) - .service(get) - .service(all), - ); + config + .app_data(web::Data::new(purl_service)) + .service(r#type::all_purl_types) + .service(r#type::get_purl_type) + .service(r#type::get_base_purl_of_type) + .service(r#type::get_versioned_purl_of_type) + .service(base::get_base_purl) + .service(base::all_base_purls) + .service(version::get_versioned_purl) + .service(get) + .service(all); } #[utoipa::path( @@ -49,7 +45,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 200, description = "Details for the qualified PURL", body = PurlDetails), ), )] -#[get("/{key}")] +#[get("/v1/purl/{key}")] /// Retrieve details of a fully-qualified pURL pub async fn get( service: web::Data, @@ -76,7 +72,7 @@ pub async fn get( (status = 200, description = "All relevant matching qualified PURLs", body = PaginatedResults), ), )] -#[get("")] +#[get("/v1/purl")] /// List fully-qualified pURLs pub async fn all( service: web::Data, diff --git a/modules/fundamental/src/purl/endpoints/type.rs b/modules/fundamental/src/purl/endpoints/type.rs index 3bc12c5a..dbf2d391 100644 --- a/modules/fundamental/src/purl/endpoints/type.rs +++ b/modules/fundamental/src/purl/endpoints/type.rs @@ -17,7 +17,7 @@ use trustify_common::{db::query::Query, model::Paginated, model::PaginatedResult (status = 200, description = "List of all known PURL types", body = Vec), ), )] -#[get("/type")] +#[get("/v1/purl/type")] /// List known pURL types pub async fn all_purl_types(service: web::Data) -> actix_web::Result { Ok(HttpResponse::Ok().json(service.purl_types(()).await?)) @@ -35,7 +35,7 @@ pub async fn all_purl_types(service: web::Data) -> actix_web::Resul (status = 200, description = "Information regarding PURLs within an type", body = PaginatedResults), ), )] -#[get("/type/{type}")] +#[get("/v1/purl/type/{type}")] /// Retrieve details about a pURL type pub async fn get_purl_type( service: web::Data, @@ -62,7 +62,7 @@ pub async fn get_purl_type( (status = 200, description = "Matching vulnerabilities", body = BasePurlDetails), ), )] -#[get("/type/{type}/{namespace_and_name:[^@]+}")] +#[get("/v1/purl/type/{type}/{namespace_and_name:[^@]+}")] /// Retrieve base pURL details of a type pub async fn get_base_purl_of_type( service: web::Data, @@ -91,7 +91,7 @@ pub async fn get_base_purl_of_type( (status = 200, description = "Matching vulnerabilities", body = VersionedPurlDetails), ), )] -#[get("/type/{type}/{namespace_and_name:[^@]+}@{version}")] +#[get("/v1/purl/type/{type}/{namespace_and_name:[^@]+}@{version}")] /// Retrieve versioned pURL details of a type pub async fn get_versioned_purl_of_type( service: web::Data, diff --git a/modules/fundamental/src/purl/endpoints/version.rs b/modules/fundamental/src/purl/endpoints/version.rs index 5f628bb2..346b03f0 100644 --- a/modules/fundamental/src/purl/endpoints/version.rs +++ b/modules/fundamental/src/purl/endpoints/version.rs @@ -17,7 +17,7 @@ use trustify_common::{id::IdError, purl::Purl}; (status = 200, description = "Details for the version of a PURL", body = VersionedPurlDetails), ), )] -#[get("/version/{key}")] +#[get("/v1/purl/version/{key}")] /// Retrieve details of a versioned, non-qualified pURL pub async fn get_versioned_purl( service: web::Data, diff --git a/modules/fundamental/src/sbom/endpoints/label.rs b/modules/fundamental/src/sbom/endpoints/label.rs index 542629d3..7fc2aedf 100644 --- a/modules/fundamental/src/sbom/endpoints/label.rs +++ b/modules/fundamental/src/sbom/endpoints/label.rs @@ -16,7 +16,7 @@ use trustify_entity::labels::Labels; (status = 404, description = "The SBOM could not be found"), ), )] -#[patch("/{id}/label")] +#[patch("/v1/sbom/{id}/label")] pub async fn update( sbom: web::Data, id: web::Path, @@ -46,7 +46,7 @@ pub async fn update( (status = 404, description = "The SBOM could not be found"), ), )] -#[put("/{id}/label")] +#[put("/v1/sbom/{id}/label")] pub async fn set( sbom: web::Data, id: web::Path, diff --git a/modules/fundamental/src/sbom/endpoints/mod.rs b/modules/fundamental/src/sbom/endpoints/mod.rs index 440a5170..f8d36c04 100644 --- a/modules/fundamental/src/sbom/endpoints/mod.rs +++ b/modules/fundamental/src/sbom/endpoints/mod.rs @@ -39,8 +39,6 @@ use trustify_module_ingestor::{ }; use trustify_module_storage::service::StorageBackend; -pub const CONTEXT_PATH: &str = "/v1/sbom"; - pub fn configure( config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database, @@ -49,24 +47,22 @@ pub fn configure( let sbom_service = SbomService::new(db.clone()); let purl_service = PurlService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(sbom_service)) - .app_data(web::Data::new(purl_service)) - .app_data(web::Data::new(Config { upload_limit })) - .service(all) - .service(all_related) - .service(count_related) - .service(get) - .service(get_sbom_advisories) - .service(delete) - .service(packages) - .service(related) - .service(upload) - .service(download) - .service(label::set) - .service(label::update), - ); + config + .app_data(web::Data::new(sbom_service)) + .app_data(web::Data::new(purl_service)) + .app_data(web::Data::new(Config { upload_limit })) + .service(all) + .service(all_related) + .service(count_related) + .service(get) + .service(get_sbom_advisories) + .service(delete) + .service(packages) + .service(related) + .service(upload) + .service(download) + .service(label::set) + .service(label::update); } #[utoipa::path( @@ -80,7 +76,7 @@ pub fn configure( (status = 200, description = "Matching SBOMs", body = PaginatedResults), ), )] -#[get("")] +#[get("/v1/sbom")] pub async fn all( fetch: web::Data, web::Query(search): web::Query, @@ -161,7 +157,7 @@ impl TryFrom for Uuid { (status = 200, description = "Matching SBOMs", body = PaginatedResults), ), )] -#[get("/by-package")] +#[get("/v1/sbom/by-package")] pub async fn all_related( sbom: web::Data, web::Query(search): web::Query, @@ -193,7 +189,7 @@ pub async fn all_related( (status = 200, description = "Number of matching SBOMs per package", body = Vec), ), )] -#[get("/count-by-package")] +#[get("/v1/sbom/count-by-package")] pub async fn count_related( sbom: web::Data, web::Json(ids): web::Json>, @@ -223,7 +219,7 @@ pub async fn count_related( (status = 404, description = "Matching SBOM not found"), ), )] -#[get("/{id}")] +#[get("/v1/sbom/{id}")] pub async fn get( fetcher: web::Data, authorizer: web::Data, @@ -250,7 +246,7 @@ pub async fn get( (status = 404, description = "Matching SBOM not found"), ), )] -#[get("/{id}/advisory")] +#[get("/v1/sbom/{id}/advisory")] pub async fn get_sbom_advisories( fetcher: web::Data, authorizer: web::Data, @@ -278,7 +274,7 @@ pub async fn get_sbom_advisories( (status = 404, description = "Matching SBOM not found"), ), )] -#[delete("/{id}")] +#[delete("/v1/sbom/{id}")] pub async fn delete( service: web::Data, purl_service: web::Data, @@ -318,7 +314,7 @@ pub async fn delete( (status = 200, description = "Packages", body = PaginatedResults), ), )] -#[get("/{id}/packages")] +#[get("/v1/sbom/{id}/packages")] pub async fn packages( fetch: web::Data, id: web::Path, @@ -363,7 +359,7 @@ struct RelatedQuery { (status = 200, description = "Packages", body = PaginatedResults), ), )] -#[get("/{id}/related")] +#[get("/v1/sbom/{id}/related")] pub async fn related( fetch: web::Data, id: web::Path, @@ -417,7 +413,7 @@ struct UploadQuery { (status = 400, description = "The file could not be parsed as an advisory"), ) )] -#[post("")] +#[post("/v1/sbom")] /// Upload a new SBOM pub async fn upload( service: web::Data, @@ -443,7 +439,7 @@ pub async fn upload( (status = 404, description = "The document could not be found"), ) )] -#[get("/{key}/download")] +#[get("/v1/sbom/{key}/download")] pub async fn download( ingestor: web::Data, sbom: web::Data, diff --git a/modules/fundamental/src/vulnerability/endpoints/mod.rs b/modules/fundamental/src/vulnerability/endpoints/mod.rs index 7fbf8c0b..8b6a2674 100644 --- a/modules/fundamental/src/vulnerability/endpoints/mod.rs +++ b/modules/fundamental/src/vulnerability/endpoints/mod.rs @@ -15,17 +15,13 @@ use trustify_common::{ model::{Paginated, PaginatedResults}, }; -pub const CONTEXT_PATH: &str = "/v1/vulnerability"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let service = VulnerabilityService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(service)) - .service(all) - .service(delete) - .service(get), - ); + config + .app_data(web::Data::new(service)) + .service(all) + .service(delete) + .service(get); } #[utoipa::path( @@ -39,7 +35,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 200, description = "Matching vulnerabilities", body = PaginatedResults), ), )] -#[get("")] +#[get("/v1/vulnerability")] /// List vulnerabilities pub async fn all( state: web::Data, @@ -65,7 +61,7 @@ pub async fn all( (status = 404, description = "Specified vulnerability not found"), ), )] -#[get("/{id}")] +#[get("/v1/vulnerability/{id}")] /// Retrieve vulnerability details pub async fn get( state: web::Data, @@ -93,7 +89,7 @@ pub async fn get( (status = 404, description = "Specified vulnerability not found"), ), )] -#[delete("/{id}")] +#[delete("/v1/vulnerability/{id}")] /// Delete vulnerability pub async fn delete( state: web::Data, diff --git a/modules/fundamental/src/weakness/endpoints/mod.rs b/modules/fundamental/src/weakness/endpoints/mod.rs index dc2ae241..76eab855 100644 --- a/modules/fundamental/src/weakness/endpoints/mod.rs +++ b/modules/fundamental/src/weakness/endpoints/mod.rs @@ -5,17 +5,13 @@ use trustify_common::{ model::{Paginated, PaginatedResults}, }; -pub const CONTEXT_PATH: &str = "/v1/weakness"; - pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { let weakness_service = WeaknessService::new(db); - config.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .app_data(web::Data::new(weakness_service)) - .service(list_weaknesses) - .service(get_weakness), - ); + config + .app_data(web::Data::new(weakness_service)) + .service(list_weaknesses) + .service(get_weakness); } #[utoipa::path( @@ -29,7 +25,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d (status = 200, description = "Matching weaknesses", body = PaginatedResults), ), )] -#[get("")] +#[get("/v1/weakness")] /// List weaknesses pub async fn list_weaknesses( state: web::Data, @@ -46,7 +42,7 @@ pub async fn list_weaknesses( (status = 200, description = "The weakness", body = LicenseSummary), ), )] -#[get("/{id}")] +#[get("/v1/weakness/{id}")] /// Retrieve weakness details pub async fn get_weakness( state: web::Data, diff --git a/modules/importer/src/endpoints.rs b/modules/importer/src/endpoints.rs index 84531e2a..a528e3e2 100644 --- a/modules/importer/src/endpoints.rs +++ b/modules/importer/src/endpoints.rs @@ -12,23 +12,18 @@ use trustify_common::{ model::{Paginated, PaginatedResults, Revisioned}, }; -pub const CONTEXT_PATH: &str = "/v1/importer"; - /// mount the "importer" module pub fn configure(svc: &mut utoipa_actix_web::service_config::ServiceConfig, db: Database) { - svc.app_data(web::Data::new(ImporterService::new(db))); - svc.service( - utoipa_actix_web::scope(CONTEXT_PATH) - .service(list) - .service(create) - .service(read) - .service(update) - .service(patch_json_merge) - .service(delete) - .service(get_reports) - .service(set_enabled) - .service(force), - ); + svc.app_data(web::Data::new(ImporterService::new(db))) + .service(list) + .service(create) + .service(read) + .service(update) + .service(patch_json_merge) + .service(delete) + .service(get_reports) + .service(set_enabled) + .service(force); } #[utoipa::path( @@ -38,7 +33,7 @@ pub fn configure(svc: &mut utoipa_actix_web::service_config::ServiceConfig, db: (status = 200, description = "List importer configurations", body = [Importer]) ) )] -#[get("")] +#[get("/v1/importer")] /// List importer configurations async fn list(service: web::Data) -> Result { Ok(web::Json(service.list().await?)) @@ -56,7 +51,7 @@ async fn list(service: web::Data) -> Result, @@ -83,7 +78,7 @@ async fn create( (status = 404, description = "An importer with that name could not be found") ) )] -#[get("/{name}")] +#[get("/v1/importer/{name}")] /// Get an importer configuration async fn read( service: web::Data, @@ -113,7 +108,7 @@ async fn read( (status = 412, description = "The provided if-match header did not match the stored revision"), ) )] -#[put("/{name}")] +#[put("/v1/importer/{name}")] /// Update an existing importer configuration async fn update( service: web::Data, @@ -150,7 +145,7 @@ async fn update( (status = 412, description = "The provided if-match header did not match the stored revision"), ) )] -#[patch("/{name}", guard = "guards::json_merge")] +#[patch("/v1/importer/{name}", guard = "guards::json_merge")] /// Update an existing importer configuration async fn patch_json_merge( service: web::Data, @@ -188,7 +183,7 @@ async fn patch_json_merge( (status = 412, description = "The provided if-match header did not match the stored revision"), ) )] -#[put("/{name}/enabled")] +#[put("/v1/importer/{name}/enabled")] /// Update an existing importer configuration async fn set_enabled( service: web::Data, @@ -225,7 +220,7 @@ async fn set_enabled( (status = 412, description = "The provided if-match header did not match the stored revision"), ) )] -#[post("/{name}/force")] +#[post("/v1/importer/{name}/force")] /// Force an importer to run as soon as possible async fn force( service: web::Data, @@ -253,7 +248,7 @@ async fn force( (status = 201, description = "Delete the importer configuration"), ) )] -#[delete("/{name}")] +#[delete("/v1/importer/{name}")] /// Delete an importer configuration async fn delete( service: web::Data, @@ -278,7 +273,7 @@ async fn delete( (status = 200, description = "Retrieved importer reports", body = PaginatedResults), ) )] -#[get("/{name}/report")] +#[get("/v1/importer/{name}/report")] /// Get reports for an importer async fn get_reports( service: web::Data, diff --git a/modules/ingestor/src/endpoints.rs b/modules/ingestor/src/endpoints.rs index 80cb0f75..72e3921b 100644 --- a/modules/ingestor/src/endpoints.rs +++ b/modules/ingestor/src/endpoints.rs @@ -8,8 +8,6 @@ use trustify_entity::labels::Labels; use trustify_module_storage::service::dispatch::DispatchBackend; use utoipa::IntoParams; -pub const CONTEXT_PATH: &str = "/v1/ingestor"; - /// mount the "ingestor" module pub fn configure( svc: &mut utoipa_actix_web::service_config::ServiceConfig, @@ -21,7 +19,7 @@ pub fn configure( svc.app_data(web::Data::new(ingestor_service)) .app_data(web::Data::new(config)) - .service(utoipa_actix_web::scope(CONTEXT_PATH).service(upload_dataset)); + .service(upload_dataset); } #[derive(Clone, Debug, Eq, PartialEq, Default)] @@ -51,7 +49,7 @@ struct UploadParams { (status = 400, description = "The file could not be parsed as an dataset"), ) )] -#[post("/dataset")] +#[post("/v1/dataset")] /// Upload a new dataset pub async fn upload_dataset( service: web::Data, diff --git a/modules/ingestor/tests/limit.rs b/modules/ingestor/tests/limit.rs index 6ac0ee78..87339b70 100644 --- a/modules/ingestor/tests/limit.rs +++ b/modules/ingestor/tests/limit.rs @@ -30,7 +30,7 @@ async fn upload_bomb_dataset(ctx: &TrustifyContext) -> anyhow::Result<()> { dataset.finish()?; let request = TestRequest::post() - .uri("/api/v1/ingestor/dataset") + .uri("/api/v1/dataset") .set_payload(data) .to_request(); diff --git a/openapi.yaml b/openapi.yaml index a4889608..709d94ef 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -446,6 +446,34 @@ paths: application/json: schema: $ref: '#/components/schemas/AnalysisStatus' + /api/v1/dataset: + post: + tags: + - dataset + summary: Upload a new dataset + operationId: uploadDataset + parameters: + - name: labels + in: query + description: |- + Optional labels. + + Only use keys with a prefix of `labels.` + required: true + schema: + $ref: '#/components/schemas/Labels' + requestBody: + content: + application/json: + schema: + type: string + format: binary + required: true + responses: + '201': + description: Uploaded the dataset + '400': + description: The file could not be parsed as an dataset /api/v1/importer: get: tags: @@ -686,34 +714,6 @@ paths: application/json: schema: $ref: '#/components/schemas/PaginatedResults_ImporterReport' - /api/v1/ingestor/dataset: - post: - tags: - - dataset - summary: Upload a new dataset - operationId: uploadDataset - parameters: - - name: labels - in: query - description: |- - Optional labels. - - Only use keys with a prefix of `labels.` - required: true - schema: - $ref: '#/components/schemas/Labels' - requestBody: - content: - application/json: - schema: - type: string - format: binary - required: true - responses: - '201': - description: Uploaded the dataset - '400': - description: The file could not be parsed as an dataset /api/v1/license: get: tags: