Skip to content

Commit 168d96a

Browse files
committed
style: cargo-fmt fixes
1 parent 8bc22f4 commit 168d96a

File tree

9 files changed

+132
-115
lines changed

9 files changed

+132
-115
lines changed

src/auth.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ use tokio::sync::{mpsc, oneshot};
44

55
use anyhow::Result;
66

7-
use actix_web::{error, get, web, App, HttpServer};
7+
use actix_web::{App, HttpServer, error, get, web};
88
use serde::Deserialize;
99

10-
use oauth2::basic::BasicClient;
1110
use oauth2::{
1211
AuthUrl, AuthorizationCode, ClientId, CsrfToken, PkceCodeChallenge, RedirectUrl, TokenResponse,
13-
TokenUrl,
12+
TokenUrl, basic::BasicClient,
1413
};
1514

1615
#[derive(Deserialize)]

src/device_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{Context, Result};
22
use azure_identity::{ClientSecretCredential, TokenCredentialOptions};
33
use azure_iot_deviceupdate::DeviceUpdateClient;
4-
use azure_storage::{shared_access_signature::service_sas::BlobSasPermissions, StorageCredentials};
4+
use azure_storage::{StorageCredentials, shared_access_signature::service_sas::BlobSasPermissions};
55
use azure_storage_blobs::prelude::{BlobServiceClient, ContainerClient};
66
use base64::prelude::*;
77
use log::{debug, info};

src/file/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ pub mod compression;
22
pub mod functions;
33
use super::validators::{
44
device_update,
5-
identity::{validate_identity, IdentityConfig, IdentityType},
5+
identity::{IdentityConfig, IdentityType, validate_identity},
66
ssh::validate_ssh_pub_key,
77
};
88
use crate::file::functions::{FileCopyFromParams, FileCopyToParams, Partition};
99
use anyhow::{Context, Result};
1010
use log::warn;
1111
use regex::Regex;
12-
use std::fs;
13-
use std::path::{Path, PathBuf};
12+
use std::{
13+
fs,
14+
path::{Path, PathBuf},
15+
};
1416

