1use anyhow::{anyhow, Result};
2use crate::tls::TlsConfig;
3
4pub fn scheduler_uri() -> String {
5 std::env::var("GL_SCHEDULER_GRPC_URI")
6 .unwrap_or_else(|_| "https://scheduler.gl.blckstrm.com".to_string())
7}
8
9pub fn get_node_id_from_tls_config(tls_config: &TlsConfig) -> Result<Vec<u8>> {
10 let subject_common_name = match &tls_config.x509_cert {
11 Some(x) => match x.subject_common_name() {
12 Some(cn) => cn,
13 None => {
14 return Err(anyhow!(
15 "Failed to parse the subject common name in the provided x509 certificate"
16 ))
17 }
18 },
19 None => {
20 return Err(anyhow!(
21 "The certificate could not be parsed in the x509 format"
22 ))
23 }
24 };
25
26 let split_subject_common_name = subject_common_name.split("/").collect::<Vec<&str>>();
27
28 assert!(split_subject_common_name[1] == "users");
29 Ok(hex::decode(split_subject_common_name[2])
30 .expect("Failed to parse the node_id from the TlsConfig to bytes"))
31}