Skip to content

Commit

Permalink
chore: revert to non-scoped setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Oct 31, 2024
1 parent 8422748 commit ab103bd
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 225 deletions.
28 changes: 12 additions & 16 deletions modules/analysis/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<AnalysisService>,
) -> actix_web::Result<impl Responder> {
Expand All @@ -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<AnalysisService>,
web::Query(search): web::Query<Query>,
Expand All @@ -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<AnalysisService>,
key: web::Path<String>,
Expand Down Expand Up @@ -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<AnalysisService>,
web::Query(search): web::Query<Query>,
Expand All @@ -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<AnalysisService>,
key: web::Path<String>,
Expand Down
4 changes: 2 additions & 2 deletions modules/fundamental/src/advisory/endpoints/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdvisoryService>,
id: web::Path<Id>,
Expand All @@ -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<AdvisoryService>,
id: web::Path<Id>,
Expand Down
36 changes: 16 additions & 20 deletions modules/fundamental/src/advisory/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -64,7 +60,7 @@ pub fn configure(
(status = 200, description = "Matching vulnerabilities", body = PaginatedResults<AdvisorySummary>),
),
)]
#[get("")]
#[get("/v1/advisory")]
/// List advisories
pub async fn all(
state: web::Data<AdvisoryService>,
Expand All @@ -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<AdvisoryService>,
Expand All @@ -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<AdvisoryService>,
Expand Down Expand Up @@ -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<IngestorService>,
Expand Down Expand Up @@ -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<IngestorService>,
Expand Down
24 changes: 10 additions & 14 deletions modules/fundamental/src/ai/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<AiService>,
request: web::Json<ChatState>,
Expand All @@ -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<AiService>) -> actix_web::Result<impl Responder> {
Ok(HttpResponse::Ok().json(AiFlags {
Expand All @@ -66,7 +62,7 @@ pub async fn flags(service: web::Data<AiService>) -> actix_web::Result<impl Resp
(status = 404, description = "The AI service is not enabled")
)
)]
#[get("/tools")]
#[get("/v1/ai/tools")]
// Gets the list of tools that are available to assist AI services.
pub async fn tools(service: web::Data<AiService>) -> actix_web::Result<impl Responder> {
let tools = &service
Expand Down Expand Up @@ -94,7 +90,7 @@ pub async fn tools(service: web::Data<AiService>) -> actix_web::Result<impl Resp
(status = 404, description = "The tool was not found")
)
)]
#[post("/tools/{name}")]
#[post("/v1/ai/tools/{name}")]
pub async fn tool_call(
service: web::Data<AiService>,
name: web::Path<String>,
Expand Down
24 changes: 10 additions & 14 deletions modules/fundamental/src/license/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -44,7 +40,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d
(status = 200, description = "Matching licenses", body = PaginatedResults<LicenseSummary>),
),
)]
#[get("")]
#[get("/v1/license")]
/// List licenses
pub async fn list_licenses(
state: web::Data<LicenseService>,
Expand All @@ -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<LicenseService>,
Expand All @@ -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<LicenseService>,
Expand Down
4 changes: 2 additions & 2 deletions modules/fundamental/src/license/endpoints/spdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use trustify_common::{
(status = 200, description = "Matching licenses", body = PaginatedResults<SpdxLicenseSummary>),
),
)]
#[get("/spdx/license")]
#[get("/v1/license/spdx/license")]
/// List SPDX licenses
pub async fn list_spdx_licenses(
state: web::Data<LicenseService>,
Expand All @@ -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<LicenseService>,
Expand Down
16 changes: 6 additions & 10 deletions modules/fundamental/src/organization/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<OrganizationService>,
Expand All @@ -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<OrganizationService>,
Expand Down
20 changes: 8 additions & 12 deletions modules/fundamental/src/product/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -39,7 +35,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d
(status = 200, description = "Matching products", body = PaginatedResults<ProductSummary>),
),
)]
#[get("")]
#[get("/v1/product")]
pub async fn all(
state: web::Data<ProductService>,
web::Query(search): web::Query<Query>,
Expand All @@ -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<ProductService>,
id: web::Path<Uuid>,
Expand All @@ -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<ProductService>,
id: web::Path<Uuid>,
Expand Down
Loading

0 comments on commit ab103bd

Please sign in to comment.