diff options
author | FxQnLr <[email protected]> | 2024-04-10 12:06:45 +0200 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-04-10 12:06:45 +0200 |
commit | 352dd535e0386d899e816ac5f597e583d1ade768 (patch) | |
tree | 064522c02fb30b3804ee399fd2e77a3e10c3f289 /src/main.rs | |
parent | 23aa75439c3ee60e22ce183853516ca3cdd13ff4 (diff) | |
download | webol-cli-352dd535e0386d899e816ac5f597e583d1ade768.tar webol-cli-352dd535e0386d899e816ac5f597e583d1ade768.tar.gz webol-cli-352dd535e0386d899e816ac5f597e583d1ade768.zip |
Closes #8. 0.4.0 seems to work
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> { |