Merge pull request 'Get client secret and key' (#5) from get-client into main

Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2024-12-16 00:42:14 +00:00
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);
}
}