From 6246546333c77190f46117db68b37c9c89386bd5 Mon Sep 17 00:00:00 2001 From: Patrick Meade Date: Mon, 21 Oct 2024 20:10:10 -0500 Subject: [PATCH] Final clean up for merging --- .github/workflows/ci.yml | 8 +-- Cargo.lock | 95 +++++++++++++++++------------------ Cargo.toml | 2 +- README.md | 106 ++++++++++++++++++++++++++++----------- bin/run-app | 2 +- client/client.sh | 4 +- 6 files changed, 132 insertions(+), 85 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83c7b7e..21508ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,10 +18,12 @@ jobs: steps: - uses: actions/checkout@v4 - run: rustup update stable && rustup default stable - - run: cargo fmt --check - - run: cargo clippy --locked - - run: cargo install cargo-outdated - run: cargo outdated --root-deps-only --exit-code 1 + - run: cargo fmt --all -- --check + - run: cargo generate-lockfile --locked + - run: cargo check --locked + - run: cargo clippy --locked + - run: cargo verify-project --locked test: name: Test diff --git a/Cargo.lock b/Cargo.lock index 75c9f58..940e1fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,9 +105,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95" [[package]] name = "async-trait" @@ -117,7 +117,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -371,15 +371,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cc" -version = "1.1.30" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" dependencies = [ "shlex", ] @@ -489,7 +489,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -500,7 +500,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -540,7 +540,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.1", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -569,7 +569,7 @@ dependencies = [ "enum-ordinalize", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -596,7 +596,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -616,7 +616,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -756,7 +756,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -858,7 +858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39260b1324f4cf40bf4d86e4aa3a7574fabf6b25fe1b07345b776698d2a0459" dependencies = [ "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -888,7 +888,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "unindent", ] @@ -1154,7 +1154,7 @@ dependencies = [ "http 1.1.0", "hyper 1.5.0", "hyper-util", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -1341,7 +1341,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1419,9 +1419,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.159" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "linked-hash-map" @@ -1581,7 +1581,7 @@ checksum = "3a6dbc533e93429a71c44a14c04547ac783b56d3f22e6c4f12b1b994cf93844e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1668,9 +1668,9 @@ checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "openssl" -version = "0.10.67" +version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b8cefcf97f41316955f9294cd61f639bdcfa9f2f230faac6cb896aa8ab64704" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -1689,7 +1689,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1781,7 +1781,7 @@ checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -1831,9 +1831,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] @@ -2056,9 +2056,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.14" +version = "0.23.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" dependencies = [ "once_cell", "rustls-pki-types", @@ -2229,14 +2229,14 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "indexmap 2.6.0", "itoa", @@ -2294,7 +2294,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2394,7 +2394,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2513,9 +2513,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" dependencies = [ "proc-macro2", "quote", @@ -2600,7 +2600,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2713,7 +2713,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2742,7 +2742,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pki-types", "tokio", ] @@ -2809,7 +2809,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2865,7 +2865,7 @@ checksum = "560b82d656506509d43abe30e0ba64c56b1953ab3d4fe7ba5902747a7a3cedd5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] @@ -2876,12 +2876,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicase" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] +checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" [[package]] name = "unicode-bidi" @@ -2998,7 +2995,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-shared", ] @@ -3032,7 +3029,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3332,7 +3329,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.82", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index be81ee3..c3d90cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ gotham_restful = "0.9.0" log = "0.4.22" mongodb = "3.1.0" serde = "1.0.210" -serde_json = "1.0.128" +serde_json = "1.0.132" time = "0.3.36" tokio = { version = "1.40.0", features = [ "full" ] } uuid = { version = "1.11.0", features = [ "serde", "v4" ] } diff --git a/README.md b/README.md index faf09c3..f96e7d7 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,93 @@ # wipac-disk-tracking Archival media tracking service for WIPAC -## API -The REST API for the wipac-disk-tracking service is documented below. +## Routes +The following routes are supported in the wipac-disk-tracking service: -The API is rooted at: +### API / +These routes live at the root of the service. - /api/v1 +#### GET /health +This route allows a client to query the health of the service. Mostly, +this is just a check if the service can access the database that stores +the disk events. This route requires no authentication, and can be +checked with a simple `curl` command: -### Disks -Disks represent a collection of unique archival disks. While the disk -entity does carry some immutable identifying information, it is mostly -a container for archival disk events. + curl -v http://localhost:8080/health && echo "" -#### Routes -These routes are implemented to work with disks: +A healthy response is 200, along with some JSON indicating the status +of the service. Here `count` is a simple count of disk events stored +in the backing database: - GET /disks/:disk_id Get the data for a given disk - GET /disks/:disk_id/events Get all of the events for a given disk - GET /disks/:disk_id/events/:event_id Get the data for a given event for a given disk - GET /disks/:disk_id/search?query Find a disk based on a key-value query + { + "status": "ok", + "count": 0 + } -### Events -Events represent a record of an event involving an archival disk. -There are four distinct events that are tracked by the system. +An unhealthy response is 500, along with some JSON indicating the error +the service is experiencing connecting to the database: - sighted This disk was observed to be loaded in a host that processes archival disks - formatted This disk was given a file system to make it ready for archival purposes - opened This disk was given a label and was designated for active archival activity - closed This disk was determined to full/finished and archival activity stopped + { + "status": "error", + "message": "Failed to connect to the database: MongoError(\"Kind: Server selection timeout: No available servers. Topology: { Type: Single, Servers: [ { Address: localhost:27017, Type: Unknown, Error: Kind: I/O error: Connection refused (os error 111), labels: {} } ] }, labels: {}\")" + } -The format for each of these events is specified with a JSON Schema file. +#### GET /token +This route allows a client to query the service's view of its token +issued by Keycloak for authorization. This route exists for debugging +purposes. -#### Routes -These routes are implemented to work with events: +The client can also inspect its token in a service like [jwt.io](https://jwt.io). - POST /events/closed Create a new 'closed' event - POST /events/formatted Create a new 'formatted' event - POST /events/opened Create a new 'opened' event - POST /events/sighted Create a new 'sighted' event - GET /events/:event_id Get the data for a given event +This route offers a view of 'how did the service parse my token' or +'how does the service see my authorization grants'? + +### API /api/v1 +These routes live under /api/v1. + +#### GET /events/:event_id +Get the data for a given event. This route is actually multi-purpose. + +If you specify the UUID assigned to an event, you can find the record +for a specific event: + + GET /api/v1/events/0badfdd0-963a-4b25-9af6-1acc52c5d334 + +If you specify the serial number of a disk, you can find the records of +every event referencing that serial number: + + GET /api/v1/events/ZRS1NWBL + +In both cases, a successful query will return with the structure like +this one: + + { + "events": [ + { + smartctl-event-here + }, + ... + { + smartctl-event-here + } + ] + } + +#### POST /events/closed +Create a new 'closed' event. This disk was determined to full/finished +and archival activity stopped. + +#### POST /events/formatted +Create a new 'formatted' event. This disk was given a file system to +make it ready for archival purposes. + +#### POST /events/opened +Create a new 'opened' event. This disk was given a label and was +designated for active archival activity. + +#### POST /events/sighted +Create a new 'sighted' event. This disk was observed to be loaded in a +host that processes archival disks. ## Development As typical in a Rust project, you can run the unit and integration tests with: diff --git a/bin/run-app b/bin/run-app index 9722884..b601e94 100755 --- a/bin/run-app +++ b/bin/run-app @@ -11,7 +11,7 @@ export MONGODB_PASSWORD=${MONGODB_PASSWORD:="hunter2"} export MONGODB_PORT_NUMBER=${MONGODB_PORT_NUMBER:="27017"} export MONGODB_TIMEOUT_SECS=${MONGODB_TIMEOUT_SECS:="5"} export MONGODB_USERNAME=${MONGODB_USERNAME:="disk_tracking"} -export OAUTH_AUDIENCE=${OAUTH_AUDIENCE:="long-term-archive"} # TODO: CHANGE THIS TO disk-tracking !!! +export OAUTH_AUDIENCE=${OAUTH_AUDIENCE:="disk-tracking"} export OAUTH_REALM=${OAUTH_REALM:="IceCube"} export OAUTH_URL=${OAUTH_URL:="https://keycloak.icecube.wisc.edu/auth"} export PORT=${PORT:="8080"} diff --git a/client/client.sh b/client/client.sh index e157af7..58b3700 100755 --- a/client/client.sh +++ b/client/client.sh @@ -2,8 +2,8 @@ # run the testing client export BASE_URL=${HEALTH_URL:="http://localhost:8080"} -export CLIENT_ID=${CLIENT_ID:="long-term-archive"} # TODO: CHANGE THIS TO disk-tracking !!! -export CLIENT_SECRET=${CLIENT_SECRET:="$(