Skip to content

Commit 12fa6af

Browse files
committed
Checkpoint Omaha server connection logic
1 parent 265734a commit 12fa6af

1 file changed

Lines changed: 47 additions & 35 deletions

File tree

crates/launcher/src/main.rs

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ pub struct HarpoonQueryResponse {
4747
#[derive(Debug, PartialEq, Eq)]
4848
pub enum QueryResult {
4949
NoUpdate,
50-
NewDocument {
51-
url: Url,
52-
version: Version,
53-
document: String,
54-
},
50+
NewDocument { url: Url, version: Version },
5551
}
5652

5753
#[derive(Parser, Debug)]
@@ -82,8 +78,7 @@ enum Command {
8278
},
8379
}
8480

85-
#[tokio::main]
86-
async fn main() {
81+
fn main() {
8782
let args = Args::parse();
8883

8984
if let Some(Ok(journal_logger)) =
@@ -103,6 +98,7 @@ async fn main() {
10398
match args.trigger {
10499
Some(Command::Trigger { url, hash }) => {
105100
debug!("Triggering update with URL: {url} and hash: {hash:?}");
101+
//trigger(&url, hash).await.unwrap();
106102
}
107103
Some(Command::Run {
108104
url,
@@ -114,6 +110,18 @@ async fn main() {
114110
}
115111
None => {
116112
debug!("No command provided. Exiting.");
113+
114+
let r = query_and_fetch_yaml_document(
115+
&Url::parse("https://nebraska-poc-ep-cda8e2czfnhahxfk.b01.azurefd.net/v1/update")
116+
.unwrap(),
117+
"b0ec8f0d-1c13-4bf4-9efd-ea54464a7098",
118+
"west-us",
119+
&Version::new(3, 1, 0),
120+
IdSource::MachineIdHashed,
121+
)
122+
.expect("Failed to query Omaha server");
123+
124+
debug!("Query result: {r:?}");
117125
}
118126
}
119127
}
@@ -134,9 +142,9 @@ async fn trigger(url: &Url, hash: Option<String>) -> Result<(), anyhow::Error> {
134142
stage: Some(StageUpdateRequest {
135143
config: Some(HostConfiguration {
136144
config: match hash {
137-
Some(hash) => format!("image:\n url: {url}\n hash: {hash}"),
145+
Some(hash) => format!("image:\n url: {url}\n sha384: {hash}"),
138146
None => {
139-
format!("image:\n url: {url}")
147+
format!("image:\n url: {url}\n sha384: ignored")
140148
}
141149
},
142150
}),
@@ -234,6 +242,13 @@ pub fn query_and_fetch_yaml_document(
234242

235243
let response = omaha::send(url, &request)?;
236244

245+
debug!(
246+
"Received response from Omaha server at '{url}' for app '{app_id}' on track '{track}': {response:#?}",
247+
url = url,
248+
app_id = app_id,
249+
track = track,
250+
response = response
251+
);
237252
if response.apps().len() != 1 {
238253
return Err(HarpoonError::InvalidResponse(
239254
"Expected exactly one app in response".to_string(),
@@ -258,6 +273,7 @@ pub fn query_and_fetch_yaml_document(
258273
let update_check = app.update_check().ok_or_else(|| {
259274
HarpoonError::InvalidResponse("Missing update check in response".to_string())
260275
})?;
276+
debug!("Received update check response: {update_check:#?}");
261277

262278
if update_check.status().is_error() {
263279
return Err(HarpoonError::QueryError(format!(
@@ -293,44 +309,40 @@ pub fn query_and_fetch_yaml_document(
293309
));
294310
}
295311

296-
// Download the document and get the URL from which it was downloaded.
297-
let response_result = download_document(
298-
update_base_url,
299-
update_check.packages().first().unwrap(),
300-
".yaml",
301-
);
302-
303-
// Send an Update Download Finished event to the server as best effort. Do
304-
// not fail the query if the event fails to send.
305-
if let Err(err) = report_omaha_event(
306-
url,
307-
app_id,
308-
track,
309-
OmahaEventType::UpdateDownloadFinished,
310-
match response_result {
311-
Ok(_) => EventResult::Success,
312-
Err(_) => EventResult::Error,
313-
},
314-
machine_id_source,
315-
) {
316-
error!("Failed to send UpdateDownloadFinished event to server at '{url}': {err}");
317-
}
318-
319-
// Now let's check if we successfully downloaded the document.
320-
let (document, package_url) = response_result?;
312+
let package_url = update_base_url
313+
.join(&update_check.packages().first().unwrap().name)
314+
.map_err(|err| {
315+
HarpoonError::InvalidResponse(format!("Failed to join URL with package name: {err}"))
316+
})?;
317+
318+
// // Send an Update Download Finished event to the server as best effort. Do
319+
// // not fail the query if the event fails to send.
320+
// if let Err(err) = report_omaha_event(
321+
// url,
322+
// app_id,
323+
// track,
324+
// OmahaEventType::UpdateDownloadFinished,
325+
// match response_result {
326+
// Ok(_) => EventResult::Success,
327+
// Err(_) => EventResult::Error,
328+
// },
329+
// machine_id_source,
330+
// ) {
331+
// error!("Failed to send UpdateDownloadFinished event to server at '{url}': {err}");
332+
// }
321333

322334
// Now let's report that we dowloaded the update!
323335
debug!(
324336
"Downloaded update for app '{}' v{} to v{}",
325337
app_id, document_version, new_version
326338
);
339+
debug!("Document URL: {package_url}");
327340

328341
Ok(HarpoonQueryResponse {
329342
session_id: request.session_id(),
330343
result: QueryResult::NewDocument {
331344
url: package_url,
332345
version: new_version.as_version().clone(),
333-
document,
334346
},
335347
})
336348
}

0 commit comments

Comments
 (0)