|
23 | 23 | //! cx.import_profile(&profile.to_yaml()?).await?; |
24 | 24 | //! ``` |
25 | 25 | //! |
26 | | -//! Profile endpoints are policy endpoints, so [`policy::Endpoint`] configures |
27 | | -//! them. Setters are named after the YAML fields they set. |
| 26 | +//! [`policy::Endpoint`] configures profile endpoints. Setters are named after |
| 27 | +//! the YAML fields they set, but explicit credential bindings belong in |
| 28 | +//! sandbox policy, not reusable profiles. |
28 | 29 | //! |
29 | 30 | //! [`policy::Endpoint`]: crate::policy::Endpoint |
30 | 31 |
|
@@ -127,7 +128,17 @@ impl Profile { |
127 | 128 | } |
128 | 129 |
|
129 | 130 | /// The profile as YAML, as `profile export` writes it. |
| 131 | + /// Returns an error if an endpoint specifies `credential_binding`. |
130 | 132 | pub fn to_yaml(&self) -> Result<String> { |
| 133 | + for endpoint in &self.profile.endpoints { |
| 134 | + if endpoint.credential_binding.is_some() { |
| 135 | + return Err(Error::msg(format!( |
| 136 | + "provider profile {} endpoint {}:{} cannot set credential_binding; \ |
| 137 | + set it in sandbox policy to bind a concrete provider", |
| 138 | + self.profile.id, endpoint.host, endpoint.port |
| 139 | + ))); |
| 140 | + } |
| 141 | + } |
131 | 142 | profile_to_yaml(&ProviderTypeProfile::from_proto(&self.profile)) |
132 | 143 | .map_err(Error::from_display) |
133 | 144 | .context(format!("render provider profile {}", self.profile.id)) |
@@ -248,6 +259,20 @@ binaries: [/usr/bin/curl, /usr/bin/python*] |
248 | 259 | assert_eq!(parsed(&yaml), expected, "rendered:\n{yaml}"); |
249 | 260 | } |
250 | 261 |
|
| 262 | + #[test] |
| 263 | + fn rejects_explicit_credential_binding() { |
| 264 | + let error = Profile::new("example") |
| 265 | + .endpoint("api.example.test", 443, |ep| { |
| 266 | + ep.credential_binding("provider"); |
| 267 | + }) |
| 268 | + .to_yaml() |
| 269 | + .expect_err("a profile must not silently drop an explicit binding") |
| 270 | + .to_string(); |
| 271 | + assert!(error.contains("api.example.test:443"), "{error}"); |
| 272 | + assert!(error.contains("credential_binding"), "{error}"); |
| 273 | + assert!(error.contains("sandbox policy"), "{error}"); |
| 274 | + } |
| 275 | + |
251 | 276 | /// A profile with only an id has the display name and category the |
252 | 277 | /// gateway requires. |
253 | 278 | #[test] |
|
0 commit comments