use serde_json::Value;
use super::VtaClient;
use crate::error::VtaError;
use crate::protocols::consent_management::{
ConsentApproverListBody, ConsentApproverSetBody, ConsentDecisionBody, ConsentListBody,
ConsentRequestBody, ConsentRevokeBody,
};
use crate::trust_tasks;
const CONSENT_TT_TIMEOUT: u64 = 30;
impl VtaClient {
pub async fn consent_request(
&self,
subject: Value,
scope: &str,
challenge: &str,
display_hint: Option<&str>,
context_hint: Option<&str>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(ConsentRequestBody {
subject,
scope: scope.to_string(),
challenge: challenge.to_string(),
display_hint: display_hint.map(str::to_string),
context_hint: context_hint.map(str::to_string),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_CONSENT_REQUEST_1_0,
payload,
CONSENT_TT_TIMEOUT,
)
.await
}
pub async fn consent_decision(
&self,
subject: Value,
effect: &str,
scope: Option<&str>,
challenge: Option<&str>,
expires_at: Option<&str>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(ConsentDecisionBody {
subject,
effect: effect.to_string(),
scope: scope.map(str::to_string),
challenge: challenge.map(str::to_string),
expires_at: expires_at.map(str::to_string),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_CONSENT_DECISION_1_0,
payload,
CONSENT_TT_TIMEOUT,
)
.await
}
pub async fn consent_revoke(
&self,
subject: Value,
reason: Option<&str>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(ConsentRevokeBody {
subject,
reason: reason.map(str::to_string),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_CONSENT_REVOKE_1_0,
payload,
CONSENT_TT_TIMEOUT,
)
.await
}
pub async fn consent_list(
&self,
agent: Option<&str>,
platform: Option<&str>,
subject: Option<Value>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(ConsentListBody {
agent: agent.map(str::to_string),
platform: platform.map(str::to_string),
subject,
})?;
self.dispatch_trust_task(
trust_tasks::TASK_CONSENT_LIST_1_0,
payload,
CONSENT_TT_TIMEOUT,
)
.await
}
pub async fn consent_approver_set(
&self,
platform: &str,
context: &str,
approver: &str,
route: Option<&str>,
route_hint: Option<&str>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(ConsentApproverSetBody {
platform: platform.to_string(),
context: context.to_string(),
approver: approver.to_string(),
route: route.map(str::to_string),
route_hint: route_hint.map(str::to_string),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_CONSENT_APPROVER_SET_1_0,
payload,
CONSENT_TT_TIMEOUT,
)
.await
}
pub async fn consent_approver_list(
&self,
platform: Option<&str>,
context: Option<&str>,
) -> Result<Value, VtaError> {
let payload = serde_json::to_value(ConsentApproverListBody {
platform: platform.map(str::to_string),
context: context.map(str::to_string),
})?;
self.dispatch_trust_task(
trust_tasks::TASK_CONSENT_APPROVER_LIST_1_0,
payload,
CONSENT_TT_TIMEOUT,
)
.await
}
}