Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions src/algebra/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ fn query(
map
});

computation
.and_then(|computation| computation.clone().query_params)
.map(|payload| {
match query_params {
Some(query_params) => {
let payload = computation.and_then(|computation| computation.clone().query_params);
let handlebars = handlebars::Handlebars::new();

let query_params_str = serde_json::to_string_pretty(&query_params).map_err(|e| {
Expand All @@ -126,13 +126,10 @@ fn query(
InternalError::encryption_error("Failed to serialize query params", None)
})?);

query_params
})
.transpose()
.map_err(|e| {
warn!("Failed to compute query params: {}", e);
InternalError::encryption_error("Failed to compute query params", None)
})
query_params.map(Some)
}
None => Ok(None),
}
}

fn headers(
Expand All @@ -155,9 +152,9 @@ fn headers(
Some(map)
});

computation
.and_then(|computation| computation.clone().headers)
.map(|payload| {
match headers {
Some(headers) => {
let payload = computation.and_then(|computation| computation.clone().headers);
let handlebars = handlebars::Handlebars::new();

let headers_str = serde_json::to_string_pretty(&headers).map_err(|e| {
Expand Down Expand Up @@ -197,11 +194,8 @@ fn headers(
Ok(header_map)
});

headers
})
.transpose()
.map_err(|e| {
warn!("Failed to compute headers: {}", e);
InternalError::encryption_error("Failed to compute headers", None)
})
headers.map(Some)
}
None => Ok(None),
}
}
25 changes: 23 additions & 2 deletions src/algebra/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ impl Actor for TriggerActor {

impl Supervised for TriggerActor {}

#[derive(Debug, Clone, serde::Serialize)]
pub struct OAuthJson {
#[serde(flatten)]
pub json: serde_json::Value,
pub metadata: OAuthSecret,
}

impl OAuthJson {
pub fn as_json(&self) -> serde_json::Value {
serde_json::to_value(self).unwrap_or_default()
}
}

impl Handler<Trigger> for TriggerActor {
type Result = ResponseFuture<Outcome>;

Expand Down Expand Up @@ -171,13 +184,21 @@ impl Handler<Trigger> for TriggerActor {
InternalError::decryption_error("Failed to parse response", None)
})?;

// This is done because some platforms do not return a refresh token in the response
// (i.e. Salesforce). In these cases, we hold on to the original refresh token as a backup.
let json_oauth = OAuthJson {
json: json.clone(),
metadata: secret.clone(),
}
.as_json();

let decoded: OAuthResponse = conn_oauth_definition
.compute
.refresh
.response
.compute(&json)
.compute(&json_oauth)
.map_err(|e| {
warn!("Failed to decode oauth response from {}: {}", json, e);
warn!("Failed to decode oauth response from {}: {}", json_oauth, e);
InternalError::decryption_error("Failed to decode oauth response", None)
})?;

Expand Down