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.
This commit is contained in:
2024-12-15 19:37:57 -05:00
parent 46cb8ad2bb
commit dee3723e47
2 changed files with 46 additions and 0 deletions

36
src/lib.rs Normal file
View File

@@ -0,0 +1,36 @@
use std::error::Error;
use std::fs::read_to_string;
pub fn run() -> Result<(), Box<dyn Error>> {
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<ClientAuth, Box<dyn Error>> {
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,
})
}

10
src/main.rs Normal file
View File

@@ -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);
}
}