-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sdk): fix client tls connections #2223
Changes from all commits
ab91e07
2f60720
01282fb
df80c15
b400b0e
20f84ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ use crate::{request_settings::AppliedRequestSettings, RequestSettings}; | |
use dapi_grpc::core::v0::core_client::CoreClient; | ||
use dapi_grpc::core::v0::{self as core_proto}; | ||
use dapi_grpc::platform::v0::{self as platform_proto, platform_client::PlatformClient}; | ||
use dapi_grpc::tonic::transport::Uri; | ||
use dapi_grpc::tonic::transport::{ClientTlsConfig, Uri}; | ||
use dapi_grpc::tonic::Streaming; | ||
use dapi_grpc::tonic::{transport::Channel, IntoRequest}; | ||
use futures::{future::BoxFuture, FutureExt, TryFutureExt}; | ||
|
@@ -18,59 +18,101 @@ pub type PlatformGrpcClient = PlatformClient<Channel>; | |
/// Core Client using gRPC transport. | ||
pub type CoreGrpcClient = CoreClient<Channel>; | ||
|
||
fn create_channel(uri: Uri, settings: Option<&AppliedRequestSettings>) -> Channel { | ||
let mut builder = Channel::builder(uri); | ||
fn create_channel( | ||
uri: Uri, | ||
settings: Option<&AppliedRequestSettings>, | ||
) -> Result<Channel, dapi_grpc::tonic::transport::Error> { | ||
let mut builder = Channel::builder(uri).tls_config( | ||
ClientTlsConfig::new() | ||
.with_native_roots() | ||
.with_webpki_roots() | ||
.assume_http2(true), | ||
lklimek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)?; | ||
|
||
if let Some(settings) = settings { | ||
if let Some(timeout) = settings.connect_timeout { | ||
builder = builder.connect_timeout(timeout); | ||
} | ||
} | ||
|
||
builder.connect_lazy() | ||
Ok(builder.connect_lazy()) | ||
} | ||
|
||
impl TransportClient for PlatformGrpcClient { | ||
type Error = dapi_grpc::tonic::Status; | ||
|
||
fn with_uri(uri: Uri, pool: &ConnectionPool) -> Self { | ||
pool.get_or_create(PoolPrefix::Platform, &uri, None, || { | ||
Self::new(create_channel(uri.clone(), None)).into() | ||
}) | ||
.into() | ||
fn with_uri(uri: Uri, pool: &ConnectionPool) -> Result<Self, Self::Error> { | ||
Ok(pool | ||
.get_or_create(PoolPrefix::Platform, &uri, None, || { | ||
match create_channel(uri.clone(), None) { | ||
Ok(channel) => Ok(Self::new(channel).into()), | ||
Err(e) => Err(dapi_grpc::tonic::Status::failed_precondition(format!( | ||
"Channel creation failed: {}", | ||
e | ||
))), | ||
} | ||
Comment on lines
+48
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Review the use of gRPC status code for error handling When handling errors from Apply this diff if you decide to change the status code: Err(e) => Err(dapi_grpc::tonic::Status::failed_precondition(format!(
- "Channel creation failed: {}",
+ "Channel is unavailable: {}",
e
))),
|
||
})? | ||
.into()) | ||
} | ||
|
||
fn with_uri_and_settings( | ||
uri: Uri, | ||
settings: &AppliedRequestSettings, | ||
pool: &ConnectionPool, | ||
) -> Self { | ||
pool.get_or_create(PoolPrefix::Platform, &uri, Some(settings), || { | ||
Self::new(create_channel(uri.clone(), Some(settings))).into() | ||
}) | ||
.into() | ||
) -> Result<Self, Self::Error> { | ||
Ok(pool | ||
.get_or_create( | ||
PoolPrefix::Platform, | ||
&uri, | ||
Some(settings), | ||
|| match create_channel(uri.clone(), Some(settings)) { | ||
Ok(channel) => Ok(Self::new(channel).into()), | ||
Err(e) => Err(dapi_grpc::tonic::Status::failed_precondition(format!( | ||
"Channel creation failed: {}", | ||
e | ||
))), | ||
}, | ||
)? | ||
.into()) | ||
} | ||
} | ||
|
||
impl TransportClient for CoreGrpcClient { | ||
type Error = dapi_grpc::tonic::Status; | ||
|
||
fn with_uri(uri: Uri, pool: &ConnectionPool) -> Self { | ||
pool.get_or_create(PoolPrefix::Core, &uri, None, || { | ||
Self::new(create_channel(uri.clone(), None)).into() | ||
}) | ||
.into() | ||
fn with_uri(uri: Uri, pool: &ConnectionPool) -> Result<Self, Self::Error> { | ||
Ok(pool | ||
.get_or_create(PoolPrefix::Core, &uri, None, || { | ||
match create_channel(uri.clone(), None) { | ||
Ok(channel) => Ok(Self::new(channel).into()), | ||
Err(e) => Err(dapi_grpc::tonic::Status::failed_precondition(format!( | ||
"Channel creation failed: {}", | ||
e | ||
))), | ||
} | ||
})? | ||
.into()) | ||
} | ||
|
||
fn with_uri_and_settings( | ||
uri: Uri, | ||
settings: &AppliedRequestSettings, | ||
pool: &ConnectionPool, | ||
) -> Self { | ||
pool.get_or_create(PoolPrefix::Core, &uri, Some(settings), || { | ||
Self::new(create_channel(uri.clone(), Some(settings))).into() | ||
}) | ||
.into() | ||
) -> Result<Self, Self::Error> { | ||
Ok(pool | ||
.get_or_create( | ||
PoolPrefix::Core, | ||
&uri, | ||
Some(settings), | ||
|| match create_channel(uri.clone(), Some(settings)) { | ||
Ok(channel) => Ok(Self::new(channel).into()), | ||
Err(e) => Err(dapi_grpc::tonic::Status::failed_precondition(format!( | ||
"Channel creation failed: {}", | ||
e | ||
))), | ||
}, | ||
)? | ||
.into()) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Unhandled
Result
types detected inTransportClient
method calls.The recent changes to
with_uri
andwith_uri_and_settings
methods introduceResult<Self, Self::Error>
returns, enhancing error handling capabilities. However, several usages of these methods do not handle theResult
, which could lead to unhandled errors and potential application instability.Please address the following instances to ensure proper error handling:
packages/rs-sdk/src/platform/types/evonode.rs: let client_result = Self::Client::with_uri_and_settings(uri.clone(), settings, &pool);
packages/rs-dapi-client/src/dapi_client.rs: let mut transport_client = R::Client::with_uri_and_settings(
packages/rs-dapi-client/src/transport/grpc.rs: fn with_uri(uri: Uri, pool: &ConnectionPool) -> Result<Self, Self::Error> {
packages/rs-dapi-client/src/transport/grpc.rs: fn with_uri_and_settings(
packages/rs-dapi-client/src/transport/grpc.rs: fn with_uri(uri: Uri, pool: &ConnectionPool) -> Result<Self, Self::Error> {
packages/rs-dapi-client/src/transport/grpc.rs: fn with_uri_and_settings(
Ensure that each method call appropriately handles the
Result
using the?
operator,match
statements, or other suitable error handling mechanisms.🔗 Analysis chain
Potential breaking changes and testing recommendation.
The modifications to both
with_uri
andwith_uri_and_settings
methods improve error handling, which aligns with the PR objective of fixing client TLS connections. However, these changes may be breaking if not all implementations and usages have been updated accordingly.TransportClient
have been updated to match the new signatures.Result
return type correctly.Run the following script to find potential usage of these methods that might need updating:
Please confirm that comprehensive testing has been performed to validate these changes across the entire codebase.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 923
Script:
Length of output: 2254