1pub mod topic;
2pub mod spu;
3pub mod customspu;
4pub mod spg;
5pub mod smartmodule;
6pub mod partition;
7pub mod versions;
8pub mod objects;
9pub mod shared;
10pub mod tableformat;
11pub mod mirror;
12pub mod mirroring;
13
14pub mod remote_file;
15
16mod apis;
17mod request;
18mod response;
19
20pub use apis::AdminPublicApiKey;
21pub use request::*;
22pub use response::*;
23pub use admin::*;
24
25pub mod errors {
26 pub use fluvio_protocol::link::ErrorCode;
27}
28
29pub use fluvio_controlplane_metadata::core;
30pub use fluvio_controlplane_metadata::store;
31pub use fluvio_controlplane_metadata::message;
32pub use error::ApiError;
33mod error {
34
35 use std::fmt::Display;
36 use std::fmt::Formatter;
37
38 use super::errors::ErrorCode;
39
40 #[derive(thiserror::Error, Debug)]
42 pub enum ApiError {
43 Code(crate::errors::ErrorCode, Option<String>),
44 NoResourceFound(String),
45 }
46
47 impl Display for ApiError {
48 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49 match self {
50 ApiError::Code(ErrorCode::TopicAlreadyExists, _) => {
51 write!(f, "Topic already exists")
52 }
53 ApiError::Code(ErrorCode::ManagedConnectorAlreadyExists, _) => {
54 write!(f, "Connector already exists")
55 }
56 ApiError::Code(ErrorCode::TopicNotFound, _) => {
57 write!(f, "Topic not found")
58 }
59 ApiError::Code(ErrorCode::MirrorNotFound, _) => {
60 write!(f, "Mirror not found")
61 }
62 ApiError::Code(ErrorCode::SmartModuleNotFound { name: _ }, _) => {
63 write!(f, "SmartModule not found")
64 }
65 ApiError::Code(ErrorCode::ManagedConnectorNotFound, _) => {
66 write!(f, "Connector not found")
67 }
68 ApiError::Code(ErrorCode::TopicInvalidName, _) => {
69 write!(
70 f,
71 "Invalid topic name: topic name may only include lowercase letters (a-z), numbers (0-9), and hyphens (-)."
72 )
73 }
74 ApiError::Code(ErrorCode::TableFormatAlreadyExists, _) => {
75 write!(f, "TableFormat already exists")
76 }
77 ApiError::Code(ErrorCode::TableFormatNotFound, _) => {
78 write!(f, "TableFormat not found")
79 }
80 ApiError::Code(_, Some(msg)) => {
81 write!(f, "{msg}")
82 }
83 ApiError::Code(code, None) => {
84 write!(f, "{code}")
85 }
86 ApiError::NoResourceFound(name) => {
87 write!(f, "No resource found: {name}")
88 }
89 }
90 }
91 }
92}
93
94mod admin {
95
96 use std::fmt::Debug;
97
98 use anyhow::Result;
99
100 use fluvio_protocol::{Encoder, Decoder, Version};
101 use fluvio_controlplane_metadata::store::MetadataStoreObject;
102
103 use crate::objects::Metadata;
104 use crate::objects::classic::ClassicCreatableAdminSpec;
105
106 use super::core::Spec;
107
108 pub trait AdminSpec: Spec + Encoder + Decoder {
110 fn convert_from<C: fluvio_controlplane_metadata::core::MetadataItem>(
112 obj: &fluvio_controlplane_metadata::store::MetadataStoreObject<Self, C>,
113 ) -> Metadata<Self>
114 where
115 Metadata<Self>: From<MetadataStoreObject<Self, C>>,
116 Self::Status: Encoder + Decoder + Debug,
117 {
118 obj.clone().into()
119 }
120
121 fn summary(self) -> Self {
123 self
124 }
125 }
126
127 pub trait CreatableAdminSpec: ClassicCreatableAdminSpec + Spec + Encoder + Decoder {}
129
130 pub trait DeletableAdminSpec: Spec + Encoder + Decoder {
131 type DeleteKey: Encoder + Decoder + Debug + Default;
132 }
133
134 pub trait UpdatableAdminSpec: Spec + Encoder + Decoder {
135 type UpdateKey: Encoder + Decoder + Debug + Default;
136 type UpdateAction: Encoder + Decoder + Debug + Default + Clone;
137 }
138
139 pub trait TryEncodableFrom<T>: Sized + Encoder + Decoder {
141 fn try_encode_from(value: T, version: Version) -> Result<Self>;
142
143 fn downcast(&self) -> Result<Option<T>>;
144 }
145}