diff --git a/cli/src/activate.rs b/cli/src/activate.rs index ee0df7c..f10b565 100644 --- a/cli/src/activate.rs +++ b/cli/src/activate.rs @@ -1,8 +1,7 @@ use crate::Debug; use clap::{Args, Subcommand}; use color_eyre::Result; -use tonic::transport::Channel; -use zeebe_client::api::{gateway_client::GatewayClient, ActivateJobsRequest}; +use zeebe_client::{api::ActivateJobsRequest, ZeebeClient}; #[derive(Args)] pub(crate) struct ActivateArgs { @@ -41,7 +40,7 @@ impl From<&ActivateJobsArgs> for ActivateJobsRequest { } pub(crate) async fn handle_activate_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &ActivateArgs, ) -> Result> { match &args.resource_type { @@ -50,7 +49,7 @@ pub(crate) async fn handle_activate_command( } async fn handle_activate_jobs_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &ActivateJobsArgs, ) -> Result> { let request: ActivateJobsRequest = args.into(); diff --git a/cli/src/cancel_process_instance.rs b/cli/src/cancel_process_instance.rs index bb57ead..7d3e7b0 100644 --- a/cli/src/cancel_process_instance.rs +++ b/cli/src/cancel_process_instance.rs @@ -2,8 +2,8 @@ use color_eyre::eyre::Result; use std::fmt::Debug; use clap::Args; -use tonic::transport::Channel; -use zeebe_client::api::{gateway_client::GatewayClient, CancelProcessInstanceRequest}; + +use zeebe_client::{api::CancelProcessInstanceRequest, ZeebeClient}; #[derive(Args)] pub struct CancelProcessInstanceArgs { @@ -19,7 +19,7 @@ impl From<&CancelProcessInstanceArgs> for CancelProcessInstanceRequest { } pub async fn handle_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &CancelProcessInstanceArgs, ) -> Result> { let request: CancelProcessInstanceRequest = args.into(); diff --git a/cli/src/create.rs b/cli/src/create.rs index e407e20..e86945e 100644 --- a/cli/src/create.rs +++ b/cli/src/create.rs @@ -1,10 +1,10 @@ use crate::Debug; use clap::{Args, Subcommand}; use color_eyre::eyre::Result; -use tonic::transport::Channel; -use zeebe_client::api::{ - gateway_client::GatewayClient, CreateProcessInstanceRequest, - CreateProcessInstanceWithResultRequest, + +use zeebe_client::{ + api::{CreateProcessInstanceRequest, CreateProcessInstanceWithResultRequest}, + ZeebeClient, }; #[derive(Args, Clone, Debug)] @@ -31,7 +31,7 @@ struct CreateInstanceArgs { } pub(crate) async fn handle_create_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &CreateArgs, ) -> Result> { match &args.resource_type { @@ -52,7 +52,7 @@ impl From<&CreateInstanceArgs> for CreateProcessInstanceRequest { } async fn handle_create_instance_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &CreateInstanceArgs, ) -> Result> { let request: CreateProcessInstanceRequest = args.into(); diff --git a/cli/src/fail_job.rs b/cli/src/fail_job.rs index 59fec11..65148d7 100644 --- a/cli/src/fail_job.rs +++ b/cli/src/fail_job.rs @@ -2,8 +2,7 @@ use color_eyre::eyre::Result; use std::fmt::Debug; use clap::Args; -use tonic::transport::Channel; -use zeebe_client::api::{gateway_client::GatewayClient, FailJobRequest}; +use zeebe_client::{api::FailJobRequest, ZeebeClient}; #[derive(Args)] pub struct FailJobArgs { @@ -35,7 +34,7 @@ impl From<&FailJobArgs> for FailJobRequest { } pub async fn handle_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &FailJobArgs, ) -> Result> { let request: FailJobRequest = args.into(); diff --git a/cli/src/publish.rs b/cli/src/publish.rs index f9361d7..92bfe71 100644 --- a/cli/src/publish.rs +++ b/cli/src/publish.rs @@ -2,8 +2,8 @@ use color_eyre::eyre::Result; use std::fmt::Debug; use clap::{Args, Subcommand}; -use tonic::transport::Channel; -use zeebe_client::api::{gateway_client::GatewayClient, PublishMessageRequest}; + +use zeebe_client::{api::PublishMessageRequest, ZeebeClient}; #[derive(Args, Clone, Debug)] pub(crate) struct PublishArgs { @@ -42,7 +42,7 @@ impl From<&PublishMessageArgs> for PublishMessageRequest { } pub(crate) async fn handle_publish_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &PublishArgs, ) -> Result> { match &args.resource_type { @@ -51,7 +51,7 @@ pub(crate) async fn handle_publish_command( } async fn handle_publish_message_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &PublishMessageArgs, ) -> Result> { let request: PublishMessageRequest = args.into(); diff --git a/cli/src/retries.rs b/cli/src/retries.rs index 9542cbb..9b89a36 100644 --- a/cli/src/retries.rs +++ b/cli/src/retries.rs @@ -2,8 +2,8 @@ use crate::Debug; use clap::Args; use color_eyre::Result; -use tonic::transport::Channel; -use zeebe_client::api::{gateway_client::GatewayClient, UpdateJobRetriesRequest}; + +use zeebe_client::{api::UpdateJobRetriesRequest, ZeebeClient}; #[derive(Args)] pub(crate) struct UpdateRetriesArgs { @@ -26,7 +26,7 @@ impl TryFrom<&UpdateRetriesArgs> for UpdateJobRetriesRequest { } pub(crate) async fn handle_set_retries_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &UpdateRetriesArgs, ) -> Result> { let request: UpdateJobRetriesRequest = args.try_into()?; diff --git a/cli/src/throw_error.rs b/cli/src/throw_error.rs index 6c6611c..a359931 100644 --- a/cli/src/throw_error.rs +++ b/cli/src/throw_error.rs @@ -2,8 +2,8 @@ use color_eyre::eyre::Result; use std::fmt::Debug; use clap::Args; -use tonic::transport::Channel; -use zeebe_client::api::{gateway_client::GatewayClient, ThrowErrorRequest}; + +use zeebe_client::{api::ThrowErrorRequest, ZeebeClient}; #[derive(Args)] pub struct ThrowErrorArgs { @@ -29,7 +29,7 @@ impl From<&ThrowErrorArgs> for ThrowErrorRequest { } pub async fn handle_command( - client: &mut GatewayClient, + client: &mut ZeebeClient, args: &ThrowErrorArgs, ) -> Result> { let request: ThrowErrorRequest = args.into(); diff --git a/client/src/auth.rs b/client/src/auth.rs new file mode 100644 index 0000000..d308a0e --- /dev/null +++ b/client/src/auth.rs @@ -0,0 +1,9 @@ +use tonic::service::Interceptor; + +pub struct AuthInterceptor {} + +impl Interceptor for AuthInterceptor { + fn call(&mut self, request: tonic::Request<()>) -> Result, tonic::Status> { + Ok(request) + } +} diff --git a/client/src/lib.rs b/client/src/lib.rs index 9b25a94..8c5abec 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1,9 +1,10 @@ +mod auth; use std::str::FromStr; -use api::gateway_client::GatewayClient; +use auth::AuthInterceptor; use thiserror::Error; use tonic::{ - codegen::http::uri::InvalidUri, + codegen::{http::uri::InvalidUri, InterceptedService}, transport::{self, Channel, Uri}, }; @@ -33,7 +34,10 @@ pub enum ConnectionError { Uri(#[from] InvalidUri), } -pub async fn connect(conn: Connection) -> Result, ConnectionError> { +pub type ZeebeClient = + api::gateway_client::GatewayClient>; + +pub async fn connect(conn: Connection) -> Result { let uri = match conn { Connection::Address(addr) => Uri::from_str(&addr), Connection::HostPort(proto, host, port) => { @@ -41,5 +45,8 @@ pub async fn connect(conn: Connection) -> Result, Connect } }?; let channel = Channel::builder(uri); - Ok(GatewayClient::new(channel.connect().await?)) + Ok(api::gateway_client::GatewayClient::with_interceptor( + channel.connect().await?, + AuthInterceptor {}, + )) }