Merge branch 'write-auth-key'
This commit is contained in:
26
src/lib.rs
26
src/lib.rs
@@ -1,5 +1,6 @@
|
||||
use std::error::Error;
|
||||
use std::fs::read_to_string;
|
||||
use std::fs::{read_to_string, File};
|
||||
use std::io::Write;
|
||||
|
||||
use oauth2::basic::BasicClient;
|
||||
use oauth2::reqwest::http_client;
|
||||
@@ -9,16 +10,23 @@ mod types;
|
||||
use types::{AuthKeyRequest, AuthKeyResponse, ClientAuth};
|
||||
|
||||
pub fn run() -> Result<(), Box<dyn Error>> {
|
||||
println!("Reading Client ID And Secret From File");
|
||||
let client_auth = read_client_auth()?;
|
||||
|
||||
println!("Client ID: {}", client_auth.id);
|
||||
println!("Client Secret: {}", client_auth.secret);
|
||||
|
||||
println!("Getting API Token With Client ID: {}", client_auth.id);
|
||||
let access_token = get_api_token(client_auth.id, client_auth.secret)?;
|
||||
|
||||
println!("Generating New Auth Key");
|
||||
let auth_key = get_auth_key(access_token)?;
|
||||
|
||||
println!("Auth Key: {}", auth_key);
|
||||
println!("Writing Auth Key to File");
|
||||
write_auth_key(auth_key)?;
|
||||
|
||||
println!(
|
||||
"Auth key has been successfully updated.\n
|
||||
*** Make sure in your tsdproxy config you are pointing to the file '/config/.auth-key' to pick up the key. ***
|
||||
*** Make sure you restart tsdproxy for the new keys to be used ***"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -81,3 +89,11 @@ fn get_auth_key(api_token: AccessToken) -> Result<String, Box<dyn Error>> {
|
||||
|
||||
Ok(auth_response.get_auth_key())
|
||||
}
|
||||
|
||||
fn write_auth_key(auth_key: String) -> Result<(), Box<dyn Error>> {
|
||||
let mut keyfile = File::create("config/.auth-key")?;
|
||||
|
||||
keyfile.write_all(auth_key.as_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user