1use std::collections::BTreeSet;
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
8pub struct RepoId {
9 pub name: String,
11 pub root: PathBuf,
13}
14
15#[derive(Debug, Clone, Default)]
17pub struct RepoInventory {
18 pub repo: RepoId,
20 pub aliases: BTreeSet<String>,
22 pub api: Vec<ApiObservation>,
24 pub kafka: Vec<KafkaObservation>,
26 pub databases: Vec<DatabaseObservation>,
28}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
32pub enum ApiDirection {
33 Exposes,
35 Calls,
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
41pub enum ApiProtocol {
42 Http,
44 Grpc,
46 Graphql,
48}
49
50#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
52pub struct ApiObservation {
53 pub direction: ApiDirection,
55 pub protocol: ApiProtocol,
57 pub method: Option<String>,
59 pub resource: String,
61 pub host_hint: Option<String>,
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
67pub enum KafkaRole {
68 Producer,
70 Consumer,
72}
73
74#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
76pub struct KafkaObservation {
77 pub role: KafkaRole,
79 pub topic: String,
81 pub cluster: Option<String>,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
87pub enum DatabaseEngine {
88 Postgres,
90 Mongo,
92 Mysql,
94 Clickhouse,
96 SqlServer,
98 Sqlite,
100 Redis,
102 Vault,
104}
105
106impl DatabaseEngine {
107 #[must_use]
109 pub const fn label(self) -> &'static str {
110 match self {
111 Self::Postgres => "PostgreSQL",
112 Self::Mongo => "MongoDB",
113 Self::Mysql => "MySQL",
114 Self::Clickhouse => "ClickHouse",
115 Self::SqlServer => "SQL Server",
116 Self::Sqlite => "SQLite",
117 Self::Redis => "Redis",
118 Self::Vault => "Vault",
119 }
120 }
121
122 #[must_use]
124 pub const fn section(self) -> &'static str {
125 match self {
126 Self::Redis => "Redis",
127 Self::Vault => "Vault",
128 Self::Postgres
129 | Self::Mongo
130 | Self::Mysql
131 | Self::Clickhouse
132 | Self::SqlServer
133 | Self::Sqlite => "Database",
134 }
135 }
136}
137
138#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
140pub struct DatabaseObservation {
141 pub engine: DatabaseEngine,
143 pub host: Option<String>,
145 pub database: Option<String>,
147 pub localhost: bool,
149}
150
151#[derive(Debug, Clone, PartialEq, Eq)]
153pub struct DatabaseRelation {
154 pub engine: String,
156 pub database: String,
158 pub peers: Vec<String>,
160}
161
162#[derive(Debug, Clone, PartialEq, Eq)]
164pub struct KafkaRelation {
165 pub topic: String,
167 pub produces: Vec<String>,
169 pub consumes: Vec<String>,
171}
172
173#[derive(Debug, Clone, Default, PartialEq, Eq)]
175pub struct ApiRelation {
176 pub outgoing: Vec<String>,
178 pub incoming: Vec<String>,
180}
181
182#[derive(Debug, Clone, PartialEq, Eq)]
184pub struct RepositoryMap {
185 pub repository: String,
187 pub databases: Vec<DatabaseRelation>,
189 pub kafka: Vec<KafkaRelation>,
191 pub api: ApiRelation,
193}
194
195impl RepositoryMap {
196 #[must_use]
198 pub fn connection_count(&self) -> usize {
199 let databases = self
200 .databases
201 .iter()
202 .map(|item| item.peers.len())
203 .sum::<usize>();
204 let kafka = self
205 .kafka
206 .iter()
207 .map(|item| item.produces.len() + item.consumes.len())
208 .sum::<usize>();
209 databases + kafka + self.api.outgoing.len() + self.api.incoming.len()
210 }
211}