You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/cli.rs
+55-59
Original file line number
Diff line number
Diff line change
@@ -441,81 +441,77 @@ impl Options {
441
441
442
442
/// TODO: refactor and document
443
443
pubfnget_url(&self,mode:Mode) -> Url{
444
-
let(endpoint, env_var) = match mode {
445
-
Mode::Ingest => {
446
-
ifself.ingestor_endpoint.is_empty(){
447
-
returnformat!(
448
-
"{}://{}",
449
-
self.get_scheme(),
450
-
self.address
451
-
)
452
-
.parse::<Url>()// if the value was improperly set, this will panic before hand
453
-
.unwrap_or_else(|err| {
454
-
panic!("{err}, failed to parse `{}` as Url. Please set the environment variable `P_ADDR` to `<ip address>:<port>` without the scheme (e.g., 192.168.1.1:8000). Please refer to the documentation: https://logg.ing/env for more details.",self.address)
455
-
});
456
-
}
457
-
(&self.ingestor_endpoint,"P_INGESTOR_ENDPOINT")
458
-
}
459
-
Mode::Index => {
460
-
ifself.indexer_endpoint.is_empty(){
461
-
returnformat!(
462
-
"{}://{}",
463
-
self.get_scheme(),
464
-
self.address
465
-
)
466
-
.parse::<Url>()// if the value was improperly set, this will panic before hand
467
-
.unwrap_or_else(|err| {
468
-
panic!("{err}, failed to parse `{}` as Url. Please set the environment variable `P_ADDR` to `<ip address>:<port>` without the scheme (e.g., 192.168.1.1:8000). Please refer to the documentation: https://logg.ing/env for more details.",self.address)
panic!("Invalid value `{}`, please set the environement variable `{env_var}` to `<ip address / DNS>:<port>` without the scheme (e.g., 192.168.1.1:8000 or example.com:8000). Please refer to the documentation: https://logg.ing/env for more details.", endpoint);
478
-
}
450
+
self.parse_endpoint(&endpoint)
451
+
}
479
452
480
-
let addr_from_env = endpoint.split(':').collect::<Vec<&str>>();
panic!("Invalid value `{}`, please set the environement variable `{env_var}` to `<ip address / DNS>:<port>` without the scheme (e.g., 192.168.1.1:8000 or example.com:8000). Please refer to the documentation: https://logg.ing/env for more details.", endpoint);
458
+
if endpoint.starts_with("http"){
459
+
panic!(
460
+
"Invalid value `{}`, please set the environment variable `{}` to `<ip address / DNS>:<port>` without the scheme (e.g., 192.168.1.1:8000 or example.com:8000). Please refer to the documentation: https://logg.ing/env for more details.",
461
+
endpoint, env_var
462
+
);
484
463
}
485
464
486
-
letmut hostname = addr_from_env[0].to_string();
487
-
letmut port = addr_from_env[1].to_string();
465
+
endpoint.to_string()
466
+
}
488
467
489
-
// if the env var value fits the pattern $VAR_NAME:$VAR_NAME
let addr_parts:Vec<&str> = endpoint.split(':').collect();
494
470
495
-
if hostname.is_empty(){
496
-
panic!("The environement variable `{}` is not set, please set as <ip address / DNS> without the scheme (e.g., 192.168.1.1 or example.com). Please refer to the documentation: https://logg.ing/env for more details.", var_hostname);
497
-
}
498
-
if hostname.starts_with("http"){
499
-
panic!("Invalid value `{}`, please set the environement variable `{}` to `<ip address / DNS>` without the scheme (e.g., 192.168.1.1 or example.com). Please refer to the documentation: https://logg.ing/env for more details.", hostname, var_hostname);
"Invalid value `{}`, please set the environment variable to `<ip address / DNS>:<port>` without the scheme (e.g., 192.168.1.1:8000 or example.com:8000). Please refer to the documentation: https://logg.ing/env for more details.",
474
+
endpoint
475
+
);
503
476
}
504
477
505
-
if port.starts_with('$'){
506
-
let var_port = port[1..].to_string();
507
-
port = env::var(&var_port).unwrap_or_default();
478
+
let hostname = self.resolve_env_var(addr_parts[0]);
479
+
let port = self.resolve_env_var(addr_parts[1]);
508
480
509
-
if port.is_empty(){
481
+
self.build_url(&format!("{}:{}", hostname, port))
482
+
}
483
+
484
+
fnresolve_env_var(&self,value:&str) -> String{
485
+
ifletSome(stripped) = value.strip_prefix('$'){
486
+
let var_name = stripped;
487
+
let resolved_value = env::var(var_name).unwrap_or_else(|_| {
488
+
panic!(
489
+
"The environment variable `{}` is not set. Please set it to a valid value. Refer to the documentation: https://logg.ing/env for more details.",
490
+
var_name
491
+
);
492
+
});
493
+
494
+
if resolved_value.starts_with("http"){
510
495
panic!(
511
-
"Port is not set in the environement variable `{}`. Please refer to the documentation: https://logg.ing/env for more details.",
512
-
var_port
496
+
"Invalid value `{}`, please set the environment variable `{}` to `<ip address / DNS>` without the scheme (e.g., 192.168.1.1 or example.com). Please refer to the documentation: https://logg.ing/env for more details.",
"{err}, failed to parse `{}` as Url. Please set the environment variable `P_ADDR` to `<ip address>:<port>` without the scheme (e.g., 192.168.1.1:8000). Please refer to the documentation: https://logg.ing/env for more details.",
0 commit comments