add credentials entry view
This commit is contained in:
parent
9055fa41aa
commit
67705aa2d1
@ -36,7 +36,7 @@ pub fn get_clients(local_port: u16) -> Result<Vec<Client>, ClientInfoError> {
|
|||||||
let mut clients = Vec::new();
|
let mut clients = Vec::new();
|
||||||
let mut sys = System::new();
|
let mut sys = System::new();
|
||||||
for p in get_associated_pids(local_port)? {
|
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);
|
sys.refresh_process(pid);
|
||||||
let proc = sys.process(pid)
|
let proc = sys.process(pid)
|
||||||
.ok_or(ClientInfoError::PidNotFound)?;
|
.ok_or(ClientInfoError::PidNotFound)?;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
use crate::state::{AppState, Session};
|
use crate::state::{AppState, Session, Credentials};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[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> {
|
pub async fn unlock(passphrase: String, app_state: State<'_, AppState>) -> Result<(), String> {
|
||||||
app_state.decrypt(&passphrase)
|
app_state.decrypt(&passphrase)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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())
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
all(not(debug_assertions), target_os = "windows"),
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -14,31 +14,24 @@ mod storage;
|
|||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let initial_state = match state::AppState::new() {
|
let initial_state = match state::AppState::new() {
|
||||||
Ok(state) => state,
|
Ok(state) => state,
|
||||||
Err(e) => {eprintln!("{}", e); return;}
|
Err(e) => {eprintln!("{}", e); return;}
|
||||||
};
|
};
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.manage(initial_state)
|
.manage(initial_state)
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
ipc::unlock,
|
ipc::unlock,
|
||||||
ipc::respond,
|
ipc::respond,
|
||||||
ipc::get_session_status,
|
ipc::get_session_status,
|
||||||
])
|
ipc::save_credentials,
|
||||||
.setup(|app| {
|
])
|
||||||
let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
|
.setup(|app| {
|
||||||
tauri::async_runtime::spawn(server::serve(addr, app.handle()));
|
let addr = std::net::SocketAddrV4::from_str("127.0.0.1:12345").unwrap();
|
||||||
Ok(())
|
tauri::async_runtime::spawn(server::serve(addr, app.handle()));
|
||||||
})
|
Ok(())
|
||||||
.run(tauri::generate_context!())
|
})
|
||||||
.expect("error while running tauri application");
|
.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");
|
|
||||||
}
|
}
|
@ -21,13 +21,19 @@ use crate::errors::*;
|
|||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum Credentials {
|
pub enum Credentials {
|
||||||
LongLived {
|
LongLived {
|
||||||
|
#[serde(rename = "AccessKeyId")]
|
||||||
access_key_id: String,
|
access_key_id: String,
|
||||||
|
#[serde(rename = "SecretAccessKey")]
|
||||||
secret_access_key: String,
|
secret_access_key: String,
|
||||||
},
|
},
|
||||||
ShortLived {
|
ShortLived {
|
||||||
|
#[serde(rename = "AccessKeyId")]
|
||||||
access_key_id: String,
|
access_key_id: String,
|
||||||
|
#[serde(rename = "SecretAccessKey")]
|
||||||
secret_access_key: String,
|
secret_access_key: String,
|
||||||
|
#[serde(rename = "Token")]
|
||||||
token: String,
|
token: String,
|
||||||
|
#[serde(rename = "Expiration")]
|
||||||
expiration: String,
|
expiration: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
async function approve() {
|
async function approve() {
|
||||||
let status = await invoke('get-session-status');
|
let status = await invoke('get_session_status');
|
||||||
if (status === 'unlocked') {
|
if (status === 'unlocked') {
|
||||||
dispatch('navigate', {target: 'ShowApproved'});
|
dispatch('navigate', {target: 'ShowApproved'});
|
||||||
}
|
}
|
||||||
|
41
src/views/EnterCredentials.svelte
Normal file
41
src/views/EnterCredentials.svelte
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount, createEventDispatcher } from 'svelte';
|
||||||
|
import { invoke } from '@tauri-apps/api/tauri';
|
||||||
|
|
||||||
|
export let appState;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher;
|
||||||
|
let AccessKeyId, SecretAccessKey, passphrase
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
try {
|
||||||
|
console.log('Saving credentials.');
|
||||||
|
let credentials = {AccessKeyId, SecretAccessKey};
|
||||||
|
console.log(credentials);
|
||||||
|
await invoke('save_credentials', {credentials, passphrase});
|
||||||
|
if (appState.currentRequest) {
|
||||||
|
dispatch('navigate', {target: 'Approve'})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dispatch('navigate', {target: Home})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log("Error saving credentials:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<form action="#" on:submit|preventDefault="{save}">
|
||||||
|
<div class="text-gray-200">AWS Access Key ID</div>
|
||||||
|
<input class="text-gray-200 bg-zinc-800" type="text" bind:value="{AccessKeyId}" />
|
||||||
|
|
||||||
|
<div class="text-gray-200">AWS Secret Access Key</div>
|
||||||
|
<input class="text-gray-200 bg-zinc-800" type="text" bind:value="{SecretAccessKey}" />
|
||||||
|
|
||||||
|
<div class="text-gray-200">Passphrase</div>
|
||||||
|
<input class="text-gray-200 bg-zinc-800" type="text" bind:value="{passphrase}" />
|
||||||
|
|
||||||
|
<input class="text-gray-200" type="submit" />
|
||||||
|
</form>
|
Loading…
x
Reference in New Issue
Block a user