add credentials entry view

This commit is contained in:
2022-12-13 21:50:34 -08:00
parent 9055fa41aa
commit 67705aa2d1
6 changed files with 83 additions and 33 deletions

View File

@ -36,7 +36,7 @@ pub fn get_clients(local_port: u16) -> Result<Vec<Client>, ClientInfoError> {
let mut clients = Vec::new();
let mut sys = System::new();
for p in get_associated_pids(local_port)? {
let pid = Pid::from(p as i32);
let pid = Pid::from(p as usize);
sys.refresh_process(pid);
let proc = sys.process(pid)
.ok_or(ClientInfoError::PidNotFound)?;

View File

@ -1,7 +1,7 @@
use serde::{Serialize, Deserialize};
use tauri::State;
use crate::state::{AppState, Session};
use crate::state::{AppState, Session, Credentials};
#[derive(Clone, Serialize, Deserialize)]
@ -43,8 +43,7 @@ pub fn respond(response: RequestResponse, app_state: State<'_, AppState>) -> Res
pub async fn unlock(passphrase: String, app_state: State<'_, AppState>) -> Result<(), String> {
app_state.decrypt(&passphrase)
.await
.map_err(|e| e.to_string())?;
Ok(())
.map_err(|e| e.to_string())
}
@ -58,3 +57,14 @@ pub fn get_session_status(app_state: State<'_, AppState>) -> String {
}
}
#[tauri::command]
pub async fn save_credentials(
credentials: Credentials,
passphrase: String,
app_state: State<'_, AppState>
) -> Result<(), String> {
app_state.save_creds(credentials, &passphrase)
.await
.map_err(|e| e.to_string())
}

View File

@ -1,6 +1,6 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::str::FromStr;
@ -14,31 +14,24 @@ mod storage;
fn main() {
let initial_state = match state::AppState::new() {
Ok(state) => state,
Err(e) => {eprintln!("{}", e); return;}
};
let initial_state = match state::AppState::new() {
Ok(state) => state,
Err(e) => {eprintln!("{}", e); return;}
};
tauri::Builder::default()
.manage(initial_state)
.invoke_handler(tauri::generate_handler![
ipc::unlock,
ipc::respond,
ipc::get_session_status,
])
.setup(|app| {
let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
tauri::async_runtime::spawn(server::serve(addr, app.handle()));
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
// let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
// let rt = Runtime::new().unwrap();
// rt.block_on(http::serve(addr)).unwrap();
// let creds = std::fs::read_to_string("credentials.json").unwrap();
// storage::save(&creds, "correct horse battery staple");
tauri::Builder::default()
.manage(initial_state)
.invoke_handler(tauri::generate_handler![
ipc::unlock,
ipc::respond,
ipc::get_session_status,
ipc::save_credentials,
])
.setup(|app| {
let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
tauri::async_runtime::spawn(server::serve(addr, app.handle()));
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -21,13 +21,19 @@ use crate::errors::*;
#[serde(untagged)]
pub enum Credentials {
LongLived {
#[serde(rename = "AccessKeyId")]
access_key_id: String,
#[serde(rename = "SecretAccessKey")]
secret_access_key: String,
},
ShortLived {
#[serde(rename = "AccessKeyId")]
access_key_id: String,
#[serde(rename = "SecretAccessKey")]
secret_access_key: String,
#[serde(rename = "Token")]
token: String,
#[serde(rename = "Expiration")]
expiration: String,
},
}