MessageQueue::new

This commit is contained in:
Luke Parker
2023-07-22 01:12:15 -04:00
parent 076a8e4d62
commit 79943c3a6c

View File

@@ -26,11 +26,14 @@ pub struct MessageQueue {
} }
impl 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 // 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 // While we could stitch together multiple variables, our control over this service makes this
// this fine // fine
let mut url = env::var("MESSAGE_QUEUE_RPC").expect("message-queue RPC wasn't specified");
if !url.contains(':') { if !url.contains(':') {
url += ":2287"; url += ":2287";
} }
@@ -38,6 +41,18 @@ impl MessageQueue {
url = "http://".to_string() + &url; 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 priv_key: Zeroizing<<Ristretto as Ciphersuite>::F> = {
let key_str = let key_str =
Zeroizing::new(env::var("MESSAGE_QUEUE_KEY").expect("message-queue key wasn't specified")); Zeroizing::new(env::var("MESSAGE_QUEUE_KEY").expect("message-queue key wasn't specified"));
@@ -54,13 +69,7 @@ impl MessageQueue {
key key
}; };
MessageQueue { Self::new(service, url, priv_key)
service,
pub_key: Ristretto::generator() * priv_key.deref(),
priv_key,
client: Client::new(),
url,
}
} }
async fn json_call(&self, method: &'static str, params: serde_json::Value) -> serde_json::Value { async fn json_call(&self, method: &'static str, params: serde_json::Value) -> serde_json::Value {