Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Fix sas token #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.3] Q3 2022
- fixed SAS Token expired handling
- bump to azure-iot-sdk 0.8.3

## [0.4.2] Q3 2022
- bump to azure-iot-sdk 0.8.2

Expand All @@ -19,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- bump to azure-iot-sdk 0.8.1

## [0.3.1] Q2 2022
- fixed readme
- fixed readme

## [0.3.0] Q2 2022
- bump to azure-iot-sdk 0.8.0:
Expand All @@ -40,7 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- notify watchdog

## [0.2.1] Q1 2022
- add D2C messages
- add D2C messages

## [0.2.0] Q1 2022
- renamed package and repo to iot-module-template-rs
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iot-client-template-rs"
version = "0.4.2"
version = "0.4.3"
edition = "2021"
authors = ["Joerg Zeidler <joerg.zeidler@conplement.de>", "Jan Zachmann <jan.zachmann@conplement.de>"]
repository = "git@github.com:ICS-DeviceManagement/iot-client-template-rs.git"
Expand All @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
# use either device_client, module_client or edge_client
azure-iot-sdk = { git = "ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk.git", tag = "0.8.2", default-features = false }
azure-iot-sdk = { git = "ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk.git", tag = "0.8.3", default-features = false }
sd-notify = { git = "ssh://git@github.com/ICS-DeviceManagement/sd-notify.git", tag = "v0.5.0", optional = true }
serde_json = "1.0"
env_logger = "0.8"
Expand Down
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod systemd;
pub mod twin;
use azure_iot_sdk::client::*;
use client::{Client, Message};
use log::{debug, error};
use log::{info, debug, error};
use std::sync::{mpsc, Arc, Mutex};

#[tokio::main]
Expand All @@ -30,11 +30,17 @@ pub async fn run() -> Result<(), IotError> {
}
}
Message::Unauthenticated(reason) => {
client.stop().await.unwrap();
return Err(IotError::from(format!(
"No connection. Reason: {:?}",
reason
)));
if let UnauthenticatedReason::ExpiredSasToken = reason {
info!("SAS Token expired, SDK will try to refresh the token automatically");
}
else {
client.stop().await.unwrap();
return Err(IotError::from(format!(
"No connection. Reason: {:?}",
reason
)));
}

Comment on lines +33 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can better write the following code. We don't need another log since it is logged already in SDK code

                if !matches!(reason, UnauthenticatedReason::ExpiredSasToken) {
                    client.stop().await.unwrap();
                    return Err(IotError::from(format!(
                        "No connection. Reason: {:?}",
                        reason
                    )));
                }

}
Message::Desired(state, desired) => {
twin::update(state, desired, Arc::clone(&tx_app2client));
Expand Down