Skip to content

Commit 98c9168

Browse files
authoredMar 23, 2021
Add iotedge system reprovision (#4660)
Adds a command to reprovision device with IoT Hub. Also restarts edged so that the new provisioning info is used.
1 parent 51ad827 commit 98c9168

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed
 

‎edgelet/Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎edgelet/identity-client/src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl IdentityClient {
5656
let res = build_request_uri(&self.host, &uri)
5757
.into_future()
5858
.and_then(move |uri| {
59-
request::<_, _, ()>(&client, hyper::Method::POST, &uri, Some(&body))
59+
request_no_content::<_, _>(&client, hyper::Method::POST, &uri, Some(&body))
6060
});
6161

6262
Box::new(res)

‎edgelet/iotedge/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ zip = "0.5.3"
3939

4040
aziot-certd-config = { git = "https://github.com/Azure/iot-identity-service", branch = "main" }
4141
aziot-identity-common = { git = "https://github.com/Azure/iot-identity-service", branch = "main" }
42+
aziot-identity-common-http = { git = "https://github.com/Azure/iot-identity-service", branch = "main" }
4243
aziot-identityd-config = { git = "https://github.com/Azure/iot-identity-service", branch = "main" }
4344
aziot-keyd-config = { git = "https://github.com/Azure/iot-identity-service", branch = "main" }
4445
aziot-keys-common = { git = "https://github.com/Azure/iot-identity-service", branch = "main" }
@@ -51,6 +52,7 @@ edgelet-docker = { path = "../edgelet-docker" }
5152
edgelet-http = { path = "../edgelet-http" }
5253
edgelet-http-mgmt = { path = "../edgelet-http-mgmt" }
5354
edgelet-utils = { path = "../edgelet-utils" }
55+
identity-client = { path = "../identity-client" }
5456
management = { path = "../management" }
5557
support-bundle = { path = "../support-bundle" }
5658

‎edgelet/iotedge/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ fn run() -> Result<(), Error> {
313313
.required(true),
314314
)
315315
)
316+
.subcommand(
317+
SubCommand::with_name("reprovision")
318+
.about("Reprovision device with IoT Hub.")
319+
)
316320
)
317321
.subcommand(
318322
SubCommand::with_name("support-bundle")
@@ -519,6 +523,7 @@ fn run() -> Result<(), Error> {
519523
log::Level::from_str(args.value_of("log_level").expect("Value is required"))
520524
.expect("Value is restricted to parsable fields"),
521525
),
526+
("reprovision", Some(_args)) => System::reprovision(&mut tokio_runtime),
522527

523528
(command, _) => {
524529
eprintln!("Unknown system subcommand {:?}", command);

‎edgelet/iotedge/src/system.rs

+25
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use aziotctl_common::{
99
SERVICE_DEFINITIONS as IS_SERVICES,
1010
};
1111

12+
use aziot_identity_common_http::ApiVersion;
13+
use identity_client::IdentityClient;
14+
1215
use crate::error::{Error, ErrorKind};
1316

1417
lazy_static! {
@@ -71,4 +74,26 @@ impl System {
7174
Error::from(ErrorKind::System)
7275
})
7376
}
77+
78+
pub fn reprovision(runtime: &mut tokio::runtime::Runtime) -> Result<(), Error> {
79+
let uri = url::Url::parse("unix:///run/aziot/identityd.sock")
80+
.expect("hard-coded URI should parse");
81+
let client = IdentityClient::new(ApiVersion::V2020_09_01, &uri);
82+
83+
runtime
84+
.block_on(client.reprovision_device())
85+
.map_err(|err| {
86+
eprintln!("Failed to reprovision: {}", err);
87+
Error::from(ErrorKind::System)
88+
})?;
89+
90+
println!("Successfully reprovisioned with IoT Hub.");
91+
92+
restart(&[&IOTEDGED]).map_err(|err| {
93+
eprintln!("{:#?}", err);
94+
Error::from(ErrorKind::System)
95+
})?;
96+
97+
Ok(())
98+
}
7499
}

0 commit comments

Comments
 (0)