diff --git a/src/ffi/dial_ffi.rs b/src/ffi/dial_ffi.rs index 7b950a0..1c45ef6 100644 --- a/src/ffi/dial_ffi.rs +++ b/src/ffi/dial_ffi.rs @@ -87,15 +87,13 @@ fn dial_without_cred( fn dial_with_cred( uri: String, - entity: Option<&str>, + entity: &str, r#type: &str, payload: &str, allow_insec: bool, disable_webrtc: bool, ) -> Result> { - log::error!("dial_with_cred\n\n\n\n\n"); - // let creds = RPCCredentials::new(None, String::from(r#type), String::from(payload)); - let creds = RPCCredentials::new(entity, String::from(r#type), String::from(payload)); + let creds = RPCCredentials::new(Some(entity.to_string()), String::from(r#type), String::from(payload)); let c = DialOptions::builder().uri(&uri).with_credentials(creds); let c = if disable_webrtc { c.disable_webrtc() @@ -113,7 +111,6 @@ fn dial_with_cred( /// When falling to dial it will return a NULL pointer /// # Arguments /// * `c_uri` a C-style string representing the address of robot you want to connect to -/// * `c_entity` a C-style string representing the entity passed into the auth API /// * `c_type` a C-style string representing the type of robot's secret you want to use, set to NULL if you don't need authentication /// * `c_payload` a C-style string that is the robot's secret, set to NULL if you don't need authentication /// * `c_allow_insecure` a bool, set to true when allowing insecure connection to your robot @@ -190,24 +187,12 @@ pub unsafe extern "C" fn dial( false => Some(CStr::from_ptr(c_payload)), } }; - let entity = { - match c_entity.is_null() { - true => None, - false => Some(CStr::from_ptr(c_entity)), - } - }; - let (server, channel) = match runtime.block_on(async move { - let e = match entity { - Some(ent) => Some(ent.to_str()?), - None => None, - }; let channel = match (r#type, payload) { (Some(t), Some(p)) => { - log::error!("EMILY before dial_with_cred\n\n\n\n\n"); dial_with_cred( uri_str, - e, + CStr::from_ptr(c_entity).to_str()?, t.to_str()?, p.to_str()?, allow_insec, diff --git a/src/rpc/dial.rs b/src/rpc/dial.rs index 2cc65c3..24d21b1 100644 --- a/src/rpc/dial.rs +++ b/src/rpc/dial.rs @@ -70,12 +70,12 @@ pub enum ViamChannel { #[derive(Debug)] pub struct RPCCredentials { - entity: Option<&'static str>, + entity: Option, credentials: Credentials, } impl RPCCredentials { - pub fn new(entity: Option<&str>, r#type: SecretType, payload: String) -> Self { + pub fn new(entity: Option, r#type: SecretType, payload: String) -> Self { Self { credentials: Credentials { r#type, payload }, entity, @@ -569,11 +569,11 @@ impl DialBuilder { async fn get_auth_token( channel: &mut Channel, creds: Credentials, - entity: &str, + entity: String, ) -> Result { let mut auth_service = AuthServiceClient::new(channel); let req = AuthenticateRequest { - entity: entity.to_string(), + entity, credentials: Some(creds), }; @@ -647,7 +647,7 @@ impl DialBuilder { .credentials .unwrap() .entity - .unwrap_or_else(|| &domain), + .unwrap_or_else(|| domain.clone()), ) .await?; log::debug!("{}", log_prefixes::ACQUIRED_AUTH_TOKEN);