From 833960b23fa708166e08e6ec07299ce5404073f6 Mon Sep 17 00:00:00 2001 From: Tilo K Date: Thu, 26 Oct 2023 21:37:26 +0200 Subject: [PATCH] Clearing Keys + README --- Cargo.lock | 41 ++-------------------- Cargo.toml | 1 - README.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/keys.rs | 19 +++++++++-- src/main.rs | 10 +++--- 5 files changed, 121 insertions(+), 48 deletions(-) create mode 100644 README.md diff --git a/Cargo.lock b/Cargo.lock index b1fcf5a..00d639d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,12 +612,6 @@ dependencies = [ "libc", ] -[[package]] -name = "numtoa" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" - [[package]] name = "object" version = "0.32.1" @@ -695,7 +689,7 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall", "smallvec", "windows-targets", ] @@ -712,7 +706,6 @@ dependencies = [ "reqwest", "rpassword", "serde", - "termion", "tokio", ] @@ -768,15 +761,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.3.5" @@ -786,15 +770,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_termios" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" -dependencies = [ - "redox_syscall 0.2.16", -] - [[package]] name = "reqwest" version = "0.11.22" @@ -1050,23 +1025,11 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.3.5", + "redox_syscall", "rustix", "windows-sys", ] -[[package]] -name = "termion" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90" -dependencies = [ - "libc", - "numtoa", - "redox_syscall 0.2.16", - "redox_termios", -] - [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index f9241f3..2358526 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,4 @@ quick-xml = { version = "0.31.0", features = ["serde", "serialize"] } reqwest = { version = "0.11.22", features = ["json"] } rpassword = "7.2.0" serde = { version = "1.0.189", features = ["serde_derive", "derive"] } -termion = "2.0.1" tokio = { version = "1.33.0", features = ["full"] } diff --git a/README.md b/README.md new file mode 100644 index 0000000..290d26c --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ +
+

+ +
PASTEBIN-CLI

+

◦ A simple CLI to use pastebin in your terminal

+

◦ Developed with the software and tools below.

+ +

+OpenSSL +Rust +Hyper +

+ +git-last-commit +GitHub commit activity +GitHub top language +
+ +--- + +## 📖 Table of Contents +- [📖 Table of Contents](#-table-of-contents) +- [📍 Overview](#-overview) +- [📦 Features](#-features) +- [📂 repository Structure](#-repository-structure) +- [⚙️ Modules](#modules) +- [🚀 Getting Started](#-getting-started) + - [🔧 Installation](#-installation) + - [🤖 Running pastebin-cli](#-running-pastebin-cli) + +--- + +## 📦 Features + +- Creating new pastes +- Reading pastes +- Deleting pastes + +--- + + +## 📂 Repository Structure + +```sh +└── pastebin-cli/ + ├── Cargo.lock + ├── Cargo.toml + └── src/ + ├── keys.rs + ├── main.rs + └── pastebin.rs + +``` + +--- + + +--- + +## 🚀 Getting Started + +### 🔧 Installation +```sh +cargo install pastebin-cli +``` + +### 🔧 Installation via Source Code + +1. Clone the pastebin-cli repository: +```sh +git clone https://github.com/Tilo-K/pastebin-cli +``` + +2. Change to the project directory: +```sh +cd pastebin-cli +``` + +3. Install the dependencies: +```sh +cargo install . +``` + +### 🤖 Running pastebin-cli + +```sh +pastebin-cli +``` + +--- + +## 🤝 Contributing + +Contributions are welcome! Here are several ways you can contribute: + +- **[Submit Pull Requests](https://github.com/Tilo-K/pastebin-cli/blob/main/CONTRIBUTING.md)**: Review open PRs, and submit your own PRs. +- **[Join the Discussions](https://github.com/Tilo-K/pastebin-cli/discussions)**: Share your insights, provide feedback, or ask questions. +- **[Report Issues](https://github.com/Tilo-K/pastebin-cli/issues)**: Submit bugs found or log feature requests for TILO-K. diff --git a/src/keys.rs b/src/keys.rs index 97e4190..beb1422 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -55,7 +55,6 @@ pub async fn get_user_key() { if key == "" { let mut username = String::new(); - let mut password = String::new(); print!("Username: "); io::stdout().lock().flush().unwrap(); @@ -65,7 +64,7 @@ pub async fn get_user_key() { print!("Password: "); io::stdout().lock().flush().unwrap(); - password = read_password().unwrap(); + let password = read_password().unwrap(); let key = pastebin::get_user_key(&API_KEY.lock().unwrap(), username, password) .await @@ -79,3 +78,19 @@ pub async fn get_user_key() { USER_KEY.lock().unwrap().push_str(&key); } + +pub fn clear_keys() { + API_KEY.lock().unwrap().clear(); + USER_KEY.lock().unwrap().clear(); + + let home_dir = match home::home_dir() { + Some(path) => path, + None => panic!("Impossible to get your home dir!"), + }; + + let key_file = home_dir.join(".pastebin_key"); + let user_key_file = home_dir.join(".pastebin_userkey"); + + fs::remove_file(key_file).expect("Error removing API KEY file"); + fs::remove_file(user_key_file).expect("Error removing USER KEY file"); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 821dd8b..93d1e41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use clap::{Parser, Subcommand}; use std::fs; use std::path::PathBuf; + mod keys; mod pastebin; @@ -19,6 +20,7 @@ enum Action { Create { file_path: std::path::PathBuf }, Delete { paste_id: String }, List { max_results: Option }, + ClearKeys, } #[tokio::main] @@ -32,6 +34,7 @@ async fn main() { Action::Create { file_path } => create(file_path).await, Action::Delete { paste_id } => delete(paste_id).await, Action::List { max_results } => list(max_results).await, + Action::ClearKeys => keys::clear_keys(), }; } @@ -64,12 +67,7 @@ async fn delete(paste_id: String) { println!("{}", resp); } -async fn edit(paste_id: String, file_path: PathBuf) { - todo!("No offical way to do that yet"); -} - async fn list(max_results: Option) { - let (x, y) = termion::terminal_size().unwrap(); let resp = pastebin::list_pastes( &keys::API_KEY.lock().unwrap(), &keys::USER_KEY.lock().unwrap(), @@ -78,7 +76,7 @@ async fn list(max_results: Option) { .await .unwrap(); - let line = "-".repeat(((x - 15) / 2).into()); + let line = "-".repeat(5); println!("{}Top {} pastes{}", line, max_results.unwrap_or(10), line); for paste in resp {