Page MenuHomePhabricator

D6955.id23458.diff
No OneTemporary

D6955.id23458.diff

diff --git a/keyserver/addons/rust-node-addon/Cargo.lock b/keyserver/addons/rust-node-addon/Cargo.lock
--- a/keyserver/addons/rust-node-addon/Cargo.lock
+++ b/keyserver/addons/rust-node-addon/Cargo.lock
@@ -987,6 +987,8 @@
"opaque-ke",
"prost",
"rand",
+ "serde",
+ "serde_json",
"tokio",
"tokio-stream",
"tonic",
@@ -1001,11 +1003,42 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
+[[package]]
+name = "ryu"
+version = "1.0.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
+
[[package]]
name = "serde"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.152"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.93"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
[[package]]
name = "sha2"
diff --git a/keyserver/addons/rust-node-addon/Cargo.toml b/keyserver/addons/rust-node-addon/Cargo.toml
--- a/keyserver/addons/rust-node-addon/Cargo.toml
+++ b/keyserver/addons/rust-node-addon/Cargo.toml
@@ -24,6 +24,8 @@
comm-opaque = {path = "../../../shared/comm-opaque"}
lazy_static = "1.4"
tunnelbroker-client = {path = "../../../shared/tunnelbroker-client"}
+serde_json = "1.0"
+serde = { version = "1.0", features = ["derive"] }
[build-dependencies]
napi-build = "2.0.1"
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/delete_user.rs b/keyserver/addons/rust-node-addon/src/identity_client/delete_user.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client/delete_user.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/delete_user.rs
@@ -4,7 +4,8 @@
#[instrument(skip_all)]
pub async fn delete_user(user_id: String) -> Result<()> {
let channel = get_identity_service_channel().await?;
- let token: MetadataValue<_> = AUTH_TOKEN
+ let token: MetadataValue<_> = IDENTITY_SERVICE_CONFIG
+ .identity_auth_token
.parse()
.map_err(|_| Error::from_status(Status::GenericFailure))?;
let mut identity_client =
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs b/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs
@@ -11,7 +11,8 @@
social_proof: String,
) -> Result<String> {
let channel = get_identity_service_channel().await?;
- let token: MetadataValue<_> = AUTH_TOKEN
+ let token: MetadataValue<_> = IDENTITY_SERVICE_CONFIG
+ .identity_auth_token
.parse()
.map_err(|_| Error::from_status(Status::GenericFailure))?;
let mut identity_client =
@@ -68,7 +69,8 @@
session_initialization_info: HashMap<String, String>,
) -> Result<String> {
let channel = get_identity_service_channel().await?;
- let token: MetadataValue<_> = AUTH_TOKEN
+ let token: MetadataValue<_> = IDENTITY_SERVICE_CONFIG
+ .identity_auth_token
.parse()
.map_err(|_| Error::from_status(Status::GenericFailure))?;
let mut identity_client =
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
@@ -41,6 +41,7 @@
CredentialResponse, RegistrationResponse, RegistrationUpload,
};
use rand::{rngs::OsRng, CryptoRng, Rng};
+use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::env::var;
use tokio::sync::mpsc;
@@ -49,11 +50,30 @@
use tracing::{error, instrument};
lazy_static! {
- pub static ref IDENTITY_SERVICE_SOCKET_ADDR: String =
- var("COMM_IDENTITY_SERVICE_SOCKET_ADDR")
- .unwrap_or_else(|_| "https://[::1]:50051".to_string());
- pub static ref AUTH_TOKEN: String = var("COMM_IDENTITY_SERVICE_AUTH_TOKEN")
- .unwrap_or_else(|_| "test".to_string());
+ static ref IDENTITY_SERVICE_CONFIG: IdentityServiceConfig = {
+ let config_json_string =
+ var("COMM_JSONCONFIG_secrets_identity_service_config");
+ match config_json_string {
+ Ok(json) => serde_json::from_str(&json).unwrap(),
+ Err(_) => IdentityServiceConfig::default(),
+ }
+ };
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct IdentityServiceConfig {
+ identity_socket_addr: String,
+ identity_auth_token: String,
+}
+
+impl Default for IdentityServiceConfig {
+ fn default() -> Self {
+ Self {
+ identity_socket_addr: "https://[::1]:50051".to_string(),
+ identity_auth_token: "test".to_string(),
+ }
+ }
}
fn handle_unexpected_response<T: std::fmt::Debug>(message: Option<T>) -> Error {
@@ -106,7 +126,7 @@
}
async fn get_identity_service_channel() -> Result<Channel> {
- Channel::from_static(&IDENTITY_SERVICE_SOCKET_ADDR)
+ Channel::from_static(&IDENTITY_SERVICE_CONFIG.identity_socket_addr)
.connect()
.await
.map_err(|_| {
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs b/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs
@@ -10,7 +10,8 @@
session_initialization_info: HashMap<String, String>,
) -> Result<String> {
let channel = get_identity_service_channel().await?;
- let token: MetadataValue<_> = AUTH_TOKEN
+ let token: MetadataValue<_> = IDENTITY_SERVICE_CONFIG
+ .identity_auth_token
.parse()
.map_err(|_| Error::from_status(Status::GenericFailure))?;
let mut identity_client =
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/update_user.rs b/keyserver/addons/rust-node-addon/src/identity_client/update_user.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client/update_user.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/update_user.rs
@@ -5,7 +5,6 @@
update_user_request, update_user_response, UpdateUserRequest,
UpdateUserResponse,
};
-use crate::identity_client::{AUTH_TOKEN, IDENTITY_SERVICE_SOCKET_ADDR};
use comm_opaque::Cipher;
use napi::bindgen_prelude::*;
use opaque_ke::{
@@ -18,17 +17,17 @@
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tonic;
-use tonic::{metadata::MetadataValue, transport::Channel};
+use tonic::metadata::MetadataValue;
use tracing::{error, instrument};
+use super::{get_identity_service_channel, IDENTITY_SERVICE_CONFIG};
+
#[napi]
#[instrument(skip_all)]
pub async fn update_user(user_id: String, password: String) -> Result<String> {
- let channel = Channel::from_static(&IDENTITY_SERVICE_SOCKET_ADDR)
- .connect()
- .await
- .map_err(|_| Error::from_status(Status::GenericFailure))?;
- let token: MetadataValue<_> = AUTH_TOKEN
+ let channel = get_identity_service_channel().await?;
+ let token: MetadataValue<_> = IDENTITY_SERVICE_CONFIG
+ .identity_auth_token
.parse()
.map_err(|_| Error::from_status(Status::GenericFailure))?;
let mut identity_client = IdentityServiceClient::with_interceptor(

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 2, 8:43 PM (20 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2608478
Default Alt Text
D6955.id23458.diff (7 KB)

Event Timeline