summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs15
1 files changed, 12 insertions, 3 deletions
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};
3use crate::config::Config; 3use crate::config::Config;
4use clap::{Command, CommandFactory, Parser, Subcommand}; 4use clap::{Command, CommandFactory, Parser, Subcommand};
5use clap_complete::{generate, Generator, Shell}; 5use clap_complete::{generate, Generator, Shell};
6use config::Method;
6use error::Error; 7use error::Error;
7use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 8use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
8use requests::{device, start::start}; 9use requests::{device, start::start};
@@ -117,13 +118,21 @@ fn default_headers(config: &Config) -> Result<HeaderMap, Error> {
117 let mut map = HeaderMap::new(); 118 let mut map = HeaderMap::new();
118 map.append("Accept-Content", HeaderValue::from_str("application/json")?); 119 map.append("Accept-Content", HeaderValue::from_str("application/json")?);
119 map.append("Content-Type", HeaderValue::from_str("application/json")?); 120 map.append("Content-Type", HeaderValue::from_str("application/json")?);
120 map.append("Authorization", HeaderValue::from_str(&config.apikey)?); 121 if config.auth.method != Method::None {
122 map.append("Authorization", HeaderValue::from_str(&config.auth.secret)?);
123
124 }
121 125
122 Ok(map) 126 Ok(map)
123} 127}
124 128
125fn format_url(config: &Config, path: &str, protocol: &Protocols) -> String { 129fn format_url(config: &Config, path: &str, protocol: &Protocols, id: Option<&str>) -> String {
126 format!("{}://{}/{}", protocol, config.server, path) 130 if let Some(id) = id {
131 format!("{}://{}/{}/{}", protocol, config.server, path, id)
132
133 } else {
134 format!("{}://{}/{}", protocol, config.server, path)
135 }
127} 136}
128 137
129async fn check_success(res: Response) -> Result<String, Error> { 138async fn check_success(res: Response) -> Result<String, Error> {