diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..333a6e6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: {} + merge_group: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-D warnings" + +jobs: + + rustfmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: hecrj/setup-rust-action@v2 + with: + components: rustfmt + - run: cargo fmt --all --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: hecrj/setup-rust-action@v2 + with: + components: clippy + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy --workspace --all-features --all-targets + + build_and_test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + toolchain: [stable, beta, nightly] + steps: + - uses: actions/checkout@v4 + - uses: hecrj/setup-rust-action@v2 + - uses: taiki-e/install-action@protoc + - uses: Swatinem/rust-cache@v2 + - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - run: cargo build --verbose + - run: cargo test --doc --all-features --verbose \ No newline at end of file diff --git a/envoy-proto-collect/src/main.rs b/envoy-proto-collect/src/main.rs index f242910..92beb76 100644 --- a/envoy-proto-collect/src/main.rs +++ b/envoy-proto-collect/src/main.rs @@ -2,7 +2,7 @@ use glob::glob; use std::{ fs::{self, File}, io::{self, Write}, - path::PathBuf, + path::{Path, PathBuf}, process, }; @@ -29,16 +29,15 @@ fn apache_v2(year: u32, owner: &str) -> String { } fn collect_protos( - out_dir: &PathBuf, + out_dir: &Path, repo: &str, glob_patterns: Vec<&str>, add_license: Option<&String>, ) { - let repo = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) - .join("submodules") - .join(repo); + let manifest_dir = std::env!("CARGO_MANIFEST_DIR"); + let repo_dir = Path::new(manifest_dir).join("submodules").join(repo); - if !repo.is_dir() { + if !repo_dir.is_dir() { eprintln!("Error: submodule repo {:?} not found.", repo); process::exit(1); } @@ -46,7 +45,7 @@ fn collect_protos( let mut source_protos: Vec = Vec::new(); for pattern in glob_patterns { - let mut matches: Vec = glob(repo.join(pattern).to_str().unwrap()) + let mut matches: Vec = glob(repo_dir.join(pattern).to_str().unwrap()) .unwrap() .filter_map(Result::ok) .collect(); @@ -59,7 +58,7 @@ fn collect_protos( let target_name = out_dir.join( proto - .strip_prefix(repo.parent().expect("repo has parent")) + .strip_prefix(repo_dir.parent().expect("repo has parent")) .expect("base is a prefix of proto"), ); @@ -84,7 +83,8 @@ fn collect_protos( } fn main() { - let out_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) + let manifest_dir = std::env!("CARGO_MANIFEST_DIR"); + let out_dir = Path::new(manifest_dir) .parent() .expect("envoy-proto-collect is inside a workspace") .join("envoy-types") diff --git a/envoy-types/src/ext_authz/mod.rs b/envoy-types/src/ext_authz/mod.rs index e02cd0d..2daef30 100644 --- a/envoy-types/src/ext_authz/mod.rs +++ b/envoy-types/src/ext_authz/mod.rs @@ -133,14 +133,17 @@ pub mod v3 { } fn with_status(status: tonic::Status) -> Self { - let mut check_response = CheckResponse::default(); - check_response.status = Some(rpc::Status { + let status = Some(rpc::Status { code: status.code().into(), message: status.message().into(), // `tonic::Status`'s details are not considered details: Vec::new(), }); - check_response + + CheckResponse { + status, + ..Default::default() + } } fn set_status(&mut self, status: tonic::Status) -> &mut Self { @@ -336,9 +339,9 @@ pub mod v3 { } } - impl Into for OkHttpResponseBuilder { - fn into(self) -> OkHttpResponse { - self.build() + impl From for OkHttpResponse { + fn from(val: OkHttpResponseBuilder) -> Self { + val.build() } } @@ -437,9 +440,9 @@ pub mod v3 { } } - impl Into for DeniedHttpResponseBuilder { - fn into(self) -> DeniedHttpResponse { - self.build() + impl From for DeniedHttpResponse { + fn from(val: DeniedHttpResponseBuilder) -> Self { + val.build() } } diff --git a/envoy-types/src/lib.rs b/envoy-types/src/lib.rs index da9cc6e..9243a92 100644 --- a/envoy-types/src/lib.rs +++ b/envoy-types/src/lib.rs @@ -96,6 +96,8 @@ using a [previous version of `envoy-types`]. #![warn(missing_debug_implementations, rust_2018_idioms)] #![allow(missing_docs, rustdoc::invalid_html_tags, rustdoc::bare_urls)] +#[rustfmt::skip] +#[allow(clippy::all)] mod generated; /// Compiled protobuf types diff --git a/examples/src/ext_authz/authorization_server_basic.rs b/examples/src/ext_authz/authorization_server_basic.rs index ae5a17e..8858fe2 100644 --- a/examples/src/ext_authz/authorization_server_basic.rs +++ b/examples/src/ext_authz/authorization_server_basic.rs @@ -1,3 +1,4 @@ +use std::env; use tonic::{transport::Server, Request, Response, Status}; use envoy_types::ext_authz::v3::pb::{ @@ -34,8 +35,9 @@ impl Authorization for MyServer { #[tokio::main] async fn main() -> Result<(), Box> { - let addr = format!("0.0.0.0:50051").parse().unwrap(); - let server = MyServer::default(); + let server_port = env::var("SERVER_PORT").unwrap_or("50051".into()); + let addr = format!("0.0.0.0:{server_port}").parse().unwrap(); + let server = MyServer; println!("AuthorizationServer listening on {addr}"); diff --git a/examples/src/ext_authz/authorization_server_full.rs b/examples/src/ext_authz/authorization_server_full.rs index a3d0e7f..362ae73 100644 --- a/examples/src/ext_authz/authorization_server_full.rs +++ b/examples/src/ext_authz/authorization_server_full.rs @@ -90,7 +90,7 @@ impl Authorization for MyServer { async fn main() -> Result<(), Box> { let server_port = env::var("SERVER_PORT").unwrap_or("50051".into()); let addr = format!("0.0.0.0:{server_port}").parse().unwrap(); - let server = MyServer::default(); + let server = MyServer; println!("AuthorizationServer listening on {}", addr); diff --git a/examples/src/ext_authz/authorization_server_pb_only.rs b/examples/src/ext_authz/authorization_server_pb_only.rs index f990a1f..3a200f9 100644 --- a/examples/src/ext_authz/authorization_server_pb_only.rs +++ b/examples/src/ext_authz/authorization_server_pb_only.rs @@ -147,7 +147,7 @@ impl Authorization for MyServer { async fn main() -> Result<(), Box> { let server_port = env::var("SERVER_PORT").unwrap_or("50051".into()); let addr = format!("0.0.0.0:{server_port}").parse().unwrap(); - let server = MyServer::default(); + let server = MyServer; println!("AuthorizationServer listening on {}", addr);