casdoor_rust_sdk/
syncer.rs1use serde::{Deserialize, Serialize};
16
17use crate::client::{get_owner, Client, Response};
18use crate::error::Result;
19use crate::serde_util::null_to_default;
20
21#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase", default)]
23pub struct TableColumn {
24 pub name: String,
25 pub r#type: String,
26 pub casdoor_name: String,
27 pub is_key: bool,
28 pub is_hashed: bool,
29 #[serde(deserialize_with = "null_to_default")]
30 pub values: Vec<String>,
31}
32
33#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase", default)]
37pub struct Syncer {
38 pub owner: String,
39 pub name: String,
40 pub created_time: String,
41
42 pub organization: String,
43 pub r#type: String,
44 pub database_type: String,
45 pub ssl_mode: String,
46 pub ssh_type: String,
47
48 pub host: String,
49 pub port: i32,
50 pub user: String,
51 pub password: String,
52 pub ssh_host: String,
53 pub ssh_port: i32,
54 pub ssh_user: String,
55 pub ssh_password: String,
56 pub cert: String,
57 pub database: String,
58 pub table: String,
59 #[serde(deserialize_with = "null_to_default")]
60 pub table_columns: Vec<TableColumn>,
61 pub affiliation_table: String,
62 pub avatar_base_url: String,
63 pub error_text: String,
64 pub sync_interval: i32,
65 pub is_read_only: bool,
66 pub is_enabled: bool,
67}
68
69impl Client {
70 pub async fn get_syncers(&self) -> Result<Vec<Syncer>> {
72 self.get_list("get-syncers", &[("owner", &self.config.organization_name)])
73 .await
74 }
75
76 pub async fn get_pagination_syncers(
79 &self,
80 p: i32,
81 page_size: i32,
82 query: &[(&str, &str)],
83 ) -> Result<(Vec<Syncer>, i32)> {
84 self.get_pagination(
85 "get-syncers",
86 &self.config.organization_name,
87 p,
88 page_size,
89 query,
90 )
91 .await
92 }
93
94 pub async fn get_syncer(&self, name: &str) -> Result<Option<Syncer>> {
96 self.get_object("get-syncer", &[("id", &self.get_id(name))])
97 .await
98 }
99
100 pub async fn add_syncer(&self, syncer: &Syncer) -> Result<bool> {
102 Ok(self.modify_syncer("add-syncer", syncer, &[]).await?.1)
103 }
104
105 pub async fn update_syncer(&self, syncer: &Syncer) -> Result<bool> {
107 Ok(self.modify_syncer("update-syncer", syncer, &[]).await?.1)
108 }
109
110 pub async fn delete_syncer(&self, syncer: &Syncer) -> Result<bool> {
112 Ok(self.modify_syncer("delete-syncer", syncer, &[]).await?.1)
113 }
114
115 async fn modify_syncer(
116 &self,
117 action: &str,
118 syncer: &Syncer,
119 columns: &[&str],
120 ) -> Result<(Response, bool)> {
121 let mut syncer = syncer.clone();
122 syncer.owner = get_owner(&syncer.owner, &self.config.organization_name);
123
124 let id = format!("{}/{}", syncer.owner, syncer.name);
125 self.modify_object(action, &id, &syncer, columns).await
126 }
127}