Skip to content

Commit d56ef9a

Browse files
committed
Store server_url in Client
1 parent 04af7cc commit d56ef9a

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

examples/provision.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async fn main() -> anyhow::Result<()> {
2525
terms_of_service_agreed: true,
2626
only_return_existing: false,
2727
},
28-
LetsEncrypt::Staging.url(),
28+
LetsEncrypt::Staging.url().to_owned(),
2929
None,
3030
)
3131
.await?;

src/lib.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,14 @@ impl Account {
524524
pub async fn from_parts(
525525
id: String,
526526
key_pkcs8_der: &[u8],
527-
directory_url: &str,
527+
server_url: String,
528528
http: Box<dyn HttpClient>,
529529
) -> Result<Self, Error> {
530530
Ok(Self {
531531
inner: Arc::new(AccountInner {
532532
id,
533533
key: Key::from_pkcs8_der(key_pkcs8_der)?,
534-
client: Arc::new(Client::new(directory_url, http).await?),
534+
client: Arc::new(Client::new(server_url, http).await?),
535535
}),
536536
})
537537
}
@@ -543,14 +543,13 @@ impl Account {
543543
#[cfg(feature = "hyper-rustls")]
544544
pub async fn create(
545545
account: &NewAccount<'_>,
546-
server_url: &str,
546+
server_url: String,
547547
external_account: Option<&ExternalAccountKey>,
548548
) -> Result<(Account, AccountCredentials), Error> {
549549
Self::create_inner(
550550
account,
551551
external_account,
552552
Client::new(server_url, Box::new(DefaultClient::try_new()?)).await?,
553-
server_url,
554553
)
555554
.await
556555
}
@@ -561,15 +560,14 @@ impl Account {
561560
/// Use [`Account::from_credentials()`] to restore the account from the credentials.
562561
pub async fn create_with_http(
563562
account: &NewAccount<'_>,
564-
server_url: &str,
563+
server_url: String,
565564
external_account: Option<&ExternalAccountKey>,
566565
http: Box<dyn HttpClient>,
567566
) -> Result<(Account, AccountCredentials), Error> {
568567
Self::create_inner(
569568
account,
570569
external_account,
571570
Client::new(server_url, http).await?,
572-
server_url,
573571
)
574572
.await
575573
}
@@ -578,7 +576,6 @@ impl Account {
578576
account: &NewAccount<'_>,
579577
external_account: Option<&ExternalAccountKey>,
580578
client: Client,
581-
server_url: &str,
582579
) -> Result<(Account, AccountCredentials), Error> {
583580
let (key, key_pkcs8) = Key::generate()?;
584581
let payload = NewAccountPayload {
@@ -611,7 +608,7 @@ impl Account {
611608
let credentials = AccountCredentials {
612609
id: id.clone(),
613610
key_pkcs8: key_pkcs8.as_ref().to_vec(),
614-
directory: Some(server_url.to_owned()),
611+
directory: Some(client.server_url.clone().unwrap()), // New clients always have `server_url`
615612
// We support deserializing URLs for compatibility with versions pre 0.4,
616613
// but we prefer to get fresh URLs from the `server_url` for newer credentials.
617614
urls: None,
@@ -881,8 +878,12 @@ impl AccountInner {
881878
id: credentials.id,
882879
key: Key::from_pkcs8_der(credentials.key_pkcs8.as_ref())?,
883880
client: Arc::new(match (credentials.directory, credentials.urls) {
884-
(Some(server_url), _) => Client::new(&server_url, http).await?,
885-
(None, Some(directory)) => Client { http, directory },
881+
(Some(server_url), _) => Client::new(server_url, http).await?,
882+
(None, Some(directory)) => Client {
883+
http,
884+
directory,
885+
server_url: None,
886+
},
886887
(None, None) => return Err("no server URLs found".into()),
887888
}),
888889
})
@@ -929,19 +930,21 @@ impl Signer for AccountInner {
929930
struct Client {
930931
http: Box<dyn HttpClient>,
931932
directory: Directory,
933+
server_url: Option<String>,
932934
}
933935

934936
impl Client {
935-
async fn new(server_url: &str, http: Box<dyn HttpClient>) -> Result<Self, Error> {
937+
async fn new(server_url: String, http: Box<dyn HttpClient>) -> Result<Self, Error> {
936938
let req = Request::builder()
937-
.uri(server_url)
939+
.uri(&server_url)
938940
.body(Full::default())
939941
.expect("infallible error should not occur");
940942
let rsp = http.request(req).await?;
941943
let body = rsp.body().await.map_err(Error::Other)?;
942944
Ok(Client {
943945
http,
944946
directory: serde_json::from_slice(&body)?,
947+
server_url: Some(server_url),
945948
})
946949
}
947950

tests/pebble.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl Environment {
484484
terms_of_service_agreed: true,
485485
only_return_existing: false,
486486
},
487-
&format!("https://{}/dir", &config.pebble.listen_address),
487+
format!("https://{}/dir", &config.pebble.listen_address),
488488
config.eab_key.as_ref(),
489489
Box::new(client.clone()),
490490
)

0 commit comments

Comments
 (0)