#![allow(deprecated)]
use serde_json::Value;
use super::VtaClient;
use crate::error::VtaError;
use crate::protocols::device_management::{
DeviceDisableBody, DeviceHeartbeatBody, DeviceRegisterBody, DeviceSetWakeBody, DeviceWipeBody,
WakeHandle,
};
use crate::trust_tasks;
const DEVICE_TT_TIMEOUT: u64 = 30;
impl VtaClient {
pub async fn device_register(
&self,
consumer_kind: Value,
display_name: &str,
platform: Option<&str>,
hpke_public_key: Option<&str>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(DeviceRegisterBody {
consumer_kind,
display_name: display_name.to_string(),
platform: platform.map(str::to_string),
hpke_public_key: hpke_public_key.map(str::to_string),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_REGISTER_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_heartbeat(&self, platform: Option<&str>) -> Result<Value, VtaError> {
let payload = serde_json::to_value(DeviceHeartbeatBody {
platform: platform.map(str::to_string),
vault_seq: None,
})?;
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_HEARTBEAT_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_list(&self, filters: Value) -> Result<Value, VtaError> {
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_LIST_0_1,
filters,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_disable(&self, device_id: &str) -> Result<Value, VtaError> {
let payload = serde_json::to_value(DeviceDisableBody {
device_id: device_id.to_string(),
reason: None,
})?;
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_DISABLE_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_wipe(
&self,
device_id: &str,
reason: &str,
scope: &str,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(DeviceWipeBody {
device_id: device_id.to_string(),
scope: scope.to_string(),
reason: reason.to_string(),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_WIPE_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_set_wake(
&self,
gateway: &str,
handle: &str,
suggested_triggers: Vec<String>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(DeviceSetWakeBody {
wake_handle: Some(WakeHandle {
gateway: gateway.to_string(),
handle: handle.to_string(),
}),
suggested_triggers: Some(suggested_triggers),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_SET_WAKE_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
}