diff options
author | FxQnLr <[email protected]> | 2024-06-17 11:19:13 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-17 11:19:13 +0200 |
commit | b375657e660b199127a76683980a5d210a572ab7 (patch) | |
tree | fbed775283917537c1d2d11bdbf38a0fa7c05a02 /src/main.rs | |
parent | 31a57425a76cae121c5d8ef5b0f2442ca6a9ee61 (diff) | |
parent | 0877850a63791772dd19a0af9a0c7c87940aead2 (diff) | |
download | webol-cli-0.3.0.tar webol-cli-0.3.0.tar.gz webol-cli-0.3.0.zip |
0.3.0
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 15 |
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}; | |||
3 | use crate::config::Config; | 3 | use crate::config::Config; |
4 | use clap::{Command, CommandFactory, Parser, Subcommand}; | 4 | use clap::{Command, CommandFactory, Parser, Subcommand}; |
5 | use clap_complete::{generate, Generator, Shell}; | 5 | use clap_complete::{generate, Generator, Shell}; |
6 | use config::Method; | ||
6 | use error::Error; | 7 | use error::Error; |
7 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | 8 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; |
8 | use requests::{device, start::start}; | 9 | use 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 | ||
125 | fn format_url(config: &Config, path: &str, protocol: &Protocols) -> String { | 129 | fn 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 | ||
129 | async fn check_success(res: Response) -> Result<String, Error> { | 138 | async fn check_success(res: Response) -> Result<String, Error> { |