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: #1112
  • Loading branch information
ctron committed Jan 15, 2025
1 parent 0d08059 commit e3ec2ac
Show file tree
Hide file tree
Showing 39 changed files with 266 additions and 266 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ zipped archive of SBOMs and/or Advisories like so:
```shell
cd etc/datasets
make
http POST localhost:8080/api/v1/dataset @ds1.zip
http POST localhost:8080/api/v2/dataset @ds1.zip
```

#### Upload
Expand All @@ -44,8 +44,8 @@ There is an "Upload" menu option in the GUI: http://localhost:8080/upload
You can also interact with the API directly in a shell:

```shell
cat some-sbom.json | http POST localhost:8080/api/v1/sbom
cat some-advisory.json | http POST localhost:8080/api/v1/advisory
cat some-sbom.json | http POST localhost:8080/api/v2/sbom
cat some-advisory.json | http POST localhost:8080/api/v2/advisory
```

#### Importers
Expand Down Expand Up @@ -140,7 +140,7 @@ If you haven't already, [get started!](https://www.rust-lang.org/learn/get-start

#### If test failures on OSX

Potentially our concurrent Postgres installations during testing can
Potentially, our concurrent Postgres installations during testing can
exhaust shared-memory. Adjusting shared-memory on OSX is not
straight-forward. Use [this
guide](https://unix.stackexchange.com/questions/689295/values-from-sysctl-a-dont-match-etc-sysctl-conf-even-after-restart).
Expand All @@ -149,7 +149,7 @@ guide](https://unix.stackexchange.com/questions/689295/values-from-sysctl-a-dont

Unit tests and "PM mode" use an embedded instance of Postgres that is
installed as required on the local filesystem. This is convenient for
local development but you can also configure the app to use an
local development, but you can also configure the app to use an
external database.

Starting a containerized Postgres instance:
Expand Down
50 changes: 25 additions & 25 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 All @@ -486,7 +486,7 @@ mod test {

// Find all deps of src rpm
let src = "pkg:rpm/redhat/[email protected]_2?arch=src";
let uri = format!("/api/v1/analysis/dep/{}", urlencoding::encode(src));
let uri = format!("/api/v2/analysis/dep/{}", urlencoding::encode(src));
let request: Request = TestRequest::get().uri(&uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
log::debug!("{response:#?}");
Expand All @@ -495,7 +495,7 @@ mod test {
// Ensure binary rpm GeneratedFrom src rpm
let x86 = "pkg:rpm/redhat/[email protected]_2?arch=x86_64";
let uri = format!(
"/api/v1/analysis/root-component/{}",
"/api/v2/analysis/root-component/{}",
urlencoding::encode(x86)
);
let request: Request = TestRequest::get().uri(&uri).to_request();
Expand Down
4 changes: 2 additions & 2 deletions modules/fundamental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
By PURL:

```bash
http localhost:8080/api/v1/sbom/by-purl purl==pkg:maven/org.apache.xmlgraphics/[email protected]
http localhost:8080/api/v2/sbom/by-purl purl==pkg:maven/org.apache.xmlgraphics/[email protected]
```

By package ID (as returned by other APIs):

```bash
http localhost:8080/api/v1/sbom/by-purl id==6cfff15d-ee06-4cb7-be37-a835aed2af82
http localhost:8080/api/v2/sbom/by-purl id==6cfff15d-ee06-4cb7-be37-a835aed2af82
```
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 e3ec2ac

Please sign in to comment.