1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright {{.Year}} Conductor OSS
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
use crate::error::Result;
use crate::http::{ApiClient, ApiPath};
use crate::models::SchemaDef;
/// Client for managing schema definitions.
#[derive(Clone)]
pub struct SchemaClient {
api: ApiClient,
}
impl SchemaClient {
/// Create a new schema client.
#[must_use]
pub fn new(api: ApiClient) -> Self {
Self { api }
}
/// Register a new schema.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn register_schema(&self, schema: &SchemaDef) -> Result<()> {
self.api.post_no_response("/schema", schema).await
}
/// Get a schema by name and version.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
pub async fn get_schema(&self, schema_name: &str, version: i32) -> Result<SchemaDef> {
let path = format!("/schema/{schema_name}");
self.api
.get_with_params(
ApiPath::templated(&path, "/schema/{schemaName}"),
&[("version", &version.to_string())],
)
.await
}
/// Get all schemas.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
pub async fn get_all_schemas(&self) -> Result<Vec<SchemaDef>> {
self.api.get("/schema").await
}
/// Delete a schema by name and version.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn delete_schema(&self, schema_name: &str, version: i32) -> Result<()> {
let path = format!("/schema/{schema_name}");
self.api
.delete_with_params(
ApiPath::templated(&path, "/schema/{schemaName}"),
&[("version", &version.to_string())],
)
.await
}
/// Delete all versions of a schema by name.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn delete_schema_by_name(&self, schema_name: &str) -> Result<()> {
let path = format!("/schema/{schema_name}/all");
self.api
.delete_no_content(ApiPath::templated(&path, "/schema/{schemaName}/all"))
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Configuration;
#[test]
fn test_schema_client_creation() {
let config = Configuration::new("http://localhost:8080/api");
let api = ApiClient::new(config).unwrap();
let _client = SchemaClient::new(api);
}
}