diff --git a/message-queue/src/client.rs b/message-queue/src/client.rs index fb1efbb2..8296da7d 100644 --- a/message-queue/src/client.rs +++ b/message-queue/src/client.rs @@ -26,11 +26,14 @@ pub struct MessageQueue { } impl MessageQueue { - pub fn from_env(service: Service) -> MessageQueue { + pub fn new( + service: Service, + mut url: String, + priv_key: Zeroizing<::F>, + ) -> MessageQueue { // Allow MESSAGE_QUEUE_RPC to either be a full URL or just a hostname - // While we could stitch together multiple env variables, our control over this service makes - // this fine - let mut url = env::var("MESSAGE_QUEUE_RPC").expect("message-queue RPC wasn't specified"); + // While we could stitch together multiple variables, our control over this service makes this + // fine if !url.contains(':') { url += ":2287"; } @@ -38,6 +41,18 @@ impl MessageQueue { url = "http://".to_string() + &url; } + MessageQueue { + service, + pub_key: Ristretto::generator() * priv_key.deref(), + priv_key, + client: Client::new(), + url, + } + } + + pub fn from_env(service: Service) -> MessageQueue { + let url = env::var("MESSAGE_QUEUE_RPC").expect("message-queue RPC wasn't specified"); + let priv_key: Zeroizing<::F> = { let key_str = Zeroizing::new(env::var("MESSAGE_QUEUE_KEY").expect("message-queue key wasn't specified")); @@ -54,13 +69,7 @@ impl MessageQueue { key }; - MessageQueue { - service, - pub_key: Ristretto::generator() * priv_key.deref(), - priv_key, - client: Client::new(), - url, - } + Self::new(service, url, priv_key) } async fn json_call(&self, method: &'static str, params: serde_json::Value) -> serde_json::Value {