Skip to content

Commit

Permalink
Merge branch 'master' into shishqa/semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby authored Jan 23, 2024
2 parents 1615dbd + 997754b commit 4a21c37
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 0 deletions.
1 change: 1 addition & 0 deletions ydb-grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use walkdir::WalkDir;
const DST_FOLDER: &str = "src/generated";

const COMPILE_FILES: &[&str] = &[
"ydb_auth_v1.proto",
"ydb_coordination_v1.proto",
"ydb_discovery_v1.proto",
"ydb_scheme_v1.proto",
Expand Down
6 changes: 6 additions & 0 deletions ydb-grpc/src/generated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pub mod google {
}
}
pub mod ydb {
pub mod auth {
pub mod v1 {
include!("ydb.auth.v1.rs");
}
include!("ydb.auth.rs");
}
pub mod coordination {
pub mod v1 {
include!("ydb.coordination.v1.rs");
Expand Down
23 changes: 23 additions & 0 deletions ydb-grpc/src/generated/ydb.auth.rs
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,
}
90 changes: 90 additions & 0 deletions ydb-grpc/src/generated/ydb.auth.v1.rs
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
}
}
}
1 change: 1 addition & 0 deletions ydb/src/grpc_wrapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) mod grpc;
#[macro_use]
mod macroses;
pub(crate) mod grpc_stream_wrapper;
pub(crate) mod raw_auth_service;
pub(crate) mod raw_common_types;
pub(crate) mod raw_discovery_client;
pub(crate) mod raw_errors;
Expand Down
31 changes: 31 additions & 0 deletions ydb/src/grpc_wrapper/raw_auth_service/client.rs
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
);
}
}
40 changes: 40 additions & 0 deletions ydb/src/grpc_wrapper/raw_auth_service/login.rs
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,
})
}
}
2 changes: 2 additions & 0 deletions ydb/src/grpc_wrapper/raw_auth_service/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod client;
pub(crate) mod login;
2 changes: 2 additions & 0 deletions ydb/src/trait_operation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::Debug;
use ydb_grpc::ydb_proto::auth::LoginResponse;
use ydb_grpc::ydb_proto::coordination::{
AlterNodeResponse, CreateNodeResponse, DescribeNodeResponse, DropNodeResponse,
};
Expand Down Expand Up @@ -48,3 +49,4 @@ operation_impl_for!(AlterNodeResponse);
operation_impl_for!(DropNodeResponse);
operation_impl_for!(CopyTableResponse);
operation_impl_for!(CopyTablesResponse);
operation_impl_for!(LoginResponse);

0 comments on commit 4a21c37

Please sign in to comment.