MessageQueue::new

This commit is contained in:
Luke Parker 2023-07-22 01:12:15 -04:00
parent 076a8e4d62
commit 79943c3a6c
No known key found for this signature in database

View file

@ -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<<Ristretto as Ciphersuite>::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<<Ristretto as Ciphersuite>::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 {