spark_rust/rpc/
mod.rs

1//! RPC client implementation for connecting to Spark nodes.
2//!
3//! This module provides the RPC client implementation used to establish secure connections
4//! to Spark nodes. It handles:
5//! - Connection management and pooling
6//! - Service client creation for different Spark services
7//! - TLS configuration and certificate verification
8//!
9//! The main type is [`SparkRpcClient`] which manages the underlying connection and
10//! provides methods to create service-specific clients.
11
12use connections::connection::SparkConnection;
13use spark_protos::{
14    authn::spark_authn_service_client::SparkAuthnServiceClient,
15    spark::spark_service_client::SparkServiceClient,
16};
17use tonic::transport::Channel;
18
19use crate::error::SparkSdkError;
20
21/// Enum representing different types of Spark RPC clients.
22/// Currently only supports TLS with certificate verification disabled.
23#[derive(Clone)]
24pub(crate) enum SparkRpcClient {
25    /// Default connection type using TLS without certificate verification
26    DefaultConnection(SparkConnection),
27}
28
29impl SparkRpcClient {
30    /// Creates a new Spark service client using the underlying connection.
31    ///
32    /// # Returns
33    /// - `Ok(SparkServiceClient)` if client creation succeeds
34    /// - `Err(SparkSdkError)` if there was an error creating the client
35    pub(crate) fn get_new_spark_service_connection(
36        &self,
37    ) -> Result<SparkServiceClient<Channel>, SparkSdkError> {
38        match self {
39            SparkRpcClient::DefaultConnection(client) => {
40                Ok(SparkServiceClient::new(client.channel.clone()))
41            }
42        }
43    }
44
45    /// Creates a new Spark authentication service client using the underlying connection.
46    ///
47    /// # Returns
48    /// - `Ok(SparkAuthnServiceClient)` if client creation succeeds
49    /// - `Err(SparkSdkError)` if there was an error creating the client
50    pub(crate) fn get_new_spark_authn_service_connection(
51        &self,
52    ) -> Result<SparkAuthnServiceClient<Channel>, SparkSdkError> {
53        match self {
54            SparkRpcClient::DefaultConnection(client) => {
55                Ok(SparkAuthnServiceClient::new(client.channel.clone()))
56            }
57        }
58    }
59}
60
61pub(crate) mod connections;
62pub(crate) mod traits;