1517
pub fn set_iotedge_gateway_config(
1618
config_file: &Path,

src/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

3-
use crate::file::functions::read_file_from_image;
43
use crate::file::functions::Partition;
4+
use crate::file::functions::read_file_from_image;
55
use anyhow::{Context, Result};
66
use regex::Regex;
77
use std::sync::LazyLock;

src/lib.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,14 @@ pub fn run() -> Result<()> {
251251
generate_bmap,
252252
compress_image,
253253
}) => {
254-
let cert_info = create_image_cert(
255-
&image,
256-
CertificateOptions {
257-
intermediate_full_chain_cert: &intermediate_full_chain_cert,
258-
intermediate_key: &intermediate_key,
259-
target_cert: "device_cert_path.pem",
260-
target_key: "device_key_path.key.pem",
261-
subject: &device_id,
262-
validity_days: days,
263-
},
264-
)
254+
let cert_info = create_image_cert(&image, CertificateOptions {
255+
intermediate_full_chain_cert: &intermediate_full_chain_cert,
256+
intermediate_key: &intermediate_key,
257+
target_cert: "device_cert_path.pem",
258+
target_key: "device_key_path.key.pem",
259+
subject: &device_id,
260+
validity_days: days,
261+
})
265262
.context("set_device_certificate: could not create certificate")?;
266263

267264
run_image_command(image, generate_bmap, compress_image, |img| {
@@ -282,17 +279,14 @@ pub fn run() -> Result<()> {
282279
generate_bmap,
283280
compress_image,
284281
}) => {
285-
let cert_info = create_image_cert(
286-
&image,
287-
CertificateOptions {
288-
intermediate_full_chain_cert: &intermediate_full_chain_cert,
289-
intermediate_key: &intermediate_key,
290-
target_cert: "edge_ca_cert_path.pem",
291-
target_key: "edge_ca_key_path.key.pem",
292-
subject: &device_id,
293-
validity_days: days,
294-
},
295-
)
282+
let cert_info = create_image_cert(&image, CertificateOptions {
283+
intermediate_full_chain_cert: &intermediate_full_chain_cert,
284+
intermediate_key: &intermediate_key,
285+
target_cert: "edge_ca_cert_path.pem",
286+
target_key: "edge_ca_key_path.key.pem",
287+
subject: &device_id,
288+
validity_days: days,
289+
})
296290
.context("set_edge_ca_certificate: could not create certificate")?;
297291

298292
run_image_command(image, generate_bmap, compress_image, |img| {

src/ssh.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
use std::convert::AsRef;
22
use std::fs;
3-
use std::io::prelude::*;
4-
use std::io::BufWriter;
3+
use std::io::{BufWriter, prelude::*};
54
use std::path::{Path, PathBuf};
65
use std::process::{Command, Stdio};
76
use std::str;
87

9-
use anyhow::anyhow;
10-
use anyhow::{Context, Result};
8+
use anyhow::{Context, Result, anyhow};
119
use directories::ProjectDirs;
1210
use oauth2::AccessToken;
13-
use serde::de::DeserializeOwned;
14-
use serde::{Deserialize, Serialize};
11+
use serde::{Deserialize, Serialize, de::DeserializeOwned};
1512
use url::Url;
1613

1714
static BACKEND_API_ENDPOINT: &str = "/api/devices/prepareSSHConnection";
@@ -192,9 +189,11 @@ async fn unpack_response<T: DeserializeOwned>(response: reqwest::Response) -> Re
192189
internal_message: String,
193190
}
194191

195-
anyhow::bail!(serde_json::from_str::<ErrorMessage>(&body)
196-
.map(|err| err.internal_message)
197-
.unwrap_or_else(|_| "unknown error type".to_string()))
192+
anyhow::bail!(
193+
serde_json::from_str::<ErrorMessage>(&body)
194+
.map(|err| err.internal_message)
195+
.unwrap_or_else(|_| "unknown error type".to_string())
196+
)
198197
} else {
199198
serde_json::from_str(&body).map_err(|_| anyhow!("unsupported reply."))
200199
}

src/validators/identity.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Context, Result};
1+
use anyhow::{Context, Result, anyhow};
22
use log::debug;
33
use regex::Regex;
44
use serde::Deserialize;
@@ -189,19 +189,15 @@ const PAYLOAD_FILEPATH: &str = "file:///etc/omnect/dps-payload.json";
189189
const WARN_MISSING_PROVISIONING: &str = "A provisioning section should be specified.";
190190
const WARN_MISSING_DPS_PARAMS: &str =
191191
"For provisioning source dps, global_endpoint and id_scope should be specified.";
192-
const WARN_MISSING_MANUAL_PARAMS: &str =
193-
"For provisioning source manual, either connection_string or iothub_hostname and device_id are required.";
194-
const WARN_MISSING_AUTHENTICATION: &str =
195-
"For provisioning source manual, an authentication section should be present in the provisioning section.";
196-
const WARN_MISSING_ATTESTATION: &str =
197-
"For provisioning source dps an attestation section should be present in the provisioning section.";
192+
const WARN_MISSING_MANUAL_PARAMS: &str = "For provisioning source manual, either connection_string or iothub_hostname and device_id are required.";
193+
const WARN_MISSING_AUTHENTICATION: &str = "For provisioning source manual, an authentication section should be present in the provisioning section.";
194+
const WARN_MISSING_ATTESTATION: &str = "For provisioning source dps an attestation section should be present in the provisioning section.";
198195
const WARN_ATTESTATION_VALID_METHOD_EXPECTED: &str =
199196
"The attestation method should be tpm, x509 or symmetric_key.";
200197
const WARN_INVALID_SOURCE: &str = "The provisioning source should be dps or manual.";
201198
const WARN_AUTHENTICATION_VALID_METHOD_EXPECTED: &str = "The authentication method should be sas.";
202199
const WARN_UNEXPECTED_PATH: &str = "Unexpected path found.";
203-
const WARN_UNEQUAL_COMMON_NAME_AND_REGISTRATION_ID: &str =
204-
"provisioning.attestation.registration_id is not equal to provisioning.attestation.identity_cert.common_name";
200+
const WARN_UNEQUAL_COMMON_NAME_AND_REGISTRATION_ID: &str = "provisioning.attestation.registration_id is not equal to provisioning.attestation.identity_cert.common_name";
205201
const WARN_PAYLOAD_FILEPATH_MISSING: &str = "Payload file is configred but file is missing.";
206202
const WARN_PAYLOAD_CONFIG_MISSING: &str = "Payload file is passed but not configred.";
207203

@@ -375,12 +371,14 @@ mod tests {
375371
#[test]
376372
fn identity_config_hostname_valid() {
377373
LazyLock::force(&LOG);
378-
assert!(validate_identity(
379-
IdentityType::Standalone,
380-
Path::new("testfiles/identity_config_hostname_valid.toml"),
381-
&None,
382-
)
383-
.is_ok());
374+
assert!(
375+
validate_identity(
376+
IdentityType::Standalone,
377+
Path::new("testfiles/identity_config_hostname_valid.toml"),
378+
&None,
379+
)
380+
.is_ok()
381+
);
384382
}
385383

386384
#[test]

tests/common/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use data_encoding::HEXUPPER;
22
use env_logger::{Builder, Env};
33
use ring::digest::{Context, SHA256};
4-
use std::fs::copy;
5-
use std::fs::File;
6-
use std::fs::{create_dir_all, remove_dir_all};
4+
use std::fs::{File, copy, create_dir_all, remove_dir_all};
75
use std::io::{BufReader, Read};
86
use std::path::PathBuf;
97
use std::sync::LazyLock;

tests/integration_tests.rs

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,23 @@ fn check_set_identity_gateway_config() {
108108
edge_device_identity_key_file_path.to_str().unwrap(),
109109
edge_device_identity_key_file_out_path
110110
));
111-
assert!(std::path::Path::new(hosts_file_out_path)
112-
.try_exists()
113-
.is_ok_and(|exists| exists));
111+
assert!(
112+
std::path::Path::new(hosts_file_out_path)
113+
.try_exists()
114+
.is_ok_and(|exists| exists)
115+
);
114116

115-
assert!(std::fs::read_to_string(hosts_file_out_path)
116-
.unwrap()
117-
.contains("127.0.1.1 my-omnect-iotedge-gateway-device"));
117+
assert!(
118+
std::fs::read_to_string(hosts_file_out_path)
119+
.unwrap()
120+
.contains("127.0.1.1 my-omnect-iotedge-gateway-device")
121+
);
118122

119-
assert!(std::fs::read_to_string(hostname_file_out_path)
120-
.unwrap()
121-
.contains("my-omnect-iotedge-gateway-device"));
123+
assert!(
124+
std::fs::read_to_string(hostname_file_out_path)
125+
.unwrap()
126+
.contains("my-omnect-iotedge-gateway-device")
127+
);
122128
}
123129

124130
#[test]
@@ -185,13 +191,17 @@ fn check_set_identity_leaf_config() {
185191
root_ca_file_out_path
186192
));
187193

