systemprompt_models/a2a/
security.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
5#[serde(tag = "type", rename_all = "camelCase")]
6pub enum SecurityScheme {
7    #[serde(rename = "apiKey")]
8    ApiKey {
9        name: String,
10        #[serde(rename = "in")]
11        location: ApiKeyLocation,
12        description: Option<String>,
13    },
14    #[serde(rename = "http")]
15    Http {
16        scheme: String,
17        bearer_format: Option<String>,
18        description: Option<String>,
19    },
20    #[serde(rename = "oauth2")]
21    OAuth2 {
22        flows: Box<OAuth2Flows>,
23        description: Option<String>,
24    },
25    #[serde(rename = "openIdConnect")]
26    OpenIdConnect {
27        open_id_connect_url: String,
28        description: Option<String>,
29    },
30    #[serde(rename = "mutualTLS")]
31    MutualTls { description: Option<String> },
32}
33
34#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
35#[serde(rename_all = "camelCase")]
36pub enum ApiKeyLocation {
37    Query,
38    Header,
39    Cookie,
40}
41
42impl std::fmt::Display for ApiKeyLocation {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        match self {
45            Self::Query => write!(f, "query"),
46            Self::Header => write!(f, "header"),
47            Self::Cookie => write!(f, "cookie"),
48        }
49    }
50}
51
52impl std::str::FromStr for ApiKeyLocation {
53    type Err = String;
54
55    fn from_str(s: &str) -> Result<Self, Self::Err> {
56        match s {
57            "query" => Ok(Self::Query),
58            "header" => Ok(Self::Header),
59            "cookie" => Ok(Self::Cookie),
60            _ => Err(format!("Invalid API key location: {s}")),
61        }
62    }
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
66#[serde(rename_all = "camelCase")]
67pub struct OAuth2Flows {
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub implicit: Option<OAuth2Flow>,
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub password: Option<OAuth2Flow>,
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub client_credentials: Option<OAuth2Flow>,
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub authorization_code: Option<OAuth2Flow>,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
79#[serde(rename_all = "camelCase")]
80pub struct OAuth2Flow {
81    pub authorization_url: Option<String>,
82    pub token_url: Option<String>,
83    pub refresh_url: Option<String>,
84    pub scopes: HashMap<String, String>,
85}
86
87pub type AgentAuthentication = serde_json::Value;