Skip to content

Commit 1c79a2d

Browse files
committed
Remove app_user_uid from the config.
1 parent 07f2d21 commit 1c79a2d

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

.unreleased/LLT-5866_teliod_remove_app_user_uid_config

Whitespace-only changes.

clis/teliod/example_teliod_config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"log_level": "trace",
33
"log_file_path": "example_log_file.log",
44
"authentication_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5-
"app_user_uid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
65
"interface": {
76
"name": "utun10",
87
"config_provider": "manual"

clis/teliod/src/config.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{num::NonZeroU64, path::PathBuf, str::FromStr};
33
use serde::{de, Deserialize, Deserializer, Serialize};
44
use smart_default::SmartDefault;
55
use std::fs;
6-
use tracing::{debug, info, level_filters::LevelFilter};
6+
use tracing::{debug, info, level_filters::LevelFilter, warn};
77
use uuid::Uuid;
88

99
use telio::crypto::SecretKey;
@@ -57,26 +57,30 @@ fn reconnect_after_expiry_default() -> Percentage {
5757

5858
#[derive(Serialize, Deserialize, Debug, Default)]
5959
pub struct DeviceIdentity {
60-
pub hw_identifier: String,
60+
pub hw_identifier: Uuid,
6161
pub private_key: SecretKey,
6262
pub machine_identifier: String,
6363
}
6464

65-
pub fn generate_hw_identifier(private_key: SecretKey) -> String {
65+
pub fn generate_hw_identifier() -> Uuid {
6666
// Generate hw_identifier
67-
let public_key = private_key.public();
68-
debug!("Generating hw identifier");
69-
format!("{}.{}", public_key, "teliod")
67+
debug!("Generating a new hw identifier");
68+
Uuid::new_v4()
7069
}
7170

7271
impl DeviceIdentity {
7372
pub fn from_file(identity_path: &PathBuf) -> Option<DeviceIdentity> {
74-
info!("Fetching config");
73+
info!("Fetching identity config");
7574

7675
if let Ok(file) = fs::File::open(identity_path) {
77-
debug!("found existing config.");
76+
debug!(
77+
"Found existing identity config {}",
78+
identity_path.to_string_lossy()
79+
);
7880
if let Ok(c) = serde_json::from_reader(file) {
7981
return Some(c);
82+
} else {
83+
warn!("Reading identity config failed");
8084
}
8185
}
8286
None
@@ -90,8 +94,6 @@ pub struct TeliodDaemonConfig {
9094
pub log_file_path: String,
9195
pub interface: InterfaceConfig,
9296

93-
pub app_user_uid: Uuid,
94-
9597
#[serde(deserialize_with = "deserialize_authentication_token")]
9698
pub authentication_token: String,
9799

@@ -163,7 +165,6 @@ mod tests {
163165
let expected = TeliodDaemonConfig {
164166
log_level: LevelFilter::INFO,
165167
log_file_path: "test.log".to_owned(),
166-
app_user_uid: Uuid::from_str("2ba97921-38d7-4736-9d47-261cf3e5c223").unwrap(),
167168
interface: InterfaceConfig {
168169
name: "utun10".to_owned(),
169170
config_provider: InterfaceConfigurationProvider::Manual,
@@ -183,7 +184,6 @@ mod tests {
183184
let json = r#"{
184185
"log_level": "Info",
185186
"log_file_path": "test.log",
186-
"app_user_uid": "2ba97921-38d7-4736-9d47-261cf3e5c223",
187187
"interface": {
188188
"name": "utun10",
189189
"config_provider": "manual"
@@ -198,7 +198,6 @@ mod tests {
198198
let json = r#"{
199199
"log_level": "Info",
200200
"log_file_path": "test.log",
201-
"app_user_uid": "2ba97921-38d7-4736-9d47-261cf3e5c223",
202201
"interface": {
203202
"name": "utun10",
204203
"config_provider": "manual"

clis/teliod/src/core_api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub async fn init_with_api(
8686
Some(identity) => identity,
8787
None => {
8888
let private_key = SecretKey::gen();
89-
let hw_identifier = generate_hw_identifier(private_key.clone());
89+
let hw_identifier = generate_hw_identifier();
9090

9191
let machine_identifier =
9292
match fetch_identifier_with_exp_backoff(auth_token, private_key.public()).await {
@@ -95,7 +95,7 @@ pub async fn init_with_api(
9595
Error::DeviceNotFound => {
9696
info!("Unable to load identifier due to {e}. Registering ...");
9797
register_machine_with_exp_backoff(
98-
&hw_identifier,
98+
&hw_identifier.to_string(),
9999
private_key.public(),
100100
auth_token,
101101
)
@@ -118,7 +118,7 @@ pub async fn init_with_api(
118118
if status == StatusCode::NOT_FOUND {
119119
debug!("Unable to update. Registering machine ...");
120120
device_identity.machine_identifier = register_machine_with_exp_backoff(
121-
&device_identity.hw_identifier,
121+
&device_identity.hw_identifier.to_string(),
122122
device_identity.private_key.public(),
123123
auth_token,
124124
)
@@ -285,7 +285,7 @@ async fn update_machine(device_identity: &DeviceIdentity, auth_token: &str) -> R
285285
.header(header::ACCEPT, "application/json")
286286
.json(&MeshConfig {
287287
public_key: device_identity.private_key.public(),
288-
hardware_identifier: device_identity.hw_identifier.clone(),
288+
hardware_identifier: device_identity.hw_identifier.to_string(),
289289
os: OS_NAME.to_owned(),
290290
os_version: "teliod".to_owned(),
291291
device_type: "other".to_owned(),

clis/teliod/src/daemon.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ pub async fn daemon_event_loop(config: TeliodDaemonConfig) -> Result<(), TeliodE
193193

194194
let socket = DaemonSocket::new(&DaemonSocket::get_ipc_socket_path()?)?;
195195

196-
let nc = NotificationCenter::new(&config).await?;
197-
198196
// Tx is unused here, but this channel can be used to communicate with the
199197
// telio task
200198
let (tx, rx) = mpsc::channel(10);
@@ -208,6 +206,9 @@ pub async fn daemon_event_loop(config: TeliodDaemonConfig) -> Result<(), TeliodE
208206
if !config.authentication_token.eq(EMPTY_TOKEN) {
209207
identity = init_with_api(&config.authentication_token, &config.interface.name).await?;
210208
}
209+
210+
let nc = NotificationCenter::new(&config, &identity.hw_identifier).await?;
211+
211212
let tx_clone = tx.clone();
212213

213214
let token_ptr = Arc::new(config.authentication_token);

clis/teliod/src/nc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,15 @@ struct NCConfig {
8686
}
8787

8888
impl NotificationCenter {
89-
pub async fn new(config: &super::TeliodDaemonConfig) -> Result<Self, Error> {
89+
pub async fn new(
90+
config: &super::TeliodDaemonConfig,
91+
app_user_uid: &Uuid,
92+
) -> Result<Self, Error> {
9093
let callbacks = Arc::new(Mutex::new(vec![]));
9194

9295
let nc_config = NCConfig {
9396
authentication_token: config.authentication_token.clone(),
94-
app_user_uid: config.app_user_uid,
97+
app_user_uid: *app_user_uid,
9598
callbacks: callbacks.clone(),
9699

97100
http_certificate_file_path: config.http_certificate_file_path.clone(),

nat-lab/data/teliod/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"log_level": "trace",
33
"log_file_path": "teliod_natlab.log",
44
"authentication_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5-
"app_user_uid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
65
"interface": {
76
"name": "teliod",
87
"config_provider": "manual"

0 commit comments

Comments
 (0)