188-
assert!(std::fs::read_to_string(hosts_file_out_path)
189-
.unwrap()
190-
.contains("127.0.1.1 my-omnect-iot-leaf-device"));
194+
assert!(
195+
std::fs::read_to_string(hosts_file_out_path)
196+
.unwrap()
197+
.contains("127.0.1.1 my-omnect-iot-leaf-device")
198+
);
191199

192-
assert!(std::fs::read_to_string(hostname_file_out_path)
193-
.unwrap()
194-
.contains("my-omnect-iot-leaf-device"));
200+
assert!(
201+
std::fs::read_to_string(hostname_file_out_path)
202+
.unwrap()
203+
.contains("my-omnect-iot-leaf-device")
204+
);
195205
}
196206

197207
#[test]
@@ -247,13 +257,17 @@ fn check_set_identity_config_est_template() {
247257
config_file_out_path
248258
));
249259

250-
assert!(std::fs::read_to_string(hosts_file_out_path)
251-
.unwrap()
252-
.contains("127.0.1.1 test-omnect-est"));
260+
assert!(
261+
std::fs::read_to_string(hosts_file_out_path)
262+
.unwrap()
263+
.contains("127.0.1.1 test-omnect-est")
264+
);
253265

254-
assert!(std::fs::read_to_string(hostname_file_out_path)
255-
.unwrap()
256-
.contains("test-omnect-est"));
266+
assert!(
267+
std::fs::read_to_string(hostname_file_out_path)
268+
.unwrap()
269+
.contains("test-omnect-est")
270+
);
257271
}
258272

