Skip to content

Commit 5f62bad

Browse files
authored
gate auth context under _secure (#622)
* gate auth context under _secure Signed-off-by: tabokie <[email protected]> * try fix windows action Signed-off-by: tabokie <[email protected]> * rearrange Signed-off-by: tabokie <[email protected]> * reproduce error Signed-off-by: tabokie <[email protected]> * update Signed-off-by: tabokie <[email protected]> * avoid --all Signed-off-by: tabokie <[email protected]> * update Signed-off-by: tabokie <[email protected]> --------- Signed-off-by: tabokie <[email protected]>
1 parent e61834c commit 5f62bad

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ no-omit-frame-pointer = ["grpcio-sys/no-omit-frame-pointer"]
5555
travis-ci = { repository = "tikv/grpc-rs" }
5656

5757
[patch.crates-io]
58-
grpcio-compiler = { path = "compiler", version = "0.12.1", default-features = false }
58+
grpcio-compiler = { path = "compiler", version = "0.12.1" }

src/call/server.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use futures_util::{Sink, Stream};
1616
use parking_lot::Mutex;
1717

1818
use super::{RpcStatus, ShareCall, ShareCallHolder, WriteFlags};
19-
use crate::auth_context::AuthContext;
2019
use crate::buf::GrpcSlice;
2120
use crate::call::{
2221
BatchContext, Call, MessageReader, MethodType, RpcStatusCode, SinkBase, StreamingBase,
@@ -193,10 +192,11 @@ impl RequestContext {
193192
}
194193

195194
/// If the server binds in non-secure mode, this will return None
196-
fn auth_context(&self) -> Option<AuthContext> {
195+
#[cfg(feature = "_secure")]
196+
fn auth_context(&self) -> Option<crate::AuthContext> {
197197
unsafe {
198198
let call = grpc_sys::grpcwrap_request_call_context_get_call(self.ctx);
199-
AuthContext::from_call_ptr(call)
199+
crate::AuthContext::from_call_ptr(call)
200200
}
201201
}
202202
}
@@ -690,7 +690,8 @@ impl<'a> RpcContext<'a> {
690690
/// Wrapper around the gRPC Core AuthContext
691691
///
692692
/// If the server binds in non-secure mode, this will return None
693-
pub fn auth_context(&self) -> Option<AuthContext> {
693+
#[cfg(feature = "_secure")]
694+
pub fn auth_context(&self) -> Option<crate::AuthContext> {
694695
self.ctx.auth_context()
695696
}
696697

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use grpcio_sys as grpc_sys;
2929
#[macro_use]
3030
extern crate log;
3131

32-
mod auth_context;
3332
mod buf;
3433
mod call;
3534
mod channel;
@@ -68,7 +67,6 @@ pub use crate::codec::pb_codec::{de as pb_de, ser as pb_ser};
6867
#[cfg(feature = "prost-codec")]
6968
pub use crate::codec::pr_codec::{de as pr_de, ser as pr_ser};
7069

71-
pub use crate::auth_context::{AuthContext, AuthProperty, AuthPropertyIter};
7270
pub use crate::codec::{Marshaller, MAX_MESSAGE_SIZE};
7371
pub use crate::env::{EnvBuilder, Environment};
7472
pub use crate::error::{Error, Result};
File renamed without changes.

src/security/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.
22

3+
#[cfg(feature = "_secure")]
4+
mod auth_context;
35
#[cfg(feature = "_secure")]
46
mod credentials;
57

68
use grpcio_sys::{grpc_channel_credentials, grpc_server_credentials};
79

10+
#[cfg(feature = "_secure")]
11+
pub use self::auth_context::*;
812
#[cfg(feature = "_secure")]
913
pub use self::credentials::{
1014
CertificateRequestType, ChannelCredentialsBuilder, ServerCredentialsBuilder,
@@ -59,6 +63,7 @@ impl ServerCredentials {
5963
ServerCredentials::from_raw(creds)
6064
}
6165
}
66+
6267
pub(crate) unsafe fn from_raw(creds: *mut grpc_server_credentials) -> ServerCredentials {
6368
ServerCredentials {
6469
creds,

0 commit comments

Comments
 (0)