Skip to content

Commit

Permalink
Recognize the new DPS registration substatus that indicates cloud ide…
Browse files Browse the repository at this point in the history
…ntity did not change. (#3834)

This commit replaces the "deviceDataUpdated" speculatively added by
1750d17 with the actual substatus that
DPS has added. The semantics are still the same.
  • Loading branch information
arsing authored Nov 11, 2020
1 parent 6ee9270 commit 2321509
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
3 changes: 0 additions & 3 deletions edgelet/dps/src/dps.rs

This file was deleted.

3 changes: 1 addition & 2 deletions edgelet/dps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
clippy::use_self
)]

pub mod dps;
pub mod error;
mod model;
pub mod registration;
Expand All @@ -22,4 +21,4 @@ pub use model::{
};
pub use registration::{DpsClient, DpsTokenSource};

pub const DPS_API_VERSION: &str = "2018-11-01";
pub const DPS_API_VERSION: &str = "2019-04-15";
6 changes: 3 additions & 3 deletions edgelet/dps/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ mod tests {

#[test]
fn server_register_with_sym_key_auth_success() {
let expected_uri = "https://global.azure-devices-provisioning.net/scope/registrations/reg/register?api-version=2018-11-01";
let expected_uri = "https://global.azure-devices-provisioning.net/scope/registrations/reg/register?api-version=2019-04-15";
let handler = move |req: Request<Body>| {
let (
http::request::Parts {
Expand Down Expand Up @@ -734,7 +734,7 @@ mod tests {

#[test]
fn server_register_with_x509_auth_success() {
let expected_uri = "https://global.azure-devices-provisioning.net/scope/registrations/reg/register?api-version=2018-11-01";
let expected_uri = "https://global.azure-devices-provisioning.net/scope/registrations/reg/register?api-version=2019-04-15";
let handler = move |req: Request<Body>| {
let (
http::request::Parts {
Expand Down Expand Up @@ -1203,7 +1203,7 @@ mod tests {

#[test]
fn get_operation_status_success() {
let expected_uri = "https://global.azure-devices-provisioning.net/scope_id/registrations/reg/operations/operation?api-version=2018-11-01";
let expected_uri = "https://global.azure-devices-provisioning.net/scope_id/registrations/reg/operations/operation?api-version=2019-04-15";
let handler = move |req: Request<Body>| {
let (http::request::Parts { method, uri, .. }, _body) = req.into_parts();
assert_eq!(uri, expected_uri);
Expand Down
37 changes: 27 additions & 10 deletions edgelet/provisioning/src/provisioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ pub enum ProvisioningStatus {

#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq)]
pub enum ReprovisioningStatus {
DeviceDataNotUpdated,
DeviceDataUpdated,
InitialAssignment,
// DPS provisioning substatuses.
//
// Ref: The `substatus` field in https://docs.microsoft.com/en-us/rest/api/iot-dps/runtimeregistration/registerdevice
DeviceDataMigrated,
DeviceDataReset,
InitialAssignment,
ReprovisionedToInitialAssignment,

// A synthetic reprovisioning status that's used when
//
// - DPS is not being used
// - DPS is being used but could not be contacted but there was an error during the provisioning and we can fall back to the backup
// - DPS provisioning returned "reprovisionedToInitialAssignment" and it matches the backup we already have
DeviceDataNotUpdated,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -120,13 +129,18 @@ impl Credentials {

impl From<&str> for ReprovisioningStatus {
fn from(s: &str) -> ReprovisioningStatus {
// TODO: check with DPS substatus value for DeviceDataUpdated when it is implemented on service side
match s {
"deviceDataMigrated" => ReprovisioningStatus::DeviceDataMigrated,
"deviceDataReset" => ReprovisioningStatus::DeviceDataReset,
"initialAssignment" => ReprovisioningStatus::InitialAssignment,
"reprovisionedToInitialAssignment" => {
ReprovisioningStatus::ReprovisionedToInitialAssignment
}
_ => {
debug!("Provisioning result substatus {}", s);
debug!(
r#"Unidentified provisioning result substatus {:?} will be treated as "initialAssignment""#,
s
);
ReprovisioningStatus::InitialAssignment
}
}
Expand Down Expand Up @@ -836,12 +850,15 @@ where
move |mut prov_result| {
debug!("Provisioning result {:?}", prov_result);
let reconfigure = match prov_result.reconfigure {
ReprovisioningStatus::DeviceDataUpdated => {
ReprovisioningStatus::ReprovisionedToInitialAssignment => {
if Self::diff_with_backup(&path, &prov_result) {
info!("Provisioning credentials were changed.");
info!("\
Device registration is unchanged in Azure but does not match local provisioning backup, \
so provisioning result substatus \"reprovisionedToInitialAssignment\" will be treated as \"initialAssignment\".\
");
ReprovisioningStatus::InitialAssignment
} else {
info!("No changes to device reprovisioning.");
info!(r#"Device registration is unchanged in Azure and matches local provisioning backup."#);
ReprovisioningStatus::DeviceDataNotUpdated
}
}
Expand Down Expand Up @@ -908,7 +925,7 @@ mod tests {
Box::new(future::ok(ProvisioningResult {
device_id: "TestDevice".to_string(),
hub_name: "TestHub".to_string(),
reconfigure: ReprovisioningStatus::DeviceDataUpdated,
reconfigure: ReprovisioningStatus::ReprovisionedToInitialAssignment,
sha256_thumbprint: None,
credentials: None,
}))
Expand All @@ -931,7 +948,7 @@ mod tests {
Box::new(future::ok(ProvisioningResult {
device_id: "TestDevice".to_string(),
hub_name: "TestHubUpdated".to_string(),
reconfigure: ReprovisioningStatus::DeviceDataUpdated,
reconfigure: ReprovisioningStatus::ReprovisionedToInitialAssignment,
sha256_thumbprint: None,
credentials: None,
}))
Expand Down

0 comments on commit 2321509

Please sign in to comment.