259273
#[test]
@@ -323,13 +337,17 @@ fn check_set_identity_config_payload_template() {
323337
payload_out_path
324338
));
325339

326-
assert!(std::fs::read_to_string(hosts_file_out_path)
327-
.unwrap()
328-
.contains("127.0.1.1 test-omnect-est-with-payload"));
340+
assert!(
341+
std::fs::read_to_string(hosts_file_out_path)
342+
.unwrap()
343+
.contains("127.0.1.1 test-omnect-est-with-payload")
344+
);
329345

330-
assert!(std::fs::read_to_string(hostname_file_out_path)
331-
.unwrap()
332-
.contains("test-omnect-est-with-payload"));
346+
assert!(
347+
std::fs::read_to_string(hostname_file_out_path)
348+
.unwrap()
349+
.contains("test-omnect-est-with-payload")
350+
);
333351
}
334352

335353
#[test]
@@ -385,13 +403,17 @@ fn check_set_identity_config_tpm_template() {
385403
config_file_out_path
386404
));
387405

388-
assert!(std::fs::read_to_string(hosts_file_out_path)
389-
.unwrap()
390-
.contains("127.0.1.1 test-omnect-tpm"));
406+
assert!(
407+
std::fs::read_to_string(hosts_file_out_path)
408+
.unwrap()
409+
.contains("127.0.1.1 test-omnect-tpm")
410+
);
391411

392-
assert!(std::fs::read_to_string(hostname_file_out_path)
393-
.unwrap()
394-
.contains("test-omnect-tpm"));
412+
assert!(
413+
std::fs::read_to_string(hostname_file_out_path)
414+
.unwrap()
415+
.contains("test-omnect-tpm")
416+
);
395417
}
396418

397419
#[test]
@@ -1009,31 +1031,36 @@ async fn check_ssh_tunnel_setup() {
10091031
.await
10101032
.unwrap();
10111033

1012-
assert!(tr
1013-
.pathbuf()
1014-
.join("config")
1015-
.try_exists()
1016-
.is_ok_and(|exists| exists));
1017-
assert!(tr
1018-
.pathbuf()
1019-
.join("id_ed25519")
1020-
.try_exists()
1021-
.is_ok_and(|exists| exists));
1022-
assert!(tr
1023-
.pathbuf()
1024-
.join("id_ed25519.pub")
1025-
.try_exists()
1026-
.is_ok_and(|exists| exists));
1027-
assert!(tr
1028-
.pathbuf()
1029-
.join("bastion-cert.pub")
1030-
.try_exists()
1031-
.is_ok_and(|exists| exists));
1032-
assert!(tr
1033-
.pathbuf()
1034-
.join("device-cert.pub")
1035-
.try_exists()
1036-
.is_ok_and(|exists| exists));
1034+
assert!(
1035+
tr.pathbuf()
1036+
.join("config")
1037+
.try_exists()
1038+
.is_ok_and(|exists| exists)
1039+
);
1040+
assert!(
1041+
tr.pathbuf()
1042+
.join("id_ed25519")
1043+
.try_exists()
1044+
.is_ok_and(|exists| exists)
1045+
);
1046+
assert!(
1047+
tr.pathbuf()
1048+
.join("id_ed25519.pub")
1049+
.try_exists()
1050+
.is_ok_and(|exists| exists)
1051+
);
1052+
assert!(
1053+
tr.pathbuf()
1054+
.join("bastion-cert.pub")
1055+
.try_exists()
1056+
.is_ok_and(|exists| exists)
1057+
);
1058+
assert!(
1059+
tr.pathbuf()
1060+
.join("device-cert.pub")
1061+
.try_exists()
1062+
.is_ok_and(|exists| exists)
1063+
);
10371064

10381065
let ssh_config = std::fs::read_to_string(tr.pathbuf().join("config")).unwrap();
10391066
let expected_config = format!(

0 commit comments

Comments
 (0)