From 352dd535e0386d899e816ac5f597e583d1ade768 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 10 Apr 2024 12:06:45 +0200 Subject: Closes #8. 0.4.0 seems to work --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5a0931d..2726a5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::{fmt::Display, time::Duration}; use crate::config::Config; use clap::{Command, CommandFactory, Parser, Subcommand}; use clap_complete::{generate, Generator, Shell}; +use config::Method; use error::Error; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use requests::{device, start::start}; @@ -117,13 +118,21 @@ fn default_headers(config: &Config) -> Result { let mut map = HeaderMap::new(); map.append("Accept-Content", HeaderValue::from_str("application/json")?); map.append("Content-Type", HeaderValue::from_str("application/json")?); - map.append("Authorization", HeaderValue::from_str(&config.apikey)?); + if config.auth.method != Method::None { + map.append("Authorization", HeaderValue::from_str(&config.auth.secret)?); + + } Ok(map) } -fn format_url(config: &Config, path: &str, protocol: &Protocols) -> String { - format!("{}://{}/{}", protocol, config.server, path) +fn format_url(config: &Config, path: &str, protocol: &Protocols, id: Option<&str>) -> String { + if let Some(id) = id { + format!("{}://{}/{}/{}", protocol, config.server, path, id) + + } else { + format!("{}://{}/{}", protocol, config.server, path) + } } async fn check_success(res: Response) -> Result { -- cgit v1.2.3