From 58b4b003110d433b136388c2f13fc0b61e7aa167 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sat, 8 Oct 2022 09:51:42 -0400 Subject: [PATCH] added auth type enum to auth struct --- src/request.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/request.rs b/src/request.rs index b0828b6..0e81099 100644 --- a/src/request.rs +++ b/src/request.rs @@ -5,6 +5,12 @@ use reqwest::blocking::Client; use crate::config::Configuration; +pub enum AuthenticationType { + BasicAuth, + ApiToken, + None, +} + pub struct Request<'a> { pub client: Client, pub arg_value: ArgMatches<'a>, @@ -17,6 +23,7 @@ pub struct Authentication { pub basic: bool, pub api_token: bool, pub credentials: (Option, Option), + pub auth_type: AuthenticationType, } impl<'a> Request<'a> { @@ -49,6 +56,17 @@ impl<'a> Request<'a> { 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 { @@ -87,6 +105,7 @@ impl Authentication { basic: true, api_token: false, credentials: (Some(user), Some(pass)), + auth_type: AuthenticationType::BasicAuth, } } @@ -98,6 +117,7 @@ impl Authentication { basic: false, api_token: true, credentials: (Some(user), Some(api_token)), + auth_type: AuthenticationType::ApiToken, } }