Skip to content

Commit 06de2d3

Browse files
committed
Start creating launcher binary
1 parent 64a41bd commit 06de2d3

13 files changed

Lines changed: 2082 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 94 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ resolver = "2"
33
default-members = ["crates/trident"]
44

55
members = [
6-
"crates/trident",
7-
"crates/trident_api",
8-
"crates/osutils",
96
"crates/docbuilder",
10-
"crates/pytest",
7+
"crates/launcher",
8+
"crates/osutils",
119
"crates/pytest_gen",
10+
"crates/pytest",
1211
"crates/sysdefs",
12+
"crates/trident_api",
1313
"crates/trident-proto",
14+
"crates/trident",
1415
]
1516

1617
[workspace.dependencies]

crates/launcher/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "launcher"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
anyhow = { version = "1.0.82", features = ["backtrace"] }
9+
log = "0.4.21"
10+
quick-xml = { version = "0.37.1", features = ["serialize"] }
11+
reqwest = { version = "0.12.4", default-features = false, features = [
12+
"blocking",
13+
"default-tls",
14+
"charset",
15+
] } # "http2" is enabled by default but causes a (false positive) CG alert
16+
semver = "1.0.23"
17+
serde = { version = "1.0.200", features = ["derive"] }
18+
serde_path_to_error = "0.1"
19+
sha2 = "0.10.8"
20+
thiserror = "1.0.59"
21+
url = { version = "2.5.0", features = ["serde"] }
22+
uuid = { version = "1.8.0", features = ["v4", "serde"] }
23+
clap = { workspace = true, features = ["derive"] }
24+
systemd-journal-logger = {workspace = true}
25+
env_logger = { workspace = true}
26+
tokio = { workspace = true }
27+
28+
sysdefs = { path = "../sysdefs" }
29+
osutils = { path = "../osutils" }
30+
trident-proto = { path = "../trident-proto" }
31+
tonic.workspace = true
32+
futures = "0.3.32"
33+
34+
[dev-dependencies]
35+
indoc = "2"
36+
maplit = "1.0.2"
37+
mockito = "1.6.0"
38+
serde_json = "1.0"

crates/launcher/src/error.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use crate::omaha::event::{EventResult, OmahaEventType};
4+
5+
#[derive(Debug, Eq, thiserror::Error, Serialize, Deserialize, PartialEq)]
6+
#[serde(rename_all = "kebab-case")]
7+
pub enum HarpoonError {
8+
#[error("Failed to initialize the Harpoon client: {0}")]
9+
InitializationError(String),
10+
11+
#[error("The version provided '{version}' is not valid semver: {inner}")]
12+
InvalidVersion { version: String, inner: String },
13+
14+
#[error("Failed to read machine-id: {0}")]
15+
MachineIdRead(String),
16+
17+
#[error("Failed to read hostname: {0}")]
18+
HostnameRead(String),
19+
20+
#[error("Internal error: {0}")]
21+
Internal(String),
22+
23+
#[error("Failed to send request: {0}")]
24+
SendRequest(String),
25+
26+
#[error("Received an HTTP error: {0}")]
27+
HttpError(String),
28+
29+
#[error("Failed to parse response: {0}")]
30+
ParseResponse(String),
31+
32+
#[error("Received an invalid response from the server: {0}")]
33+
InvalidResponse(String),
34+
35+
#[error("Failed to query for updates: {0}")]
36+
QueryError(String),
37+
38+
#[error("Failed to fetch the updated document: {0}")]
39+
FetchError(String),
40+
41+
#[error(
42+
"Expected a yaml document, but the provided URL does not have a .yaml extension '{0}'"
43+
)]
44+
ExpectedYamlDocument(String),
45+
46+
#[error("Event '{0:?}:{1:?}' was not acknowledged by server.")]
47+
EventNotAcknowledged(OmahaEventType, EventResult),
48+
}

crates/launcher/src/id.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::fmt::Display;
2+
3+
use osutils::{hostname, machine_id::MachineId};
4+
5+
use crate::error::HarpoonError;
6+
7+
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
8+
pub enum IdSource {
9+
MachineIdHashed,
10+
MachineIdRaw,
11+
Hostname,
12+
}
13+
14+
impl Display for IdSource {
15+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16+
match self {
17+
IdSource::MachineIdHashed => write!(f, "machin-id-hashed"),
18+
IdSource::MachineIdRaw => write!(f, "machine-id-raw"),
19+
IdSource::Hostname => write!(f, "hostname"),
20+
}
21+
}
22+
}
23+
24+
impl IdSource {
25+
pub(super) fn produce_id(&self) -> Result<String, HarpoonError> {
26+
Ok(match self {
27+
IdSource::MachineIdHashed => MachineId::read()
28+
.map_err(|err| HarpoonError::MachineIdRead(err.to_string()))?
29+
.hashed_uuid()
30+
.to_string(),
31+
IdSource::MachineIdRaw => MachineId::read()
32+
.map_err(|err| HarpoonError::MachineIdRead(err.to_string()))?
33+
.as_string(),
34+
IdSource::Hostname => {
35+
hostname::read().map_err(|err| HarpoonError::HostnameRead(err.to_string()))?
36+
}
37+
})
38+
}
39+
}

0 commit comments

Comments
 (0)