Skip to content

Commit e3ec2ac

Browse files
committed
chore: change API version to v2
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
1 parent 0d08059 commit e3ec2ac

File tree

39 files changed

+266
-266
lines changed

39 files changed

+266
-266
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ zipped archive of SBOMs and/or Advisories like so:
3434
```shell
3535
cd etc/datasets
3636
make
37-
http POST localhost:8080/api/v1/dataset @ds1.zip
37+
http POST localhost:8080/api/v2/dataset @ds1.zip
3838
```
3939

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

4646
```shell
47-
cat some-sbom.json | http POST localhost:8080/api/v1/sbom
48-
cat some-advisory.json | http POST localhost:8080/api/v1/advisory
47+
cat some-sbom.json | http POST localhost:8080/api/v2/sbom
48+
cat some-advisory.json | http POST localhost:8080/api/v2/advisory
4949
```
5050

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

141141
#### If test failures on OSX
142142

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

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

155155
Starting a containerized Postgres instance:

modules/analysis/src/endpoints.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn configure(config: &mut utoipa_actix_web::service_config::ServiceConfig, d
3232
(status = 200, description = "Analysis status.", body = AnalysisStatus),
3333
),
3434
)]
35-
#[get("/v1/analysis/status")]
35+
#[get("/v2/analysis/status")]
3636
pub async fn analysis_status(
3737
service: web::Data<AnalysisService>,
3838
db: web::Data<Database>,
@@ -55,7 +55,7 @@ pub async fn analysis_status(
5555
(status = 200, description = "Search component(s) and return their root components.", body = AncestorSummary),
5656
),
5757
)]
58-
#[get("/v1/analysis/root-component")]
58+
#[get("/v2/analysis/root-component")]
5959
pub async fn search_component_root_components(
6060
service: web::Data<AnalysisService>,
6161
db: web::Data<Database>,
@@ -80,7 +80,7 @@ pub async fn search_component_root_components(
8080
(status = 200, description = "Retrieve component(s) root components by name or pURL.", body = AncestorSummary),
8181
),
8282
)]
83-
#[get("/v1/analysis/root-component/{key}")]
83+
#[get("/v2/analysis/root-component/{key}")]
8484
pub async fn get_component_root_components(
8585
service: web::Data<AnalysisService>,
8686
db: web::Data<Database>,
@@ -115,7 +115,7 @@ pub async fn get_component_root_components(
115115
(status = 200, description = "Search component(s) and return their deps.", body = DepSummary),
116116
),
117117
)]
118-
#[get("/v1/analysis/dep")]
118+
#[get("/v2/analysis/dep")]
119119
pub async fn search_component_deps(
120120
service: web::Data<AnalysisService>,
121121
db: web::Data<Database>,
@@ -140,7 +140,7 @@ pub async fn search_component_deps(
140140
(status = 200, description = "Retrieve component(s) dep components by name or pURL.", body = DepSummary),
141141
),
142142
)]
143-
#[get("/v1/analysis/dep/{key}")]
143+
#[get("/v2/analysis/dep/{key}")]
144144
pub async fn get_component_deps(
145145
service: web::Data<AnalysisService>,
146146
db: web::Data<Database>,
@@ -183,7 +183,7 @@ mod test {
183183
ctx.ingest_documents(["spdx/simple.json"]).await?;
184184

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

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

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

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

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

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

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

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

@@ -268,7 +268,7 @@ mod test {
268268
])
269269
.await?;
270270

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

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

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

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

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

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

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

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

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

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

360-
let uri = "/api/v1/analysis/dep/A";
360+
let uri = "/api/v2/analysis/dep/A";
361361

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

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

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

415-
let uri = "/api/v1/analysis/dep?q=spymemcached";
415+
let uri = "/api/v2/analysis/dep?q=spymemcached";
416416

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

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

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

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

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

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

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

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

@@ -486,7 +486,7 @@ mod test {
486486

487487
// Find all deps of src rpm
488488
let src = "pkg:rpm/redhat/[email protected]_2?arch=src";
489-
let uri = format!("/api/v1/analysis/dep/{}", urlencoding::encode(src));
489+
let uri = format!("/api/v2/analysis/dep/{}", urlencoding::encode(src));
490490
let request: Request = TestRequest::get().uri(&uri).to_request();
491491
let response: Value = app.call_and_read_body_json(request).await;
492492
log::debug!("{response:#?}");
@@ -495,7 +495,7 @@ mod test {
495495
// Ensure binary rpm GeneratedFrom src rpm
496496
let x86 = "pkg:rpm/redhat/[email protected]_2?arch=x86_64";
497497
let uri = format!(
498-
"/api/v1/analysis/root-component/{}",
498+
"/api/v2/analysis/root-component/{}",
499499
urlencoding::encode(x86)
500500
);
501501
let request: Request = TestRequest::get().uri(&uri).to_request();

modules/fundamental/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
By PURL:
77

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

1212
By package ID (as returned by other APIs):
1313

1414
```bash
15-
http localhost:8080/api/v1/sbom/by-purl id==6cfff15d-ee06-4cb7-be37-a835aed2af82
15+
http localhost:8080/api/v2/sbom/by-purl id==6cfff15d-ee06-4cb7-be37-a835aed2af82
1616
```

modules/fundamental/src/advisory/endpoints/label.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use trustify_entity::labels::Labels;
1818
(status = 404, description = "The advisory could not be found"),
1919
),
2020
)]
21-
#[put("/v1/advisory/{id}/label")]
21+
#[put("/v2/advisory/{id}/label")]
2222
pub async fn set(
2323
advisory: web::Data<AdvisoryService>,
2424
db: web::Data<Database>,
@@ -50,7 +50,7 @@ pub async fn set(
5050
(status = 404, description = "The advisory could not be found"),
5151
),
5252
)]
53-
#[patch("/v1/advisory/{id}/label")]
53+
#[patch("/v2/advisory/{id}/label")]
5454
pub async fn update(
5555
advisory: web::Data<AdvisoryService>,
5656
id: web::Path<Id>,

modules/fundamental/src/advisory/endpoints/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn configure(
6464
(status = 200, description = "Matching vulnerabilities", body = PaginatedResults<AdvisorySummary>),
6565
),
6666
)]
67-
#[get("/v1/advisory")]
67+
#[get("/v2/advisory")]
6868
/// List advisories
6969
pub async fn all(
7070
state: web::Data<AdvisoryService>,
@@ -92,7 +92,7 @@ pub async fn all(
9292
(status = 404, description = "Matching advisory not found"),
9393
),
9494
)]
95-
#[get("/v1/advisory/{key}")]
95+
#[get("/v2/advisory/{key}")]
9696
/// Get an advisory
9797
pub async fn get(
9898
state: web::Data<AdvisoryService>,
@@ -121,7 +121,7 @@ pub async fn get(
121121
(status = 404, description = "Matching advisory not found"),
122122
),
123123
)]
124-
#[delete("/v1/advisory/{key}")]
124+
#[delete("/v2/advisory/{key}")]
125125
/// Delete an advisory
126126
pub async fn delete(
127127
state: web::Data<AdvisoryService>,
@@ -175,7 +175,7 @@ struct UploadParams {
175175
(status = 400, description = "The file could not be parsed as an advisory"),
176176
)
177177
)]
178-
#[post("/v1/advisory")]
178+
#[post("/v2/advisory")]
179179
/// Upload a new advisory
180180
pub async fn upload(
181181
service: web::Data<IngestorService>,
@@ -204,7 +204,7 @@ pub async fn upload(
204204
(status = 404, description = "The document could not be found"),
205205
)
206206
)]
207-
#[get("/v1/advisory/{key}/download")]
207+
#[get("/v2/advisory/{key}/download")]
208208
/// Download an advisory document
209209
pub async fn download(
210210
db: web::Data<Database>,

0 commit comments

Comments
 (0)