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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
// ── Manifest ─────────────────────────────────────────────────────────────────
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Manifest {
#[serde(default = "default_version")]
pub version: String,
#[serde(default)]
pub discovery: DiscoveryConfig,
#[serde(default)]
pub policy: PolicyConfig,
pub services: Vec<ServiceEntry>,
}
impl Manifest {
pub fn load(path: &Path) -> Result<Self> {
let text = std::fs::read_to_string(path)
.with_context(|| format!("cannot read manifest: {}", path.display()))?;
let manifest: Self = serde_yaml::from_str(&text)
.with_context(|| format!("cannot parse manifest: {}", path.display()))?;
Ok(manifest)
}
/// Effective discovery glob patterns, falling back to common monorepo conventions.
pub fn effective_discovery_paths(&self) -> Vec<String> {
if self.discovery.paths.is_empty() {
DEFAULT_DISCOVERY_PATHS
.iter()
.map(|s| s.to_string())
.collect()
} else {
self.discovery.paths.clone()
}
}
}
// ── Policy config ─────────────────────────────────────────────────────────────
/// Declarative policy rules enforced during `svccat check`.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PolicyConfig {
/// Fields that every service entry must declare.
/// Missing fields become error-level drift items.
/// Example: ["url", "language", "platform"]
#[serde(default)]
pub require_fields: Vec<String>,
}
// ── Discovery config ─────────────────────────────────────────────────────────
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DiscoveryConfig {
/// Glob patterns (relative to repo root) that expand to candidate service
/// directories. Defaults to common monorepo conventions when empty.
#[serde(default)]
pub paths: Vec<String>,
/// Filenames whose presence inside a directory marks it as a service.
#[serde(default = "default_markers")]
pub markers: Vec<String>,
/// Glob patterns (relative to repo root) for directories to exclude from
/// discovery. E.g. `["examples/*", "vendor/*"]`.
#[serde(default)]
pub ignore: Vec<String>,
}
/// Glob patterns tried when `discovery.paths` is empty.
pub const DEFAULT_DISCOVERY_PATHS: &[&str] =
&["services/*", "microservices/*", "apps/*", "packages/*"];
fn default_markers() -> Vec<String> {
default_markers_pub()
}
/// Public version of the default markers list, usable outside this module.
pub fn default_markers_pub() -> Vec<String> {
[
"Cargo.toml",
"Dockerfile",
"go.mod",
"package.json",
"pyproject.toml",
"requirements.txt",
// JVM
"build.gradle",
"build.gradle.kts",
"pom.xml",
// C / C++
"CMakeLists.txt",
// .NET
"Directory.Build.props",
// Ruby
"Gemfile",
// Elixir
"mix.exs",
// Dart / Flutter
"pubspec.yaml",
]
.iter()
.map(|s| s.to_string())
.collect()
}
// ── Service entry ─────────────────────────────────────────────────────────────
/// One entry in the `services:` list.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ServiceEntry {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub language: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub platform: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<String>,
/// Owning team name (e.g. "platform", "growth").
#[serde(skip_serializing_if = "Option::is_none")]
pub team: Option<String>,
/// On-call contact: a user handle, email, or PagerDuty service name.
#[serde(skip_serializing_if = "Option::is_none")]
pub oncall: Option<String>,
/// Portfolio-compatible: git submodule path that owns the source.
#[serde(skip_serializing_if = "Option::is_none")]
pub submodule: Option<String>,
/// Explicit filesystem path to the service root (overrides name-based matching).
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
/// Path to the service's documentation file.
#[serde(skip_serializing_if = "Option::is_none")]
pub docs: Option<String>,
/// Path to the service's CI workflow file.
#[serde(skip_serializing_if = "Option::is_none")]
pub ci: Option<String>,
/// Arbitrary labels for grouping and filtering (e.g. "critical", "beta").
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tags: Vec<String>,
/// Names of other services this service depends on (used for graph edges).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub depends_on: Vec<String>,
}
impl ServiceEntry {
/// Returns the canonical relative path for existence checks.
/// Prefers `path`, then `submodule`, then `None` (name-based matching).
pub fn declared_path(&self) -> Option<&str> {
self.path.as_deref().or(self.submodule.as_deref())
}
}
// ── Helpers ───────────────────────────────────────────────────────────────────
fn default_version() -> String {
"1".to_string()
}
/// Look for a manifest in `root`, trying common filenames.
pub fn find_default(root: &Path) -> PathBuf {
for name in &["svccat.yaml", "svccat.yml", "services.yaml", "services.yml"] {
let p = root.join(name);
if p.exists() {
return p;
}
}
root.join("services.yaml")
}