added auth type enum to auth struct

This commit is contained in:
Wyatt J. Miller 2022-10-08 09:51:42 -04:00
parent a8c70a2869
commit 58b4b00311

View File

@ -5,6 +5,12 @@ use reqwest::blocking::Client;
use crate::config::Configuration; use crate::config::Configuration;
pub enum AuthenticationType {
BasicAuth,
ApiToken,
None,
}
pub struct Request<'a> { pub struct Request<'a> {
pub client: Client, pub client: Client,
pub arg_value: ArgMatches<'a>, pub arg_value: ArgMatches<'a>,
@ -17,6 +23,7 @@ pub struct Authentication {
pub basic: bool, pub basic: bool,
pub api_token: bool, pub api_token: bool,
pub credentials: (Option<String>, Option<String>), pub credentials: (Option<String>, Option<String>),
pub auth_type: AuthenticationType,
} }
impl<'a> Request<'a> { impl<'a> Request<'a> {
@ -49,6 +56,17 @@ impl<'a> Request<'a> {
authentication: auth, authentication: auth,
} }
} }
/// public method that decides whether to format the request url
/// based on the authentication written in the config file.
/// Returns an integer.
pub fn url_request(&self) -> bool {
if self.authentication.api_token {
true
} else {
false
}
}
} }
impl Authentication { impl Authentication {
@ -87,6 +105,7 @@ impl Authentication {
basic: true, basic: true,
api_token: false, api_token: false,
credentials: (Some(user), Some(pass)), credentials: (Some(user), Some(pass)),
auth_type: AuthenticationType::BasicAuth,
} }
} }
@ -98,6 +117,7 @@ impl Authentication {
basic: false, basic: false,
api_token: true, api_token: true,
credentials: (Some(user), Some(api_token)), credentials: (Some(user), Some(api_token)),
auth_type: AuthenticationType::ApiToken,
} }
} }