//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vault/usage`. Version: `0.2`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Consumer queries the maintainer's audit log of recent vault uses (proxy-logins, releases). Drives UIs like "recent activity" and "which AI agent has been using my GitHub credential". Read-only.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/vault/usage/0.2",
/// "title": "Payload",
/// "description": "Consumer queries the maintainer's audit log of recent vault uses (proxy-logins, releases). Drives UIs like \"recent activity\" and \"which AI agent has been using my GitHub credential\". Read-only.",
/// "type": "object",
/// "properties": {
/// "byConsumer": {
/// "description": "Optional filter — usage by this consumer DID only. Useful for \"what has AI agent X been doing on my behalf\".",
/// "type": "string",
/// "minLength": 1
/// },
/// "contextId": {
/// "description": "Optional filter — usage within this trust context only.",
/// "type": "string",
/// "minLength": 1
/// },
/// "cursor": {
/// "type": "string"
/// },
/// "entryId": {
/// "description": "Optional filter — usage for this entry only.",
/// "type": "string",
/// "minLength": 1
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "kindFilter": {
/// "type": "array",
/// "items": {
/// "type": "string",
/// "enum": [
/// "proxyLogin",
/// "release"
/// ]
/// },
/// "uniqueItems": true
/// },
/// "pageSize": {
/// "type": "integer",
/// "maximum": 1000.0,
/// "minimum": 1.0
/// },
/// "since": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "until": {
/// "type": "string",
/// "format": "date-time"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Optional filter — usage by this consumer DID only. Useful for "what has AI agent X been doing on my behalf".
#[serde(
rename = "byConsumer",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub by_consumer: ::std::option::Option<PayloadByConsumer>,
///Optional filter — usage within this trust context only.
#[serde(
rename = "contextId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub context_id: ::std::option::Option<PayloadContextId>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub cursor: ::std::option::Option<::std::string::String>,
///Optional filter — usage for this entry only.
#[serde(
rename = "entryId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub entry_id: ::std::option::Option<PayloadEntryId>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
#[serde(
rename = "kindFilter",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub kind_filter: ::std::option::Option<Vec<PayloadKindFilterItem>>,
#[serde(
rename = "pageSize",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub page_size: ::std::option::Option<::std::num::NonZeroU64>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub since: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub until: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
by_consumer: Default::default(),
context_id: Default::default(),
cursor: Default::default(),
entry_id: Default::default(),
ext: Default::default(),
kind_filter: Default::default(),
page_size: Default::default(),
since: Default::default(),
until: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Optional filter — usage by this consumer DID only. Useful for "what has AI agent X been doing on my behalf".
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Optional filter — usage by this consumer DID only. Useful for \"what has AI agent X been doing on my behalf\".",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadByConsumer(::std::string::String);
impl ::std::ops::Deref for PayloadByConsumer {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadByConsumer> for ::std::string::String {
fn from(value: PayloadByConsumer) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadByConsumer {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadByConsumer {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadByConsumer {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadByConsumer {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadByConsumer {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Optional filter — usage within this trust context only.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Optional filter — usage within this trust context only.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadContextId(::std::string::String);
impl ::std::ops::Deref for PayloadContextId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadContextId> for ::std::string::String {
fn from(value: PayloadContextId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadContextId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadContextId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadContextId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadContextId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadContextId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Optional filter — usage for this entry only.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Optional filter — usage for this entry only.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadEntryId(::std::string::String);
impl ::std::ops::Deref for PayloadEntryId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadEntryId> for ::std::string::String {
fn from(value: PayloadEntryId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadEntryId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadEntryId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadEntryId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadEntryId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadEntryId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`PayloadKindFilterItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "enum": [
/// "proxyLogin",
/// "release"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum PayloadKindFilterItem {
#[serde(rename = "proxyLogin")]
ProxyLogin,
#[serde(rename = "release")]
Release,
}
impl ::std::fmt::Display for PayloadKindFilterItem {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::ProxyLogin => f.write_str("proxyLogin"),
Self::Release => f.write_str("release"),
}
}
}
impl ::std::str::FromStr for PayloadKindFilterItem {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"proxyLogin" => Ok(Self::ProxyLogin),
"release" => Ok(Self::Release),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for PayloadKindFilterItem {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadKindFilterItem {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadKindFilterItem {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "truncated",
/// "uses"
/// ],
/// "properties": {
/// "cursor": {
/// "type": "string"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "truncated": {
/// "type": "boolean"
/// },
/// "uses": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/UsageRecord"
/// }
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub cursor: ::std::option::Option<::std::string::String>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
pub truncated: bool,
pub uses: ::std::vec::Vec<UsageRecord>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`UsageRecord`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "UsageRecord",
/// "type": "object",
/// "required": [
/// "consumerDid",
/// "contextId",
/// "entryId",
/// "id",
/// "kind",
/// "occurredAt",
/// "outcome"
/// ],
/// "properties": {
/// "consumerDid": {
/// "description": "DID of the Companion/Service that initiated the use.",
/// "type": "string",
/// "minLength": 1
/// },
/// "contextId": {
/// "type": "string",
/// "minLength": 1
/// },
/// "deviceId": {
/// "type": "string",
/// "minLength": 1
/// },
/// "entryId": {
/// "type": "string",
/// "minLength": 1
/// },
/// "errorCode": {
/// "description": "Trust Task error code when outcome is a failure.",
/// "type": "string"
/// },
/// "id": {
/// "type": "string",
/// "minLength": 1
/// },
/// "kind": {
/// "type": "string",
/// "enum": [
/// "proxyLogin",
/// "release"
/// ]
/// },
/// "occurredAt": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "outcome": {
/// "type": "string",
/// "enum": [
/// "allowed",
/// "denied",
/// "stepUpRequired",
/// "stepUpSatisfied",
/// "targetUnreachable",
/// "credentialRejected",
/// "policyDeny"
/// ]
/// },
/// "policyDecisionId": {
/// "description": "Pointer to the policy evaluation record for forensic detail.",
/// "type": "string"
/// },
/// "sessionId": {
/// "description": "For successful proxy-logins, the maintainer-assigned session id; absent for releases and for failures.",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct UsageRecord {
///DID of the Companion/Service that initiated the use.
#[serde(rename = "consumerDid")]
pub consumer_did: UsageRecordConsumerDid,
#[serde(rename = "contextId")]
pub context_id: UsageRecordContextId,
#[serde(
rename = "deviceId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub device_id: ::std::option::Option<UsageRecordDeviceId>,
#[serde(rename = "entryId")]
pub entry_id: UsageRecordEntryId,
///Trust Task error code when outcome is a failure.
#[serde(
rename = "errorCode",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub error_code: ::std::option::Option<::std::string::String>,
pub id: UsageRecordId,
pub kind: UsageRecordKind,
#[serde(rename = "occurredAt")]
pub occurred_at: ::chrono::DateTime<::chrono::offset::Utc>,
pub outcome: UsageRecordOutcome,
///Pointer to the policy evaluation record for forensic detail.
#[serde(
rename = "policyDecisionId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub policy_decision_id: ::std::option::Option<::std::string::String>,
///For successful proxy-logins, the maintainer-assigned session id; absent for releases and for failures.
#[serde(
rename = "sessionId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub session_id: ::std::option::Option<UsageRecordSessionId>,
}
impl UsageRecord {
pub fn builder() -> builder::UsageRecord {
Default::default()
}
}
///DID of the Companion/Service that initiated the use.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "DID of the Companion/Service that initiated the use.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct UsageRecordConsumerDid(::std::string::String);
impl ::std::ops::Deref for UsageRecordConsumerDid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<UsageRecordConsumerDid> for ::std::string::String {
fn from(value: UsageRecordConsumerDid) -> Self {
value.0
}
}
impl ::std::str::FromStr for UsageRecordConsumerDid {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordConsumerDid {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordConsumerDid {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordConsumerDid {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for UsageRecordConsumerDid {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`UsageRecordContextId`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct UsageRecordContextId(::std::string::String);
impl ::std::ops::Deref for UsageRecordContextId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<UsageRecordContextId> for ::std::string::String {
fn from(value: UsageRecordContextId) -> Self {
value.0
}
}
impl ::std::str::FromStr for UsageRecordContextId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordContextId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordContextId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordContextId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for UsageRecordContextId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`UsageRecordDeviceId`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct UsageRecordDeviceId(::std::string::String);
impl ::std::ops::Deref for UsageRecordDeviceId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<UsageRecordDeviceId> for ::std::string::String {
fn from(value: UsageRecordDeviceId) -> Self {
value.0
}
}
impl ::std::str::FromStr for UsageRecordDeviceId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordDeviceId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordDeviceId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordDeviceId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for UsageRecordDeviceId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`UsageRecordEntryId`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct UsageRecordEntryId(::std::string::String);
impl ::std::ops::Deref for UsageRecordEntryId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<UsageRecordEntryId> for ::std::string::String {
fn from(value: UsageRecordEntryId) -> Self {
value.0
}
}
impl ::std::str::FromStr for UsageRecordEntryId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordEntryId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordEntryId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordEntryId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for UsageRecordEntryId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`UsageRecordId`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct UsageRecordId(::std::string::String);
impl ::std::ops::Deref for UsageRecordId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<UsageRecordId> for ::std::string::String {
fn from(value: UsageRecordId) -> Self {
value.0
}
}
impl ::std::str::FromStr for UsageRecordId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for UsageRecordId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`UsageRecordKind`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "enum": [
/// "proxyLogin",
/// "release"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum UsageRecordKind {
#[serde(rename = "proxyLogin")]
ProxyLogin,
#[serde(rename = "release")]
Release,
}
impl ::std::fmt::Display for UsageRecordKind {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::ProxyLogin => f.write_str("proxyLogin"),
Self::Release => f.write_str("release"),
}
}
}
impl ::std::str::FromStr for UsageRecordKind {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"proxyLogin" => Ok(Self::ProxyLogin),
"release" => Ok(Self::Release),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordKind {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordKind {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordKind {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///`UsageRecordOutcome`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "enum": [
/// "allowed",
/// "denied",
/// "stepUpRequired",
/// "stepUpSatisfied",
/// "targetUnreachable",
/// "credentialRejected",
/// "policyDeny"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum UsageRecordOutcome {
#[serde(rename = "allowed")]
Allowed,
#[serde(rename = "denied")]
Denied,
#[serde(rename = "stepUpRequired")]
StepUpRequired,
#[serde(rename = "stepUpSatisfied")]
StepUpSatisfied,
#[serde(rename = "targetUnreachable")]
TargetUnreachable,
#[serde(rename = "credentialRejected")]
CredentialRejected,
#[serde(rename = "policyDeny")]
PolicyDeny,
}
impl ::std::fmt::Display for UsageRecordOutcome {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Allowed => f.write_str("allowed"),
Self::Denied => f.write_str("denied"),
Self::StepUpRequired => f.write_str("stepUpRequired"),
Self::StepUpSatisfied => f.write_str("stepUpSatisfied"),
Self::TargetUnreachable => f.write_str("targetUnreachable"),
Self::CredentialRejected => f.write_str("credentialRejected"),
Self::PolicyDeny => f.write_str("policyDeny"),
}
}
}
impl ::std::str::FromStr for UsageRecordOutcome {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"allowed" => Ok(Self::Allowed),
"denied" => Ok(Self::Denied),
"stepUpRequired" => Ok(Self::StepUpRequired),
"stepUpSatisfied" => Ok(Self::StepUpSatisfied),
"targetUnreachable" => Ok(Self::TargetUnreachable),
"credentialRejected" => Ok(Self::CredentialRejected),
"policyDeny" => Ok(Self::PolicyDeny),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordOutcome {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordOutcome {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordOutcome {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///For successful proxy-logins, the maintainer-assigned session id; absent for releases and for failures.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "For successful proxy-logins, the maintainer-assigned session id; absent for releases and for failures.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct UsageRecordSessionId(::std::string::String);
impl ::std::ops::Deref for UsageRecordSessionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<UsageRecordSessionId> for ::std::string::String {
fn from(value: UsageRecordSessionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for UsageRecordSessionId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for UsageRecordSessionId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for UsageRecordSessionId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for UsageRecordSessionId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for UsageRecordSessionId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
by_consumer: ::std::result::Result<
::std::option::Option<super::PayloadByConsumer>,
::std::string::String,
>,
context_id: ::std::result::Result<
::std::option::Option<super::PayloadContextId>,
::std::string::String,
>,
cursor: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
entry_id: ::std::result::Result<
::std::option::Option<super::PayloadEntryId>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
kind_filter: ::std::result::Result<
::std::option::Option<Vec<super::PayloadKindFilterItem>>,
::std::string::String,
>,
page_size: ::std::result::Result<
::std::option::Option<::std::num::NonZeroU64>,
::std::string::String,
>,
since: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
until: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
by_consumer: Ok(Default::default()),
context_id: Ok(Default::default()),
cursor: Ok(Default::default()),
entry_id: Ok(Default::default()),
ext: Ok(Default::default()),
kind_filter: Ok(Default::default()),
page_size: Ok(Default::default()),
since: Ok(Default::default()),
until: Ok(Default::default()),
}
}
}
impl Payload {
pub fn by_consumer<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadByConsumer>>,
T::Error: ::std::fmt::Display,
{
self.by_consumer = value
.try_into()
.map_err(|e| format!("error converting supplied value for by_consumer: {e}"));
self
}
pub fn context_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadContextId>>,
T::Error: ::std::fmt::Display,
{
self.context_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for context_id: {e}"));
self
}
pub fn cursor<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.cursor = value
.try_into()
.map_err(|e| format!("error converting supplied value for cursor: {e}"));
self
}
pub fn entry_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadEntryId>>,
T::Error: ::std::fmt::Display,
{
self.entry_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for entry_id: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn kind_filter<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::PayloadKindFilterItem>>>,
T::Error: ::std::fmt::Display,
{
self.kind_filter = value
.try_into()
.map_err(|e| format!("error converting supplied value for kind_filter: {e}"));
self
}
pub fn page_size<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::num::NonZeroU64>>,
T::Error: ::std::fmt::Display,
{
self.page_size = value
.try_into()
.map_err(|e| format!("error converting supplied value for page_size: {e}"));
self
}
pub fn since<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.since = value
.try_into()
.map_err(|e| format!("error converting supplied value for since: {e}"));
self
}
pub fn until<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.until = value
.try_into()
.map_err(|e| format!("error converting supplied value for until: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
by_consumer: value.by_consumer?,
context_id: value.context_id?,
cursor: value.cursor?,
entry_id: value.entry_id?,
ext: value.ext?,
kind_filter: value.kind_filter?,
page_size: value.page_size?,
since: value.since?,
until: value.until?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
by_consumer: Ok(value.by_consumer),
context_id: Ok(value.context_id),
cursor: Ok(value.cursor),
entry_id: Ok(value.entry_id),
ext: Ok(value.ext),
kind_filter: Ok(value.kind_filter),
page_size: Ok(value.page_size),
since: Ok(value.since),
until: Ok(value.until),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
cursor: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
truncated: ::std::result::Result<bool, ::std::string::String>,
uses: ::std::result::Result<::std::vec::Vec<super::UsageRecord>, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
cursor: Ok(Default::default()),
ext: Ok(Default::default()),
truncated: Err("no value supplied for truncated".to_string()),
uses: Err("no value supplied for uses".to_string()),
}
}
}
impl Response {
pub fn cursor<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.cursor = value
.try_into()
.map_err(|e| format!("error converting supplied value for cursor: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn truncated<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.truncated = value
.try_into()
.map_err(|e| format!("error converting supplied value for truncated: {e}"));
self
}
pub fn uses<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::UsageRecord>>,
T::Error: ::std::fmt::Display,
{
self.uses = value
.try_into()
.map_err(|e| format!("error converting supplied value for uses: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
cursor: value.cursor?,
ext: value.ext?,
truncated: value.truncated?,
uses: value.uses?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
cursor: Ok(value.cursor),
ext: Ok(value.ext),
truncated: Ok(value.truncated),
uses: Ok(value.uses),
}
}
}
#[derive(Clone, Debug)]
pub struct UsageRecord {
consumer_did: ::std::result::Result<super::UsageRecordConsumerDid, ::std::string::String>,
context_id: ::std::result::Result<super::UsageRecordContextId, ::std::string::String>,
device_id: ::std::result::Result<
::std::option::Option<super::UsageRecordDeviceId>,
::std::string::String,
>,
entry_id: ::std::result::Result<super::UsageRecordEntryId, ::std::string::String>,
error_code: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
id: ::std::result::Result<super::UsageRecordId, ::std::string::String>,
kind: ::std::result::Result<super::UsageRecordKind, ::std::string::String>,
occurred_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
outcome: ::std::result::Result<super::UsageRecordOutcome, ::std::string::String>,
policy_decision_id: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
session_id: ::std::result::Result<
::std::option::Option<super::UsageRecordSessionId>,
::std::string::String,
>,
}
impl ::std::default::Default for UsageRecord {
fn default() -> Self {
Self {
consumer_did: Err("no value supplied for consumer_did".to_string()),
context_id: Err("no value supplied for context_id".to_string()),
device_id: Ok(Default::default()),
entry_id: Err("no value supplied for entry_id".to_string()),
error_code: Ok(Default::default()),
id: Err("no value supplied for id".to_string()),
kind: Err("no value supplied for kind".to_string()),
occurred_at: Err("no value supplied for occurred_at".to_string()),
outcome: Err("no value supplied for outcome".to_string()),
policy_decision_id: Ok(Default::default()),
session_id: Ok(Default::default()),
}
}
}
impl UsageRecord {
pub fn consumer_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::UsageRecordConsumerDid>,
T::Error: ::std::fmt::Display,
{
self.consumer_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for consumer_did: {e}"));
self
}
pub fn context_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::UsageRecordContextId>,
T::Error: ::std::fmt::Display,
{
self.context_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for context_id: {e}"));
self
}
pub fn device_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::UsageRecordDeviceId>>,
T::Error: ::std::fmt::Display,
{
self.device_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for device_id: {e}"));
self
}
pub fn entry_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::UsageRecordEntryId>,
T::Error: ::std::fmt::Display,
{
self.entry_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for entry_id: {e}"));
self
}
pub fn error_code<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.error_code = value
.try_into()
.map_err(|e| format!("error converting supplied value for error_code: {e}"));
self
}
pub fn id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::UsageRecordId>,
T::Error: ::std::fmt::Display,
{
self.id = value
.try_into()
.map_err(|e| format!("error converting supplied value for id: {e}"));
self
}
pub fn kind<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::UsageRecordKind>,
T::Error: ::std::fmt::Display,
{
self.kind = value
.try_into()
.map_err(|e| format!("error converting supplied value for kind: {e}"));
self
}
pub fn occurred_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.occurred_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for occurred_at: {e}"));
self
}
pub fn outcome<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::UsageRecordOutcome>,
T::Error: ::std::fmt::Display,
{
self.outcome = value
.try_into()
.map_err(|e| format!("error converting supplied value for outcome: {e}"));
self
}
pub fn policy_decision_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.policy_decision_id = value.try_into().map_err(|e| {
format!("error converting supplied value for policy_decision_id: {e}")
});
self
}
pub fn session_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::UsageRecordSessionId>>,
T::Error: ::std::fmt::Display,
{
self.session_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for session_id: {e}"));
self
}
}
impl ::std::convert::TryFrom<UsageRecord> for super::UsageRecord {
type Error = super::error::ConversionError;
fn try_from(
value: UsageRecord,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
consumer_did: value.consumer_did?,
context_id: value.context_id?,
device_id: value.device_id?,
entry_id: value.entry_id?,
error_code: value.error_code?,
id: value.id?,
kind: value.kind?,
occurred_at: value.occurred_at?,
outcome: value.outcome?,
policy_decision_id: value.policy_decision_id?,
session_id: value.session_id?,
})
}
}
impl ::std::convert::From<super::UsageRecord> for UsageRecord {
fn from(value: super::UsageRecord) -> Self {
Self {
consumer_did: Ok(value.consumer_did),
context_id: Ok(value.context_id),
device_id: Ok(value.device_id),
entry_id: Ok(value.entry_id),
error_code: Ok(value.error_code),
id: Ok(value.id),
kind: Ok(value.kind),
occurred_at: Ok(value.occurred_at),
outcome: Ok(value.outcome),
policy_decision_id: Ok(value.policy_decision_id),
session_id: Ok(value.session_id),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vault/usage/0.2";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"cursor\": {\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"truncated\": {\n \"type\": \"boolean\"\n },\n \"uses\": {\n \"items\": {\n \"$ref\": \"#/$defs/UsageRecord\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"uses\",\n \"truncated\"\n ],\n \"title\": \"Vault Usage — response payload\",\n \"type\": \"object\"\n },\n \"UsageRecord\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"consumerDid\": {\n \"description\": \"DID of the Companion/Service that initiated the use.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"contextId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"deviceId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"entryId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"errorCode\": {\n \"description\": \"Trust Task error code when outcome is a failure.\",\n \"type\": \"string\"\n },\n \"id\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"kind\": {\n \"enum\": [\n \"proxyLogin\",\n \"release\"\n ],\n \"type\": \"string\"\n },\n \"occurredAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"outcome\": {\n \"enum\": [\n \"allowed\",\n \"denied\",\n \"stepUpRequired\",\n \"stepUpSatisfied\",\n \"targetUnreachable\",\n \"credentialRejected\",\n \"policyDeny\"\n ],\n \"type\": \"string\"\n },\n \"policyDecisionId\": {\n \"description\": \"Pointer to the policy evaluation record for forensic detail.\",\n \"type\": \"string\"\n },\n \"sessionId\": {\n \"description\": \"For successful proxy-logins, the maintainer-assigned session id; absent for releases and for failures.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\",\n \"entryId\",\n \"contextId\",\n \"consumerDid\",\n \"kind\",\n \"outcome\",\n \"occurredAt\"\n ],\n \"title\": \"UsageRecord\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vault/usage/0.2\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Consumer queries the maintainer's audit log of recent vault uses (proxy-logins, releases). Drives UIs like \\\"recent activity\\\" and \\\"which AI agent has been using my GitHub credential\\\". Read-only.\",\n \"properties\": {\n \"byConsumer\": {\n \"description\": \"Optional filter — usage by this consumer DID only. Useful for \\\"what has AI agent X been doing on my behalf\\\".\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"contextId\": {\n \"description\": \"Optional filter — usage within this trust context only.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"cursor\": {\n \"type\": \"string\"\n },\n \"entryId\": {\n \"description\": \"Optional filter — usage for this entry only.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"kindFilter\": {\n \"items\": {\n \"enum\": [\n \"proxyLogin\",\n \"release\"\n ],\n \"type\": \"string\"\n },\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"pageSize\": {\n \"maximum\": 1000,\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"since\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"until\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"title\": \"Vault Usage — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vault/usage/0.2#response";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"cursor\": {\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"truncated\": {\n \"type\": \"boolean\"\n },\n \"uses\": {\n \"items\": {\n \"$ref\": \"#/$defs/UsageRecord\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"uses\",\n \"truncated\"\n ],\n \"title\": \"Vault Usage — response payload\",\n \"type\": \"object\"\n },\n \"UsageRecord\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"consumerDid\": {\n \"description\": \"DID of the Companion/Service that initiated the use.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"contextId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"deviceId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"entryId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"errorCode\": {\n \"description\": \"Trust Task error code when outcome is a failure.\",\n \"type\": \"string\"\n },\n \"id\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"kind\": {\n \"enum\": [\n \"proxyLogin\",\n \"release\"\n ],\n \"type\": \"string\"\n },\n \"occurredAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"outcome\": {\n \"enum\": [\n \"allowed\",\n \"denied\",\n \"stepUpRequired\",\n \"stepUpSatisfied\",\n \"targetUnreachable\",\n \"credentialRejected\",\n \"policyDeny\"\n ],\n \"type\": \"string\"\n },\n \"policyDecisionId\": {\n \"description\": \"Pointer to the policy evaluation record for forensic detail.\",\n \"type\": \"string\"\n },\n \"sessionId\": {\n \"description\": \"For successful proxy-logins, the maintainer-assigned session id; absent for releases and for failures.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\",\n \"entryId\",\n \"contextId\",\n \"consumerDid\",\n \"kind\",\n \"outcome\",\n \"occurredAt\"\n ],\n \"title\": \"UsageRecord\",\n \"type\": \"object\"\n }\n },\n \"$ref\": \"#/$defs/Response\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
#[cfg(test)]
mod conformance {
//! Round-trip tests harvested from the spec's `spec.md`,
//! plus a `rejects_invalid_examples` test for any fixtures
//! in `payload.invalid-examples.json` (validate feature).
/// Each fixture in `payload.invalid-examples.json` MUST be
/// rejected by at least one of: serde deserialization, or
/// JSON-Schema validation under the `validate` feature. The
/// fixture file documents the producer-side bug class that
/// each payload exemplifies; this generated test pins it.
#[cfg(feature = "validate")]
#[test]
fn rejects_invalid_examples() {
use crate::validate::ValidatedPayload;
let fixtures: &[(&str, &str)] = &[(
"Unknown top-level member is rejected (additionalProperties: false).",
"{\n \"__notARealMember__\": true\n}",
)];
for (i, (note, raw)) in fixtures.iter().enumerate() {
let value: serde_json::Value = match serde_json::from_str(raw) {
Ok(v) => v,
Err(_) => continue,
};
let serde_ok = serde_json::from_value::<super::Payload>(value.clone()).is_ok();
let schema_ok = super::Payload::validate_value(&value).is_ok();
assert!(
!(serde_ok && schema_ok),
"invalid-example #{} ({:?}) was accepted by both serde and JSON Schema; \
the fixture's stated failure class is no longer caught:\n{}",
i + 1,
note,
raw
);
}
}
}