Skip to content

Commit 8c98e95

Browse files
fix(DiscoveryBuilder): hide the URL details. (#21)
Signed-off-by: Arnaud de Grandmaison <[email protected]>
1 parent b5a7614 commit 8c98e95

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

examples/challenge_response.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ fn my_evidence_builder(nonce: &[u8], accept: &[String]) -> Result<(Vec<u8>, Stri
2020
fn main() {
2121
let base_url = "https://localhost:8080";
2222

23-
let discovery_api_endpoint = format!("{}{}", base_url, "/.well-known/veraison/verification");
24-
2523
let discovery = DiscoveryBuilder::new()
26-
.with_url(discovery_api_endpoint)
24+
.with_base_url(base_url.into())
2725
.with_root_certificate("veraison-root.crt".into())
2826
.build()
2927
.expect("Failed to start API discovery with the service");

src/lib.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,15 @@ impl DiscoveryBuilder {
376376
}
377377
}
378378

379-
/// Use this method to supply the URL of the discovery endpoint, e.g.:
380-
/// "https://veraison.example/.well-known/veraison/verification"
381-
pub fn with_url(mut self, v: String) -> DiscoveryBuilder {
382-
self.url = Some(v);
379+
/// Use this method to supply the base URL of the discovery endpoint, e.g.
380+
/// "https://veraison.example" in the full
381+
/// "https://veraison.example/.well-known/veraison/verification".
382+
/// This hides / encapsulate the details of what the actual URL looks like.
383+
pub fn with_base_url(mut self, base_url: String) -> DiscoveryBuilder {
384+
self.url = Some(format!(
385+
"{}{}",
386+
base_url, "/.well-known/veraison/verification"
387+
));
383388
self
384389
}
385390

@@ -710,14 +715,8 @@ mod tests {
710715
.mount(&mock_server)
711716
.await;
712717

713-
let discovery_api_endpoint = format!(
714-
"{}{}",
715-
mock_server.uri(),
716-
"/.well-known/veraison/verification"
717-
);
718-
719718
let discovery = DiscoveryBuilder::new()
720-
.with_url(discovery_api_endpoint)
719+
.with_base_url(mock_server.uri())
721720
.build()
722721
.expect("Failed to create Discovery client.");
723722

0 commit comments

Comments
 (0)