Skip to content

Commit

Permalink
RSDK-4755: hacky way that made it work
Browse files Browse the repository at this point in the history
  • Loading branch information
ohEmily committed Sep 1, 2023
1 parent 9cd1ff7 commit 02f06f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
21 changes: 3 additions & 18 deletions src/ffi/dial_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DialBuilder<WithCredentials>> {
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()
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/rpc/dial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ pub enum ViamChannel {

#[derive(Debug)]
pub struct RPCCredentials {
entity: Option<&'static str>,
entity: Option<String>,
credentials: Credentials,
}

impl RPCCredentials {
pub fn new(entity: Option<&str>, r#type: SecretType, payload: String) -> Self {
pub fn new(entity: Option<String>, r#type: SecretType, payload: String) -> Self {
Self {
credentials: Credentials { r#type, payload },
entity,
Expand Down Expand Up @@ -569,11 +569,11 @@ impl DialBuilder<WithoutCredentials> {
async fn get_auth_token(
channel: &mut Channel,
creds: Credentials,
entity: &str,
entity: String,
) -> Result<String> {
let mut auth_service = AuthServiceClient::new(channel);
let req = AuthenticateRequest {
entity: entity.to_string(),
entity,
credentials: Some(creds),
};

Expand Down Expand Up @@ -647,7 +647,7 @@ impl DialBuilder<WithCredentials> {
.credentials
.unwrap()
.entity
.unwrap_or_else(|| &domain),
.unwrap_or_else(|| domain.clone()),
)
.await?;
log::debug!("{}", log_prefixes::ACQUIRED_AUTH_TOKEN);
Expand Down

0 comments on commit 02f06f1

Please sign in to comment.