summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-06-17 11:19:13 +0200
committerGitHub <[email protected]>2024-06-17 11:19:13 +0200
commitb375657e660b199127a76683980a5d210a572ab7 (patch)
treefbed775283917537c1d2d11bdbf38a0fa7c05a02 /src/main.rs
parent31a57425a76cae121c5d8ef5b0f2442ca6a9ee61 (diff)
parent0877850a63791772dd19a0af9a0c7c87940aead2 (diff)
downloadwebol-cli-0.3.0.tar
webol-cli-0.3.0.tar.gz
webol-cli-0.3.0.zip
Merge pull request #9 from FxQnLr/0.3.0HEAD0.3.0main
0.3.0
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> {