Skip to content

Commit

Permalink
feat: add empty auth interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaschoenburg committed Aug 10, 2022
1 parent a0cc4b5 commit ce96eff
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 30 deletions.
7 changes: 3 additions & 4 deletions cli/src/activate.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -41,7 +40,7 @@ impl From<&ActivateJobsArgs> for ActivateJobsRequest {
}

pub(crate) async fn handle_activate_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &ActivateArgs,
) -> Result<Box<dyn Debug>> {
match &args.resource_type {
Expand All @@ -50,7 +49,7 @@ pub(crate) async fn handle_activate_command(
}

async fn handle_activate_jobs_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &ActivateJobsArgs,
) -> Result<Box<dyn Debug>> {
let request: ActivateJobsRequest = args.into();
Expand Down
6 changes: 3 additions & 3 deletions cli/src/cancel_process_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,7 +19,7 @@ impl From<&CancelProcessInstanceArgs> for CancelProcessInstanceRequest {
}

pub async fn handle_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &CancelProcessInstanceArgs,
) -> Result<Box<dyn Debug>> {
let request: CancelProcessInstanceRequest = args.into();
Expand Down
12 changes: 6 additions & 6 deletions cli/src/create.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -31,7 +31,7 @@ struct CreateInstanceArgs {
}

pub(crate) async fn handle_create_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &CreateArgs,
) -> Result<Box<dyn Debug>> {
match &args.resource_type {
Expand All @@ -52,7 +52,7 @@ impl From<&CreateInstanceArgs> for CreateProcessInstanceRequest {
}

async fn handle_create_instance_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &CreateInstanceArgs,
) -> Result<Box<dyn Debug>> {
let request: CreateProcessInstanceRequest = args.into();
Expand Down
5 changes: 2 additions & 3 deletions cli/src/fail_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -35,7 +34,7 @@ impl From<&FailJobArgs> for FailJobRequest {
}

pub async fn handle_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &FailJobArgs,
) -> Result<Box<dyn Debug>> {
let request: FailJobRequest = args.into();
Expand Down
8 changes: 4 additions & 4 deletions cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -42,7 +42,7 @@ impl From<&PublishMessageArgs> for PublishMessageRequest {
}

pub(crate) async fn handle_publish_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &PublishArgs,
) -> Result<Box<dyn Debug>> {
match &args.resource_type {
Expand All @@ -51,7 +51,7 @@ pub(crate) async fn handle_publish_command(
}

async fn handle_publish_message_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &PublishMessageArgs,
) -> Result<Box<dyn Debug>> {
let request: PublishMessageRequest = args.into();
Expand Down
6 changes: 3 additions & 3 deletions cli/src/retries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,7 +26,7 @@ impl TryFrom<&UpdateRetriesArgs> for UpdateJobRetriesRequest {
}

pub(crate) async fn handle_set_retries_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &UpdateRetriesArgs,
) -> Result<Box<dyn Debug>> {
let request: UpdateJobRetriesRequest = args.try_into()?;
Expand Down
6 changes: 3 additions & 3 deletions cli/src/throw_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -29,7 +29,7 @@ impl From<&ThrowErrorArgs> for ThrowErrorRequest {
}

pub async fn handle_command(
client: &mut GatewayClient<Channel>,
client: &mut ZeebeClient,
args: &ThrowErrorArgs,
) -> Result<Box<dyn Debug>> {
let request: ThrowErrorRequest = args.into();
Expand Down
9 changes: 9 additions & 0 deletions client/src/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use tonic::service::Interceptor;

pub struct AuthInterceptor {}

impl Interceptor for AuthInterceptor {
fn call(&mut self, request: tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status> {
Ok(request)
}
}
15 changes: 11 additions & 4 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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},
};

Expand Down Expand Up @@ -33,13 +34,19 @@ pub enum ConnectionError {
Uri(#[from] InvalidUri),
}

pub async fn connect(conn: Connection) -> Result<GatewayClient<Channel>, ConnectionError> {
pub type ZeebeClient =
api::gateway_client::GatewayClient<InterceptedService<Channel, AuthInterceptor>>;

pub async fn connect(conn: Connection) -> Result<ZeebeClient, ConnectionError> {
let uri = match conn {
Connection::Address(addr) => Uri::from_str(&addr),
Connection::HostPort(proto, host, port) => {
Uri::from_str(&format!("{:?}://{}:{}", proto, host, port))
}
}?;
let channel = Channel::builder(uri);
Ok(GatewayClient::new(channel.connect().await?))
Ok(api::gateway_client::GatewayClient::with_interceptor(
channel.connect().await?,
AuthInterceptor {},
))
}

0 comments on commit ce96eff

Please sign in to comment.