-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into shishqa/semaphore
- Loading branch information
Showing
9 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[derive(serde::Serialize, serde::Deserialize)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct LoginRequest { | ||
#[prost(message, optional, tag = "1")] | ||
pub operation_params: ::core::option::Option<super::operations::OperationParams>, | ||
#[prost(string, tag = "2")] | ||
pub user: ::prost::alloc::string::String, | ||
#[prost(string, tag = "3")] | ||
pub password: ::prost::alloc::string::String, | ||
} | ||
#[derive(serde::Serialize, serde::Deserialize)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct LoginResponse { | ||
/// After successfull completion must contain LoginResult. | ||
#[prost(message, optional, tag = "1")] | ||
pub operation: ::core::option::Option<super::operations::Operation>, | ||
} | ||
#[derive(serde::Serialize, serde::Deserialize)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct LoginResult { | ||
#[prost(string, tag = "1")] | ||
pub token: ::prost::alloc::string::String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/// Generated client implementations. | ||
pub mod auth_service_client { | ||
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] | ||
use tonic::codegen::*; | ||
use tonic::codegen::http::Uri; | ||
#[derive(Debug, Clone)] | ||
pub struct AuthServiceClient<T> { | ||
inner: tonic::client::Grpc<T>, | ||
} | ||
impl AuthServiceClient<tonic::transport::Channel> { | ||
/// Attempt to create a new client by connecting to a given endpoint. | ||
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error> | ||
where | ||
D: std::convert::TryInto<tonic::transport::Endpoint>, | ||
D::Error: Into<StdError>, | ||
{ | ||
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; | ||
Ok(Self::new(conn)) | ||
} | ||
} | ||
impl<T> AuthServiceClient<T> | ||
where | ||
T: tonic::client::GrpcService<tonic::body::BoxBody>, | ||
T::Error: Into<StdError>, | ||
T::ResponseBody: Body<Data = Bytes> + Send + 'static, | ||
<T::ResponseBody as Body>::Error: Into<StdError> + Send, | ||
{ | ||
pub fn new(inner: T) -> Self { | ||
let inner = tonic::client::Grpc::new(inner); | ||
Self { inner } | ||
} | ||
pub fn with_origin(inner: T, origin: Uri) -> Self { | ||
let inner = tonic::client::Grpc::with_origin(inner, origin); | ||
Self { inner } | ||
} | ||
pub fn with_interceptor<F>( | ||
inner: T, | ||
interceptor: F, | ||
) -> AuthServiceClient<InterceptedService<T, F>> | ||
where | ||
F: tonic::service::Interceptor, | ||
T::ResponseBody: Default, | ||
T: tonic::codegen::Service< | ||
http::Request<tonic::body::BoxBody>, | ||
Response = http::Response< | ||
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody, | ||
>, | ||
>, | ||
<T as tonic::codegen::Service< | ||
http::Request<tonic::body::BoxBody>, | ||
>>::Error: Into<StdError> + Send + Sync, | ||
{ | ||
AuthServiceClient::new(InterceptedService::new(inner, interceptor)) | ||
} | ||
/// Compress requests with the given encoding. | ||
/// This requires the server to support it otherwise it might respond with an | ||
/// error. | ||
#[must_use] | ||
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { | ||
self.inner = self.inner.send_compressed(encoding); | ||
self | ||
} | ||
/// Enable decompressing responses. | ||
#[must_use] | ||
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { | ||
self.inner = self.inner.accept_compressed(encoding); | ||
self | ||
} | ||
/// Perform login using built-in auth system | ||
pub async fn login( | ||
&mut self, | ||
request: impl tonic::IntoRequest<super::super::LoginRequest>, | ||
) -> Result<tonic::Response<super::super::LoginResponse>, tonic::Status> { | ||
self.inner | ||
.ready() | ||
.await | ||
.map_err(|e| { | ||
tonic::Status::new( | ||
tonic::Code::Unknown, | ||
format!("Service was not ready: {}", e.into()), | ||
) | ||
})?; | ||
let codec = tonic::codec::ProstCodec::default(); | ||
let path = http::uri::PathAndQuery::from_static( | ||
"/Ydb.Auth.V1.AuthService/Login", | ||
); | ||
self.inner.unary(request.into_request(), path, codec).await | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use ydb_grpc::ydb_proto::auth::v1::auth_service_client::AuthServiceClient; | ||
|
||
use crate::grpc_wrapper::raw_auth_service::login::RawLoginResult; | ||
use crate::grpc_wrapper::raw_auth_service::login::RawLoginRequest; | ||
use crate::grpc_wrapper::runtime_interceptors::InterceptedChannel; | ||
use crate::grpc_wrapper::raw_errors::RawResult; | ||
|
||
use tracing::trace; | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct RawAuthClient { | ||
service: AuthServiceClient<InterceptedChannel>, | ||
} | ||
|
||
impl RawAuthClient { | ||
#[allow(dead_code)] | ||
pub fn new(service: InterceptedChannel) -> Self { | ||
Self { | ||
service: AuthServiceClient::new(service), | ||
} | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub async fn login(&mut self, req: RawLoginRequest) -> RawResult<RawLoginResult> { | ||
request_with_result!( | ||
self.service.login, | ||
req => ydb_grpc::ydb_proto::auth::LoginRequest, | ||
ydb_grpc::ydb_proto::auth::LoginResult => RawLoginResult | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use ydb_grpc::ydb_proto::auth::LoginRequest; | ||
use ydb_grpc::ydb_proto::auth::LoginResult; | ||
|
||
use crate::grpc_wrapper::raw_ydb_operation::RawOperationParams; | ||
use crate::grpc_wrapper::raw_errors::RawError; | ||
use crate::grpc_wrapper::raw_errors::RawResult; | ||
|
||
|
||
#[derive(serde::Serialize)] | ||
pub(crate) struct RawLoginRequest { | ||
pub operation_params: RawOperationParams, | ||
pub user: String, | ||
pub password: String, | ||
} | ||
|
||
impl From<RawLoginRequest> for LoginRequest { | ||
fn from(value: RawLoginRequest) -> Self { | ||
Self { | ||
operation_params: Some(value.operation_params.into()), | ||
user: value.user, | ||
password: value.password, | ||
} | ||
} | ||
} | ||
|
||
#[allow(dead_code)] | ||
#[derive(Debug)] | ||
pub(crate) struct RawLoginResult { | ||
pub token: String, | ||
} | ||
|
||
impl TryFrom<LoginResult> for RawLoginResult { | ||
type Error = RawError; | ||
|
||
fn try_from(value: LoginResult) -> RawResult<Self> { | ||
Ok(Self { | ||
token: value.token, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub(crate) mod client; | ||
pub(crate) mod login; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters