From dee3723e476763d714be0e900ad2c7b9968d6dfc Mon Sep 17 00:00:00 2001 From: Wesley Irvin Date: Sun, 15 Dec 2024 19:37:57 -0500 Subject: [PATCH] Get client secret and key This is to solve issue #4. This pulls in the client secret and key and is able to print them out on the screen successfully from our own created data type. --- src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ src/main.rs | 10 ++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..9901970 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,36 @@ +use std::error::Error; +use std::fs::read_to_string; + +pub fn run() -> Result<(), Box> { + let client_auth = read_client_auth()?; + + println!("Client ID: {}", client_auth.client_id); + println!("Client Secret: {}", client_auth.client_secret); + + Ok(()) +} + +struct ClientAuth { + client_id: String, + client_secret: String, +} + +fn read_client_auth() -> Result> { + let mut id = String::new(); + let mut secret = String::new(); + + for line in read_to_string(".client-auth")?.lines() { + let line_str = line.to_string(); + let cur_line: Vec<&str> = line_str.split('=').collect(); + if cur_line[0] == "client_id" { + id = cur_line[1].to_string(); + } else if cur_line[0] == "client_secret" { + secret = cur_line[1].to_string(); + } + } + + Ok(ClientAuth { + client_id: id, + client_secret: secret, + }) +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..371f8ac --- /dev/null +++ b/src/main.rs @@ -0,0 +1,10 @@ +use std::process; + +use tsdproxy_keygen::run; + +fn main() { + if let Err(e) = run() { + println!("An error occured: {e}"); + process::exit(1); + } +}