From 64c638eaa7726c24c3affd32cc8fff36a3033c30 Mon Sep 17 00:00:00 2001 From: David Mears Date: Tue, 26 Nov 2024 16:26:10 +0000 Subject: [PATCH 1/6] Add custom metadata to packit/metadata endpoint --- src/metadata.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/metadata.rs b/src/metadata.rs index 75d0c37..a6233b6 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -19,6 +19,7 @@ pub struct PackitPacket { pub name: String, pub parameters: Option>, pub time: PacketTime, + pub custom: Option, } impl PackitPacket { @@ -28,6 +29,7 @@ impl PackitPacket { name: packet.name.to_string(), parameters: packet.parameters.clone(), time: packet.time.clone(), + custom: packet.custom.clone(), } } } From d2ce6fb6dee1c0d85382be5d90252951ad7b2995 Mon Sep 17 00:00:00 2001 From: David Mears Date: Tue, 26 Nov 2024 16:55:02 +0000 Subject: [PATCH 2/6] Update api schema --- schema/server/list.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/schema/server/list.json b/schema/server/list.json index f21b6d5..cceb661 100644 --- a/schema/server/list.json +++ b/schema/server/list.json @@ -17,6 +17,7 @@ "description": "Task parameters, used when running and for querying", "type": ["null", "object"] }, + "time": { "description": "Information about the running time", "start": { @@ -27,6 +28,11 @@ "description": "Time that the report was completed, in seconds since 1970-01-01", "type": "number" } + }, + + "custom": { + "description": "Optional custom metadata, grouped under application keys", + "type": ["null", "object"] } }, "required": ["id", "name"], From 169988981289d40d0732a2624e9642b7add77e79 Mon Sep 17 00:00:00 2001 From: David Mears Date: Tue, 26 Nov 2024 17:05:00 +0000 Subject: [PATCH 3/6] Update unit test for packit/metadata endpoint --- tests/test_api.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_api.rs b/tests/test_api.rs index dcce3d9..969f4f0 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -277,6 +277,13 @@ async fn can_list_metadata() { entries[0].get("time").unwrap().get("end").unwrap(), 1503074938.2232 ); + assert_eq!( + entries[0].get("custom").unwrap().as_object().unwrap() + .get("orderly").unwrap().as_object().unwrap() + .get("artefacts").unwrap().as_array().unwrap()[3] + .get("description").unwrap().as_str().unwrap(), + "Projected Coverage for routine immunisation in PINE countries" + ); assert_eq!( entries[1].get("id").unwrap().as_str().unwrap(), "20170818-164847-7574883b" From e58c783d8ffcbc0c37366a9d644f40b501e9f94c Mon Sep 17 00:00:00 2001 From: David Mears Date: Tue, 26 Nov 2024 17:05:20 +0000 Subject: [PATCH 4/6] Update README --- README.md | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7e48c3d..ba8e692 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Run all tests with `cargo test`. ## API ### GET / -``` +```json { "status": "succcess", "data": { @@ -66,17 +66,17 @@ Returns hash of all current packet ids, ordered alphanumerically and concatenate in the `outpack` config, unless a query parameter specifying an alternative is passed: e.g. `/checksum?alg=md5`. -``` +```json { "status": "succcess", - "data": "md5:117723186364b4b409081b1bd347d406" + "data": "md5:117723186364b4b409081b1bd347d406", "errors": null } ``` ### GET /metadata/list -``` +```json { "status": "success", "errors": null, @@ -113,7 +113,7 @@ from which to return results. This will filter packets by the `time` property of location metadata, i.e. the point at which they were inserted into the index. e.g. `/packit/metadata?known_since=1683117048`. -``` +```json { "status": "success", "errors": null, @@ -121,14 +121,22 @@ e.g. `/packit/metadata?known_since=1683117048`. { "id": "20220812-155808-c873e405", "name": "depends", - "custom": { "orderly": { "display": "Report with dependencies" }} - "parameters": null + "parameters": null, + "time": { + "end": 1503074545.8687, + "start": 1503074545.8687 + }, + "custom": { "orderly": { "description": { "display": "Report with dependencies" }}}, }, { "id": "20220812-155808-d5747caf", "name": "params", - "custom": { "orderly": { "display": "Report with parameters" }}, - "parameters": { "alpha": 1 } + "parameters": { "alpha": 1 }, + "time": { + "start": 1722267993.0676, + "end": 1722267993.0971 + }, + "custom": { "orderly": { "description": { "display": "Report with parameters" }}}, } ] } @@ -137,7 +145,7 @@ e.g. `/packit/metadata?known_since=1683117048`. ### GET /metadata/\/json -``` +```json { "status": "success", "errors": null, @@ -223,7 +231,7 @@ Given a list of ids, returns those that are missing in the current root. If `unp returns missing unpacked packets, otherwise just looks at missing metadata. #### Response -``` +```json { "status": "success", "errors": null, @@ -246,7 +254,7 @@ returns missing unpacked packets, otherwise just looks at missing metadata. Given a list of file hashes, returns those that are missing in the current root. #### Response -``` +```json { "status": "success", "errors": null, @@ -265,7 +273,7 @@ The file contents should be written directly to the request body. #### Response -``` +```json { "status": "success", "errors": null, @@ -284,7 +292,7 @@ The metadata should be written directly to the request body. #### Response -``` +```json { "status": "success", "errors": null, @@ -302,7 +310,7 @@ Returns an array of branches with their `name`, `commit_hash` (where branch poin #### Response -``` +```json { "status": "success", "data": { From 23d2e262a30dc4168552c8842bb304cb2670e4a5 Mon Sep 17 00:00:00 2001 From: David Mears Date: Tue, 26 Nov 2024 17:12:39 +0000 Subject: [PATCH 5/6] Formatting --- tests/test_api.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_api.rs b/tests/test_api.rs index 969f4f0..6ea1541 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -278,10 +278,23 @@ async fn can_list_metadata() { 1503074938.2232 ); assert_eq!( - entries[0].get("custom").unwrap().as_object().unwrap() - .get("orderly").unwrap().as_object().unwrap() - .get("artefacts").unwrap().as_array().unwrap()[3] - .get("description").unwrap().as_str().unwrap(), + entries[0] + .get("custom") + .unwrap() + .as_object() + .unwrap() + .get("orderly") + .unwrap() + .as_object() + .unwrap() + .get("artefacts") + .unwrap() + .as_array() + .unwrap()[3] + .get("description") + .unwrap() + .as_str() + .unwrap(), "Projected Coverage for routine immunisation in PINE countries" ); assert_eq!( From 9176a78cb4b64502c49c1cc66d5747645c656e58 Mon Sep 17 00:00:00 2001 From: David Mears Date: Wed, 27 Nov 2024 13:00:58 +0000 Subject: [PATCH 6/6] Write unit test more tersely --- tests/test_api.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tests/test_api.rs b/tests/test_api.rs index 6ea1541..0af6707 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -278,23 +278,7 @@ async fn can_list_metadata() { 1503074938.2232 ); assert_eq!( - entries[0] - .get("custom") - .unwrap() - .as_object() - .unwrap() - .get("orderly") - .unwrap() - .as_object() - .unwrap() - .get("artefacts") - .unwrap() - .as_array() - .unwrap()[3] - .get("description") - .unwrap() - .as_str() - .unwrap(), + entries[0]["custom"]["orderly"]["artefacts"][3]["description"], "Projected Coverage for routine immunisation in PINE countries" ); assert_eq!(