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 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)?;
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ fn main() {
|
||||
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();
|
||||
@ -33,12 +34,4 @@ fn main() {
|
||||
})
|
||||
.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)]
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
async function approve() {
|
||||
let status = await invoke('get-session-status');
|
||||
let status = await invoke('get_session_status');
|
||||
if (status === 'unlocked') {
|
||||
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