Skip to content

Commit

Permalink
chore: change API version to v2
Browse files Browse the repository at this point in the history
BREAKING-CHANGE: This changes the prefix of the API from
/api/v1 to /api/v2 as this is the successor API of trustification (v1).

Closes: trustification#1112
  • Loading branch information
ctron committed Jan 13, 2025
1 parent 4a7ae84 commit f0b048b
Show file tree
Hide file tree
Showing 35 changed files with 239 additions and 239 deletions.
46 changes: 23 additions & 23 deletions modules/analysis/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d
(status = 200, description = "Analysis status.", body = AnalysisStatus),
),
)]
#[get("/v1/analysis/status")]
#[get("/v2/analysis/status")]
pub async fn analysis_status(
service: web::Data<AnalysisService>,
db: web::Data<Database>,
Expand All @@ -55,7 +55,7 @@ pub async fn analysis_status(
(status = 200, description = "Search component(s) and return their root components.", body = AncestorSummary),
),
)]
#[get("/v1/analysis/root-component")]
#[get("/v2/analysis/root-component")]
pub async fn search_component_root_components(
service: web::Data<AnalysisService>,
db: web::Data<Database>,
Expand All @@ -80,7 +80,7 @@ pub async fn search_component_root_components(
(status = 200, description = "Retrieve component(s) root components by name or pURL.", body = AncestorSummary),
),
)]
#[get("/v1/analysis/root-component/{key}")]
#[get("/v2/analysis/root-component/{key}")]
pub async fn get_component_root_components(
service: web::Data<AnalysisService>,
db: web::Data<Database>,
Expand Down Expand Up @@ -115,7 +115,7 @@ pub async fn get_component_root_components(
(status = 200, description = "Search component(s) and return their deps.", body = DepSummary),
),
)]
#[get("/v1/analysis/dep")]
#[get("/v2/analysis/dep")]
pub async fn search_component_deps(
service: web::Data<AnalysisService>,
db: web::Data<Database>,
Expand All @@ -140,7 +140,7 @@ pub async fn search_component_deps(
(status = 200, description = "Retrieve component(s) dep components by name or pURL.", body = DepSummary),
),
)]
#[get("/v1/analysis/dep/{key}")]
#[get("/v2/analysis/dep/{key}")]
pub async fn get_component_deps(
service: web::Data<AnalysisService>,
db: web::Data<Database>,
Expand Down Expand Up @@ -183,7 +183,7 @@ mod test {
ctx.ingest_documents(["spdx/simple.json"]).await?;

//should match multiple components
let uri = "/api/v1/analysis/root-component?q=B";
let uri = "/api/v2/analysis/root-component?q=B";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;

Expand All @@ -197,7 +197,7 @@ mod test {
log::info!("{:?}", response);

//should match a single component
let uri = "/api/v1/analysis/root-component?q=BB";
let uri = "/api/v2/analysis/root-component?q=BB";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
assert_eq!(response["items"][0]["purl"], "pkg:rpm/redhat/[email protected]");
Expand All @@ -218,7 +218,7 @@ mod test {
let app = caller(ctx).await?;
ctx.ingest_documents(["spdx/simple.json"]).await?;

let uri = "/api/v1/analysis/root-component/B";
let uri = "/api/v2/analysis/root-component/B";

let request: Request = TestRequest::get().uri(uri).to_request();

Expand All @@ -241,7 +241,7 @@ mod test {
let app = caller(ctx).await?;
ctx.ingest_documents(["spdx/simple.json"]).await?;

let uri = "/api/v1/analysis/root-component/pkg%3A%2F%2Frpm%2Fredhat%2FB%400.0.0";
let uri = "/api/v2/analysis/root-component/pkg%3A%2F%2Frpm%2Fredhat%2FB%400.0.0";

let request: Request = TestRequest::get().uri(uri).to_request();

Expand All @@ -268,7 +268,7 @@ mod test {
])
.await?;

let uri = "/api/v1/analysis/root-component?q=spymemcached";
let uri = "/api/v2/analysis/root-component?q=spymemcached";

let request: Request = TestRequest::get().uri(uri).to_request();

Expand Down Expand Up @@ -300,11 +300,11 @@ mod test {
ctx.ingest_documents(["spdx/simple.json"]).await?;

//prime the graph hashmap
let uri = "/api/v1/analysis/root-component?q=BB";
let uri = "/api/v2/analysis/root-component?q=BB";
let load1 = TestRequest::get().uri(uri).to_request();
let _response: Value = app.call_and_read_body_json(load1).await;

let uri = "/api/v1/analysis/status";
let uri = "/api/v2/analysis/status";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;

Expand All @@ -314,7 +314,7 @@ mod test {
// ingest duplicate sbom which has different date
ctx.ingest_documents(["spdx/simple-dup.json"]).await?;

let uri = "/api/v1/analysis/status";
let uri = "/api/v2/analysis/status";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;

Expand All @@ -330,7 +330,7 @@ mod test {
let app = caller(ctx).await?;
ctx.ingest_documents(["spdx/simple.json"]).await?;

let uri = "/api/v1/analysis/dep?q=A";
let uri = "/api/v2/analysis/dep?q=A";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;

Expand All @@ -357,7 +357,7 @@ mod test {
let app = caller(ctx).await?;
ctx.ingest_documents(["spdx/simple.json"]).await?;

let uri = "/api/v1/analysis/dep/A";
let uri = "/api/v2/analysis/dep/A";

let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
Expand Down Expand Up @@ -385,7 +385,7 @@ mod test {
let app = caller(ctx).await?;
ctx.ingest_documents(["spdx/simple.json"]).await?;

let uri = "/api/v1/analysis/dep/pkg%3A%2F%2Frpm%2Fredhat%2FAA%400.0.0%3Farch%3Dsrc";
let uri = "/api/v2/analysis/dep/pkg%3A%2F%2Frpm%2Fredhat%2FAA%400.0.0%3Farch%3Dsrc";

let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
Expand All @@ -412,7 +412,7 @@ mod test {
])
.await?;

let uri = "/api/v1/analysis/dep?q=spymemcached";
let uri = "/api/v2/analysis/dep?q=spymemcached";

let request: Request = TestRequest::get().uri(uri).to_request();

Expand All @@ -435,41 +435,41 @@ mod test {
ctx.ingest_documents(["spdx/simple.json"]).await?;

// filter on node_id
let uri = "/api/v1/analysis/dep?q=node_id%3DSPDXRef-A";
let uri = "/api/v2/analysis/dep?q=node_id%3DSPDXRef-A";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
assert_eq!(response["items"][0]["name"], "A");
assert_eq!(&response["total"], 1);

// filter on node_id
let uri = "/api/v1/analysis/root-component?q=node_id%3DSPDXRef-B";
let uri = "/api/v2/analysis/root-component?q=node_id%3DSPDXRef-B";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
assert_eq!(response["items"][0]["name"], "B");
assert_eq!(&response["total"], 1);

// filter on node_id & name
let uri = "/api/v1/analysis/root-component?q=node_id%3DSPDXRef-B%26name%3DB";
let uri = "/api/v2/analysis/root-component?q=node_id%3DSPDXRef-B%26name%3DB";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
assert_eq!(response["items"][0]["name"], "B");
assert_eq!(&response["total"], 1);

// filter on sbom_id (which has urn:uuid: prefix)
let sbom_id = response["items"][0]["sbom_id"].as_str().unwrap();
let uri = format!("/api/v1/analysis/root-component?q=sbom_id={}", sbom_id);
let uri = format!("/api/v2/analysis/root-component?q=sbom_id={}", sbom_id);
let request: Request = TestRequest::get().uri(uri.clone().as_str()).to_request();
let response: Value = app.call_and_read_body_json(request).await;
assert_eq!(&response["total"], 8);

// negative test
let uri = "/api/v1/analysis/root-component?q=sbom_id=urn:uuid:99999999-9999-9999-9999-999999999999";
let uri = "/api/v2/analysis/root-component?q=sbom_id=urn:uuid:99999999-9999-9999-9999-999999999999";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
assert_eq!(&response["total"], 0);

// negative test
let uri = "/api/v1/analysis/root-component?q=node_id%3DSPDXRef-B%26name%3DA";
let uri = "/api/v2/analysis/root-component?q=node_id%3DSPDXRef-B%26name%3DA";
let request: Request = TestRequest::get().uri(uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;

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 @@ -18,7 +18,7 @@ use trustify_entity::labels::Labels;
(status = 404, description = "The advisory could not be found"),
),
)]
#[put("/v1/advisory/{id}/label")]
#[put("/v2/advisory/{id}/label")]
pub async fn set(
advisory: web::Data<AdvisoryService>,
db: web::Data<Database>,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub async fn set(
(status = 404, description = "The advisory could not be found"),
),
)]
#[patch("/v1/advisory/{id}/label")]
#[patch("/v2/advisory/{id}/label")]
pub async fn update(
advisory: web::Data<AdvisoryService>,
id: web::Path<Id>,
Expand Down
10 changes: 5 additions & 5 deletions modules/fundamental/src/advisory/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn configure(
(status = 200, description = "Matching vulnerabilities", body = PaginatedResults<AdvisorySummary>),
),
)]
#[get("/v1/advisory")]
#[get("/v2/advisory")]
/// List advisories
pub async fn all(
state: web::Data<AdvisoryService>,
Expand Down Expand Up @@ -92,7 +92,7 @@ pub async fn all(
(status = 404, description = "Matching advisory not found"),
),
)]
#[get("/v1/advisory/{key}")]
#[get("/v2/advisory/{key}")]
/// Get an advisory
pub async fn get(
state: web::Data<AdvisoryService>,
Expand Down Expand Up @@ -121,7 +121,7 @@ pub async fn get(
(status = 404, description = "Matching advisory not found"),
),
)]
#[delete("/v1/advisory/{key}")]
#[delete("/v2/advisory/{key}")]
/// Delete an advisory
pub async fn delete(
state: web::Data<AdvisoryService>,
Expand Down Expand Up @@ -175,7 +175,7 @@ struct UploadParams {
(status = 400, description = "The file could not be parsed as an advisory"),
)
)]
#[post("/v1/advisory")]
#[post("/v2/advisory")]
/// Upload a new advisory
pub async fn upload(
service: web::Data<IngestorService>,
Expand Down Expand Up @@ -204,7 +204,7 @@ pub async fn upload(
(status = 404, description = "The document could not be found"),
)
)]
#[get("/v1/advisory/{key}/download")]
#[get("/v2/advisory/{key}/download")]
/// Download an advisory document
pub async fn download(
db: web::Data<Database>,
Expand Down
Loading

0 comments on commit f0b048b

Please sign in to comment.