-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for device identity operations (#142)
* Initial work on identities for modules and devices * Add create/update device identity feature * Add missing docs to all enums/structs members and derive default for DeviceCapabilities * Fix formatting
- Loading branch information
1 parent
e1da0cd
commit 5aa5e8e
Showing
4 changed files
with
567 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use iothub::service::identity::{DesiredCapability, Status}; | ||
use iothub::service::ServiceClient; | ||
use std::error::Error; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
let iothub_connection_string = std::env::var("IOTHUB_CONNECTION_STRING") | ||
.expect("Set env variable IOTHUB_CONNECTION_STRING first!"); | ||
|
||
let device_id = std::env::args() | ||
.nth(1) | ||
.expect("Please pass the device id as the first parameter"); | ||
|
||
println!("Getting device twin for device '{}'", device_id); | ||
|
||
let service_client = ServiceClient::from_connection_string(iothub_connection_string, 3600)?; | ||
let device = service_client | ||
.create_device_identity() | ||
.device_id(device_id) | ||
.authentication_using_sas( | ||
"QhgevIUBSWe37q1MP+M/vtktjOcrE74BVbpcxlLQw58=", | ||
"6YS6w5wqkpdfkEW7iOP1NvituehFlFRfPko2n7KY4Gk=", | ||
) | ||
.status(Status::Enabled) | ||
.execute() | ||
.await?; | ||
|
||
println!("Successfully created a new device '{}'", device.device_id); | ||
|
||
println!( | ||
"Setting status to disabled and set IoT Edge capability of device '{}'", | ||
device.device_id | ||
); | ||
let device = service_client | ||
.update_device_identity(device.etag) | ||
.device_id(device.device_id) | ||
.device_capability(DesiredCapability::IotEdge) | ||
.authentication_using_sas( | ||
"QhgevIUBSWe37q1MP+M/vtktjOcrE74BVbpcxlLQw58=", | ||
"6YS6w5wqkpdfkEW7iOP1NvituehFlFRfPko2n7KY4Gk=", | ||
) | ||
.status(Status::Disabled) | ||
.execute() | ||
.await?; | ||
|
||
println!("Getting device identity of '{}'", device.device_id); | ||
let device = service_client.get_device_identity(device.device_id).await?; | ||
println!("Identity is: {:?}", device); | ||
|
||
println!("Deleting device '{}'", device.device_id); | ||
service_client | ||
.delete_device_identity(device.device_id, None) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.