From 39dbda26f917c9296cb9a407af99fb1263ef1240 Mon Sep 17 00:00:00 2001 From: jlanson Date: Mon, 12 Aug 2024 10:26:09 -0400 Subject: [PATCH] feat: add proto-file based code gen --- Cargo.lock | 587 +++++++++++++++++++++++++++++++++ Containerfile | 2 +- hipcheck/Cargo.toml | 4 + hipcheck/build.rs | 7 +- hipcheck/proto/hipcheck.proto | 145 ++++++++ hipcheck/src/.gitignore | 1 + hipcheck/src/main.rs | 5 + site/content/install/_index.md | 1 + 8 files changed, 749 insertions(+), 3 deletions(-) create mode 100644 hipcheck/proto/hipcheck.proto create mode 100644 hipcheck/src/.gitignore diff --git a/Cargo.lock b/Cargo.lock index 58442c7b..48773db8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -127,12 +136,113 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "async-trait" +version = "0.1.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper 1.0.1", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", +] + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.21.7" @@ -755,6 +865,45 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -778,6 +927,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + [[package]] name = "git2" version = "0.19.0" @@ -857,6 +1012,25 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "h2" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap 2.2.6", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -890,6 +1064,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "hipcheck" version = "3.5.0" @@ -926,6 +1106,7 @@ dependencies = [ "paste", "pathbuf", "petgraph", + "prost", "rayon", "regex", "rustls", @@ -943,6 +1124,8 @@ dependencies = [ "tempfile", "term_size", "toml", + "tonic", + "tonic-build", "unicode-normalization", "ureq", "url", @@ -991,12 +1174,101 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-timeout" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" +dependencies = [ + "hyper", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -1104,6 +1376,15 @@ dependencies = [ "nom", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -1273,12 +1554,24 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1294,6 +1587,24 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "multimap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" + [[package]] name = "nom" version = "7.1.3" @@ -1395,6 +1706,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" +[[package]] +name = "object" +version = "0.36.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -1581,12 +1901,38 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "pin-project-lite" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.30" @@ -1611,6 +1957,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn 2.0.72", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1644,6 +2000,59 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb182580f71dd070f88d01ce3de9f4da5021db7115d2e1c3605a754153b77c1" +dependencies = [ + "bytes", + "heck 0.5.0", + "itertools", + "log", + "multimap", + "once_cell", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 2.0.72", + "tempfile", +] + +[[package]] +name = "prost-derive" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18bec9b0adc4eba778b33684b7ba3e7137789434769ee3ce3930463ef904cfca" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "prost-types" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cee5168b05f49d4b0ca581206eb14a7b22fafd963efe729ac48eb03266e25cc2" +dependencies = [ + "prost", +] + [[package]] name = "quote" version = "1.0.36" @@ -1787,6 +2196,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -2066,6 +2481,15 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -2083,6 +2507,16 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "spdx" version = "0.10.6" @@ -2202,6 +2636,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "tabled" version = "0.15.0" @@ -2326,6 +2772,57 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tokio" +version = "1.39.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml" version = "0.8.19" @@ -2360,6 +2857,81 @@ dependencies = [ "winnow", ] +[[package]] +name = "tonic" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38659f4a91aba8598d27821589f5db7dddd94601e7a01b1e485a50e5484c7401" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.22.1", + "bytes", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-timeout", + "hyper-util", + "percent-encoding", + "pin-project", + "prost", + "socket2", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-build" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "568392c5a2bd0020723e3f387891176aabafe36fd9fcd074ad309dfa0c8eb964" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "indexmap 1.9.3", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.40" @@ -2391,6 +2963,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.17.0" @@ -2516,6 +3094,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Containerfile b/Containerfile index eb2a11c1..5a76828c 100644 --- a/Containerfile +++ b/Containerfile @@ -29,7 +29,7 @@ COPY scripts/ scripts/ RUN set -eux && \ apt-get update && \ - apt-get install -y npm git && \ + apt-get install -y npm git protobuf-compiler && \ apt-get clean && \ npm install -g module-deps@6.2 --no-audit --no-fund && \ adduser --disabled-password hc_user && \ diff --git a/hipcheck/Cargo.toml b/hipcheck/Cargo.toml index 202543d7..a507277f 100644 --- a/hipcheck/Cargo.toml +++ b/hipcheck/Cargo.toml @@ -86,6 +86,9 @@ http = "1.1.0" dialoguer = "0.11.0" tabled = "0.15.0" fs_extra = "1.3.0" +tonic = "0.12.1" +prost = "0.13.1" +tonic-build = { version = "0.12.1", features = ["prost"] } # Exactly matching the version of rustls used by ureq # Get rid of default features since we don't use the AWS backed crypto provider (we use ring). @@ -102,6 +105,7 @@ features = [ [build-dependencies] anyhow = "1.0.86" +tonic-build = "0.12.1" which = { version = "6.0.1", default-features = false } [dev-dependencies] diff --git a/hipcheck/build.rs b/hipcheck/build.rs index 44391b7d..a140c7c1 100644 --- a/hipcheck/build.rs +++ b/hipcheck/build.rs @@ -11,11 +11,14 @@ use std::path::Path; use std::process::Command; use which::which; -fn main() { +fn main() -> Result<()> { let repo_dir = env!("CARGO_MANIFEST_DIR", "can't find Cargo manifest directory"); let head = get_head_commit(repo_dir).unwrap_or_default(); - println!("cargo:rustc-env=HC_HEAD_COMMIT={}", head) + tonic_build::compile_protos("proto/hipcheck.proto")?; + + println!("cargo:rustc-env=HC_HEAD_COMMIT={}", head); + Ok(()) } fn get_head_commit>(path: P) -> Result { diff --git a/hipcheck/proto/hipcheck.proto b/hipcheck/proto/hipcheck.proto new file mode 100644 index 00000000..724514e2 --- /dev/null +++ b/hipcheck/proto/hipcheck.proto @@ -0,0 +1,145 @@ +syntax = "proto3"; + +package hipcheck; + +service Plugin { + /** + * Get schemas for all supported queries by the plugin. + * + * This is used by Hipcheck to validate that: + * + * - The plugin supports a default query taking a `target` type if used + * as a top-level plugin in the user's policy file. + * - That requests sent to the plugin and data returned by the plugin + * match the schema during execution. + */ + rpc GetQuerySchemas (Empty) returns (stream Schema); + + /** + * Hipcheck sends all child nodes for the plugin from the user's policy + * file to configure the plugin. + */ + rpc SetConfiguration (Configuration) returns (ConfigurationResult); + + /** + * Get the default policy for a plugin, which may additionally depend on + * the plugin's configuration. + */ + rpc GetDefaultPolicyExpression (Empty) returns (PolicyExpression); + + /** + * Open a bidirectional streaming RPC to enable a request/response + * protocol between Hipcheck and a plugin, where Hipcheck can issue + * queries to the plugin, and the plugin may issue queries to _other_ + * plugins through Hipcheck. + * + * Queries are cached by the publisher name, plugin name, query name, + * and key, and if a match is found for those four values, then + * Hipcheck will respond with the cached result of that prior matching + * query rather than running the query again. + */ + rpc InitiateQueryProtocol (stream Query) returns (stream Query); +} + +message Configuration { + // JSON string containing configuration data expected by the plugin, + // pulled from the user's policy file. + string configuration = 1; +} + +enum ConfigurationStatus { + // An unknown error occured. + ERROR_UNKNOWN = 0; + // No error; the operation was successful. + ERROR_NONE = 1; + // The user failed to provide a required configuration item. + ERROR_MISSING_REQUIRED_CONFIGURATION = 2; + // The user provided a configuration item whose name was not recognized. + ERROR_UNRECOGNIZED_CONFIGURATION = 3; + // The user provided a configuration item whose value is invalid. + ERROR_INVALID_CONFIGURATION_VALUE = 4; +} + +message ConfigurationResult { + // The status of the configuration call. + ConfigurationStatus status = 1; + // An optional error message, if there was an error. + string message = 2; +} + +message PolicyExpression { + // A policy expression, if the plugin has a default policy. + // This MUST be filled in with any default values pulled from the plugin's + // configuration. Hipcheck will only request the default policy _after_ + // configuring the plugin. + string policy_expression = 1; +} + +message Schema { + // The name of the query being described by the schemas provided. + // + // If either the key and/or output schemas result in a message which is + // too big, they may be chunked across multiple replies in the stream. + // Replies with matching query names should have their fields concatenated + // in the order received to reconstruct the chunks. + string query_name = 1; + + // The key schema, in JSON Schema format. + string key_schema = 2; + + // The output schema, in JSON Schema format. + string output_schema = 3; +} + +enum QueryState { + // Something has gone wrong. + QUERY_UNSPECIFIED = 0; + + // We are submitting a new query. + QUERY_SUBMIT = 1; + + // We are replying to a query and expect more chunks. + QUERY_REPLY_IN_PROGRESS = 2; + + // We are closing a reply to a query. If a query response is in one chunk, + // just send this. If a query is in more than one chunk, send this with + // the last message in the reply. This tells the receiver that all chunks + // have been received. + QUERY_REPLY_COMPLETE = 3; +} + +message Query { + // The ID of the request, used to associate requests and replies. + // Odd numbers = initiated by `hc`. + // Even numbers = initiated by a plugin. + int32 id = 1; + + // The state of the query, indicating if this is a request or a reply, + // and if it's a reply whether it's the end of the reply. + QueryState state = 2; + + // Publisher name and plugin name, when sent from Hipcheck to a plugin + // to initiate a fresh query, are used by the receiving plugin to validate + // that the query was intended for them. + // + // When a plugin is making a query to another plugin through Hipcheck, it's + // used to indicate the destination plugin, and to indicate the plugin that + // is replying when Hipcheck sends back the reply. + string publisher_name = 3; + string plugin_name = 4; + + // The name of the query being made, so the responding plugin knows what + // to do with the provided data. + string query_name = 5; + + // The key for the query, as a JSON object. This is the data that Hipcheck's + // incremental computation system will use to cache the response. + string key = 6; + + // The response for the query, as a JSON object. This will be cached by + // Hipcheck for future queries matching the publisher name, plugin name, + // query name, and key. + string output = 7; +} + +message Empty {} diff --git a/hipcheck/src/.gitignore b/hipcheck/src/.gitignore new file mode 100644 index 00000000..3bb866e8 --- /dev/null +++ b/hipcheck/src/.gitignore @@ -0,0 +1 @@ +hipcheck.rs diff --git a/hipcheck/src/main.rs b/hipcheck/src/main.rs index 13f3b070..53b22988 100644 --- a/hipcheck/src/main.rs +++ b/hipcheck/src/main.rs @@ -15,6 +15,7 @@ mod git2_log_shim; mod git2_rustls_transport; mod log_bridge; mod metric; +mod plugin; mod report; mod session; mod setup; @@ -24,6 +25,10 @@ mod target; mod util; mod version; +pub mod hipcheck { + include!(concat!(env!("OUT_DIR"), "/hipcheck.rs")); +} + use crate::analysis::report_builder::build_report; use crate::analysis::report_builder::AnyReport; use crate::analysis::report_builder::Format; diff --git a/site/content/install/_index.md b/site/content/install/_index.md index 64082def..f4535b78 100644 --- a/site/content/install/_index.md +++ b/site/content/install/_index.md @@ -100,6 +100,7 @@ will need to build Hipcheck from source. To build Hipcheck from source, you'll need: - A Rust toolchain: see the [official Rust installation instructions](https://www.rust-lang.org/tools/install) +- The `protoc` compiler: see the [installation instructions](https://grpc.io/docs/protoc-installation/) If you _only_ want to build from source without configuring the build in any way, you can use `cargo install` to install Hipcheck into a Cargo0-specific