From 808c6a526c8b5f0ce4df70d4630e151253989ad0 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Mon, 26 Aug 2024 19:45:26 -0400 Subject: [PATCH] added base64 encoding option to basic auth --- Cargo.toml | 3 ++- src/repo.rs | 6 ++++++ src/request.rs | 22 ++++++++++++++++++++++ src/user.rs | 10 ++++++++++ src/util.rs | 7 +++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cb09472..3fdbf67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gt" -version = "0.2.0" +version = "0.3.0" authors = ["Wyatt J. Miller "] edition = "2018" description = "A Gitea CLI client" @@ -11,6 +11,7 @@ license-file = "LICENSE" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +base64 = "0.22.1" clap = "2.33.1" colored = "2.0.0" config = "0.11.0" diff --git a/src/repo.rs b/src/repo.rs index c79d3a6..feea55a 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -423,3 +423,9 @@ impl Repository { pub fn create_commit(&self, request: &Request, config: Configuration) {} } + +impl Default for Repository { + fn default() -> Self { + Repository::new() + } +} diff --git a/src/request.rs b/src/request.rs index 3e2d4b8..e51bc3e 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,5 +1,6 @@ use std::{collections::HashMap, process}; +use base64::{engine::general_purpose::URL_SAFE, Engine as _}; use clap::ArgMatches; use reqwest::blocking::Client; @@ -67,6 +68,23 @@ impl<'a> Request<'a> { request_type: util::get_request_type(&arg).unwrap(), } } + + pub fn auth_type(&self) { + match self.authentication.auth_type { + AuthenticationType::BasicAuth => { + URL_SAFE.encode(self.authentication.credentials.1.unwrap()) + } + AuthenticationType::ApiToken => self.authentication.credentials.1, + AuthenticationType::None => { + // this shouldn't happen, ever + panic!(); + } + } + } + + pub fn url_builder(&self) { + Ok() + } } impl Authentication { @@ -140,3 +158,7 @@ impl Authentication { } } } + +impl Default for Authentication { + fn default() -> Self {} +} diff --git a/src/user.rs b/src/user.rs index dd6cce3..8d74a16 100644 --- a/src/user.rs +++ b/src/user.rs @@ -224,4 +224,14 @@ impl User { Err(e) => panic!("{}", e), } } + + pub fn authed_user(&self, request: &Request) { + let client = &request.client; + } +} + +impl Default for User { + fn default() -> Self { + User::new() + } } diff --git a/src/util.rs b/src/util.rs index f2d7dce..afe49a6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -9,6 +9,7 @@ pub enum ErrorKind { ForbiddenRequest, NotFound, UnprocessiableRequest, + JsonError, } // TODO: Can't get this function to properly work @@ -60,6 +61,12 @@ pub fn bad_response_message(message: &String, error_kind: ErrorKind) -> String { ErrorKind::UnprocessiableRequest => { final_message = format!("Client error - the request can't be processed. Please try again!\nError message: {}", message); } + ErrorKind::JsonError => { + final_message = format!( + "Client error - can't parse command!\nError message: {}", + message + ); + } } String::from(final_message)