Skip to main content

gproxy_channel_api/
metadata.rs

1//! Self-description used by the Admin API and generic Console forms.
2
3use serde::{Deserialize, Serialize};
4use serde_json::{Value, json};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum CredentialFamily {
9    ApiKey,
10    OauthTokens,
11    ServiceAccount,
12    GithubToken,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
16#[serde(rename_all = "snake_case")]
17pub enum LoginMode {
18    Authcode,
19    Device,
20    Cookie,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(rename_all = "snake_case")]
25pub enum SettingControl {
26    Text,
27    Url,
28    Boolean,
29    Integer,
30    StringList,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct ChannelSettingField {
35    pub key: String,
36    pub control: SettingControl,
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub label: Option<String>,
39    #[serde(default)]
40    pub required: bool,
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub default: Option<Value>,
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub placeholder: Option<String>,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct ChannelMetadata {
49    pub id: String,
50    pub display_name: String,
51    pub credential_family: CredentialFamily,
52    pub login_modes: Vec<LoginMode>,
53    pub settings_fields: Vec<ChannelSettingField>,
54    pub secret_template: Value,
55    pub endpoint_kinds: Vec<String>,
56    pub usage: bool,
57}
58
59impl ChannelMetadata {
60    pub fn new(id: impl Into<String>) -> Self {
61        let id = id.into();
62        Self {
63            display_name: id.clone(),
64            id,
65            credential_family: CredentialFamily::ApiKey,
66            login_modes: Vec::new(),
67            settings_fields: Vec::new(),
68            secret_template: json!({ "api_key": "" }),
69            endpoint_kinds: Vec::new(),
70            usage: false,
71        }
72    }
73}
74
75#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
76#[serde(rename_all = "snake_case")]
77pub enum ChannelSource {
78    Builtin,
79    External,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct ChannelCatalogEntry {
84    pub source: ChannelSource,
85    #[serde(flatten)]
86    pub metadata: ChannelMetadata,
87}