From d89f9b0d9b49eb9c2017f2f937eb9a181c94f307 Mon Sep 17 00:00:00 2001 From: Patrick Casey Date: Tue, 17 Dec 2024 11:51:03 -0500 Subject: [PATCH] chore: deleted deprecated proto top-level folder - Migrated hipcheck-common/proto to the top-level proto folder - Enabled running "buf lint" in CI Signed-off-by: Patrick Casey --- .buf.yaml | 3 + hipcheck-common/build.rs | 2 +- .../hipcheck/v1/hipcheck.proto | 0 .../default_policy_expr_request.proto | 12 ---- .../default_policy_expr_response.proto | 15 ----- proto/hipcheck/v1/messages/empty.proto | 7 -- .../explain_default_query_request.proto | 8 --- .../explain_default_query_response.proto | 12 ---- proto/hipcheck/v1/messages/query.proto | 46 ------------- .../hipcheck/v1/messages/query_request.proto | 8 --- .../hipcheck/v1/messages/query_response.proto | 8 --- .../v1/messages/query_schemas_request.proto | 8 --- .../v1/messages/query_schemas_response.proto | 18 ----- proto/hipcheck/v1/messages/query_state.proto | 19 ------ .../v1/messages/set_config_request.proto | 8 --- .../v1/messages/set_config_response.proto | 9 --- proto/hipcheck/v1/plugin_service.proto | 67 ------------------- xtask/src/task/buf.rs | 14 ++-- xtask/src/task/ci.rs | 18 ++++- xtask/src/task/mod.rs | 2 +- 20 files changed, 26 insertions(+), 258 deletions(-) rename {hipcheck-common/proto => proto}/hipcheck/v1/hipcheck.proto (100%) delete mode 100644 proto/hipcheck/v1/messages/default_policy_expr_request.proto delete mode 100644 proto/hipcheck/v1/messages/default_policy_expr_response.proto delete mode 100644 proto/hipcheck/v1/messages/empty.proto delete mode 100644 proto/hipcheck/v1/messages/explain_default_query_request.proto delete mode 100644 proto/hipcheck/v1/messages/explain_default_query_response.proto delete mode 100644 proto/hipcheck/v1/messages/query.proto delete mode 100644 proto/hipcheck/v1/messages/query_request.proto delete mode 100644 proto/hipcheck/v1/messages/query_response.proto delete mode 100644 proto/hipcheck/v1/messages/query_schemas_request.proto delete mode 100644 proto/hipcheck/v1/messages/query_schemas_response.proto delete mode 100644 proto/hipcheck/v1/messages/query_state.proto delete mode 100644 proto/hipcheck/v1/messages/set_config_request.proto delete mode 100644 proto/hipcheck/v1/messages/set_config_response.proto delete mode 100644 proto/hipcheck/v1/plugin_service.proto diff --git a/.buf.yaml b/.buf.yaml index bae2c1ff..7fecffe3 100644 --- a/.buf.yaml +++ b/.buf.yaml @@ -1,4 +1,7 @@ version: v2 +# tell buf to look in proto for .proto files +modules: + - path: proto lint: use: - STANDARD diff --git a/hipcheck-common/build.rs b/hipcheck-common/build.rs index 38e64f3f..156531d4 100644 --- a/hipcheck-common/build.rs +++ b/hipcheck-common/build.rs @@ -7,7 +7,7 @@ use tonic_build::compile_protos; fn main() -> Result<()> { // Compile the Hipcheck gRPC protocol spec to an .rs file let root = env!("CARGO_MANIFEST_DIR"); - let path = pathbuf![root, "proto", "hipcheck", "v1", "hipcheck.proto"]; + let path = pathbuf![root, "..", "proto", "hipcheck", "v1", "hipcheck.proto"]; compile_protos(path)?; // Make the target available as a compile-time env var for plugin arch diff --git a/hipcheck-common/proto/hipcheck/v1/hipcheck.proto b/proto/hipcheck/v1/hipcheck.proto similarity index 100% rename from hipcheck-common/proto/hipcheck/v1/hipcheck.proto rename to proto/hipcheck/v1/hipcheck.proto diff --git a/proto/hipcheck/v1/messages/default_policy_expr_request.proto b/proto/hipcheck/v1/messages/default_policy_expr_request.proto deleted file mode 100644 index 6acc1a83..00000000 --- a/proto/hipcheck/v1/messages/default_policy_expr_request.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "empty.proto"; - -/** - * Getting the default policy expression has no params, so we just wrap - * the empty message for maximal forward compatibility. - */ -message DefaultPolicyExprRequest { - Empty empty = 1; -} diff --git a/proto/hipcheck/v1/messages/default_policy_expr_response.proto b/proto/hipcheck/v1/messages/default_policy_expr_response.proto deleted file mode 100644 index ef00ab36..00000000 --- a/proto/hipcheck/v1/messages/default_policy_expr_response.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -/** - * The response from the DefaultPolicyExpr RPC call. - */ -message DefaultPolicyExprResponse { - /** - * 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; -} diff --git a/proto/hipcheck/v1/messages/empty.proto b/proto/hipcheck/v1/messages/empty.proto deleted file mode 100644 index cc468416..00000000 --- a/proto/hipcheck/v1/messages/empty.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -/** - * An empty message. - */ -message Empty {} diff --git a/proto/hipcheck/v1/messages/explain_default_query_request.proto b/proto/hipcheck/v1/messages/explain_default_query_request.proto deleted file mode 100644 index 0a02c862..00000000 --- a/proto/hipcheck/v1/messages/explain_default_query_request.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "empty.proto"; - -message ExplainDefaultQueryRequest { - Empty empty = 1; -} diff --git a/proto/hipcheck/v1/messages/explain_default_query_response.proto b/proto/hipcheck/v1/messages/explain_default_query_response.proto deleted file mode 100644 index 03ad17bf..00000000 --- a/proto/hipcheck/v1/messages/explain_default_query_response.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -/** - * The response from the ExplainDefaultQuery RPC call. - */ -message ExplainDefaultQueryResponse { - /** - * An unstructured description of the default query. - */ - string explanation = 1; -} diff --git a/proto/hipcheck/v1/messages/query.proto b/proto/hipcheck/v1/messages/query.proto deleted file mode 100644 index 41161b0e..00000000 --- a/proto/hipcheck/v1/messages/query.proto +++ /dev/null @@ -1,46 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "query_state.proto"; - -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; - - // Any "concerns" reported by a query. Concerns are *not* provided to - // other plugins calling a query, and are _only_ used by Hipcheck itself - // to provide the end-user with additional information about issues found - // during analysis. - // - // Concern chunking is the same as other fields. - repeated string concern = 8; -} diff --git a/proto/hipcheck/v1/messages/query_request.proto b/proto/hipcheck/v1/messages/query_request.proto deleted file mode 100644 index 7c8af882..00000000 --- a/proto/hipcheck/v1/messages/query_request.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "query.proto"; - -message QueryRequest { - Query query = 1; -} diff --git a/proto/hipcheck/v1/messages/query_response.proto b/proto/hipcheck/v1/messages/query_response.proto deleted file mode 100644 index 1fa86bac..00000000 --- a/proto/hipcheck/v1/messages/query_response.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "query.proto"; - -message QueryResponse { - Query query = 1; -} diff --git a/proto/hipcheck/v1/messages/query_schemas_request.proto b/proto/hipcheck/v1/messages/query_schemas_request.proto deleted file mode 100644 index d04c2cef..00000000 --- a/proto/hipcheck/v1/messages/query_schemas_request.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "empty.proto"; - -message QuerySchemasRequest { - Empty empty = 1; -} diff --git a/proto/hipcheck/v1/messages/query_schemas_response.proto b/proto/hipcheck/v1/messages/query_schemas_response.proto deleted file mode 100644 index 58e70217..00000000 --- a/proto/hipcheck/v1/messages/query_schemas_response.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -message QuerySchemasResponse { - // 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; -} diff --git a/proto/hipcheck/v1/messages/query_state.proto b/proto/hipcheck/v1/messages/query_state.proto deleted file mode 100644 index 1a093605..00000000 --- a/proto/hipcheck/v1/messages/query_state.proto +++ /dev/null @@ -1,19 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -enum QueryState { - // Something has gone wrong. - QUERY_STATE_UNSPECIFIED = 0; - - // We are submitting a new query. - QUERY_STATE_SUBMIT = 1; - - // We are replying to a query and expect more chunks. - QUERY_STATE_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_STATE_REPLY_COMPLETE = 3; -} diff --git a/proto/hipcheck/v1/messages/set_config_request.proto b/proto/hipcheck/v1/messages/set_config_request.proto deleted file mode 100644 index 430ab075..00000000 --- a/proto/hipcheck/v1/messages/set_config_request.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -message SetConfigRequest { - // JSON string containing configuration data expected by the plugin, - // pulled from the user's policy file. - string configuration = 1; -} diff --git a/proto/hipcheck/v1/messages/set_config_response.proto b/proto/hipcheck/v1/messages/set_config_response.proto deleted file mode 100644 index f4c0951a..00000000 --- a/proto/hipcheck/v1/messages/set_config_response.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "empty.proto"; - -message SetConfigResponse { - // No actual data returned. Errors handled with normal gRPC error system. - Empty empty = 1; -} diff --git a/proto/hipcheck/v1/plugin_service.proto b/proto/hipcheck/v1/plugin_service.proto deleted file mode 100644 index 201189c3..00000000 --- a/proto/hipcheck/v1/plugin_service.proto +++ /dev/null @@ -1,67 +0,0 @@ -syntax = "proto3"; -package hipcheck.v1; - -import "messages/query_schemas_request.proto"; -import "messages/query_schemas_response.proto"; -import "messages/set_config_request.proto"; -import "messages/set_config_response.proto"; -import "messages/default_policy_expr_request.proto"; -import "messages/default_policy_expr_response.proto"; -import "messages/explain_default_query_request.proto"; -import "messages/explain_default_query_response.proto"; -import "messages/query_request.proto"; -import "messages/query_response.proto"; - -/** - * Defines a Hipcheck plugin, able to interact with Hipcheck to provide - * support for additional analyses and sources of data. - */ -service PluginService { - /** - * 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 QuerySchemas (QuerySchemasRequest) returns (stream QuerySchemasResponse); - - /** - * Hipcheck sends all child nodes for the plugin from the user's policy - * file to configure the plugin. - */ - rpc SetConfig (SetConfigRequest) returns (SetConfigResponse); - - /** - * Get the default policy for a plugin, which may additionally depend on - * the plugin's configuration. - */ - rpc DefaultPolicyExpr (DefaultPolicyExprRequest) returns (DefaultPolicyExprResponse); - - /** - * Get an explanation of what the default query returns, to use when - * reporting analysis results to users. - * - * Note that, because users can specify their own policy expression, this - * explanation *should not* assume the user has used the default policy - * expression, if one is provided by the plugin. - */ - rpc ExplainDefaultQuery (ExplainDefaultQueryRequest) - returns (ExplainDefaultQueryResponse); - - /** - * 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 Query (stream QueryRequest) returns (stream QueryResponse); -} diff --git a/xtask/src/task/buf.rs b/xtask/src/task/buf.rs index 5fa7b573..692922d7 100644 --- a/xtask/src/task/buf.rs +++ b/xtask/src/task/buf.rs @@ -1,21 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::workspace; use anyhow::{Context, Result}; -use pathbuf::pathbuf; use which::which; -use xshell::{cmd, Shell}; +use xshell::Shell; + +use super::ci::run_buf_lint; /// Run the `buf lint` command pub fn run() -> Result<()> { let sh = Shell::new().context("could not init shell")?; which("buf").context("could not find 'buf'")?; - - let root = workspace::root()?; - let config = pathbuf![&root, ".buf.yaml"]; - let target = pathbuf![&root, "hipcheck", "proto"]; - - cmd!(sh, "buf lint --config {config} {target}").run()?; - + run_buf_lint(&sh)?; Ok(()) } diff --git a/xtask/src/task/ci.rs b/xtask/src/task/ci.rs index 5beb54f8..416ce748 100644 --- a/xtask/src/task/ci.rs +++ b/xtask/src/task/ci.rs @@ -25,6 +25,7 @@ pub fn run() -> Result<()> { task!(check_target_matches_ci), task!(print_versions), task!(run_fmt), + task!(run_buf_lint), task!(run_check), task!(run_build), task!(run_test), @@ -123,7 +124,7 @@ fn print_versions(sh: &Shell) -> Result<()> { print_fmt_version(sh)?; print_clippy_version(sh)?; print_xtask_version(sh)?; - + print_buf_version(sh)?; Ok(()) } @@ -169,6 +170,13 @@ fn print_xtask_version(sh: &Shell) -> Result<()> { .map_err(reason("call to cargo xtask failed. Make sure rust is installed and path to home-dir-here/.cargo/bin is on your path.")) } +// Print the version of `buf` +fn print_buf_version(sh: &Shell) -> Result<()> { + cmd!(sh, "buf --version").run().map(drop).map_err(reason( + "call to buf failed. Make sure buf is installed and on your path.", + )) +} + /// Run `cargo fmt`. fn run_fmt(sh: &Shell) -> Result<()> { cmd!(sh, "cargo fmt --all -- --color=always --check") @@ -228,6 +236,14 @@ fn run_xtask_check(sh: &Shell) -> Result<()> { .map_err(reason("call to cargo xtask failed")) } +/// Run `buf lint` +pub fn run_buf_lint(sh: &Shell) -> Result<()> { + cmd!(sh, "buf lint --config .buf.yaml") + .run() + .map(drop) + .map_err(reason("call to cargo xtask failed")) +} + /// Tell the user we're done. fn done(_sh: &Shell) -> Result<()> { log::info!( diff --git a/xtask/src/task/mod.rs b/xtask/src/task/mod.rs index f944fc57..67b77ddb 100644 --- a/xtask/src/task/mod.rs +++ b/xtask/src/task/mod.rs @@ -6,6 +6,6 @@ pub mod buf; pub mod changelog; pub mod check; pub mod ci; +pub mod manifest; pub mod rfd; pub mod site; -pub mod manifest;