Compare commits
1 Commits
persistent
...
a49bd47e8c
Author | SHA1 | Date | |
---|---|---|---|
a49bd47e8c |
@ -11,12 +11,11 @@ use std::{
|
|||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let global_matches = cli::parser().get_matches();
|
let res = match cli::parser().get_matches().subcommand() {
|
||||||
let res = match global_matches.subcommand() {
|
|
||||||
None | Some(("run", _)) => launch_gui(),
|
None | Some(("run", _)) => launch_gui(),
|
||||||
Some(("get", m)) => cli::get(m, &global_matches),
|
Some(("get", m)) => cli::get(m),
|
||||||
Some(("exec", m)) => cli::exec(m, &global_matches),
|
Some(("exec", m)) => cli::exec(m),
|
||||||
Some(("shortcut", m)) => cli::invoke_shortcut(m, &global_matches),
|
Some(("shortcut", m)) => cli::invoke_shortcut(m),
|
||||||
_ => unreachable!("Unknown subcommand"),
|
_ => unreachable!("Unknown subcommand"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,10 +102,10 @@ pub fn parser() -> Command<'static> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get(args: &ArgMatches, global_args: &ArgMatches) -> Result<(), CliError> {
|
pub fn get(args: &ArgMatches) -> Result<(), CliError> {
|
||||||
let name = args.get_one("name").cloned();
|
let name = args.get_one("name").cloned();
|
||||||
let base = *args.get_one("base").unwrap_or(&false);
|
let base = *args.get_one("base").unwrap_or(&false);
|
||||||
let addr = global_args.get_one("server_addr").cloned();
|
let addr = args.get_one("server_addr").cloned();
|
||||||
|
|
||||||
let output = match make_request(addr, &Request::GetAwsCredentials { name, base })? {
|
let output = match make_request(addr, &Request::GetAwsCredentials { name, base })? {
|
||||||
Response::AwsBase(creds) => serde_json::to_string(&creds).unwrap(),
|
Response::AwsBase(creds) => serde_json::to_string(&creds).unwrap(),
|
||||||
@ -117,10 +117,10 @@ pub fn get(args: &ArgMatches, global_args: &ArgMatches) -> Result<(), CliError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn exec(args: &ArgMatches, global_args: &ArgMatches) -> Result<(), CliError> {
|
pub fn exec(args: &ArgMatches) -> Result<(), CliError> {
|
||||||
let name = args.get_one("name").cloned();
|
let name = args.get_one("name").cloned();
|
||||||
let base = *args.get_one("base").unwrap_or(&false);
|
let base = *args.get_one("base").unwrap_or(&false);
|
||||||
let addr = global_args.get_one("server_addr").cloned();
|
let addr = args.get_one("server_addr").cloned();
|
||||||
let mut cmd_line = args.get_many("command")
|
let mut cmd_line = args.get_many("command")
|
||||||
.ok_or(ExecError::NoCommand)?;
|
.ok_or(ExecError::NoCommand)?;
|
||||||
|
|
||||||
@ -172,8 +172,8 @@ pub fn exec(args: &ArgMatches, global_args: &ArgMatches) -> Result<(), CliError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn invoke_shortcut(args: &ArgMatches, global_args: &ArgMatches) -> Result<(), CliError> {
|
pub fn invoke_shortcut(args: &ArgMatches) -> Result<(), CliError> {
|
||||||
let addr = global_args.get_one("server_addr").cloned();
|
let addr = args.get_one("server_addr").cloned();
|
||||||
let action = match args.get_one::<String>("action").map(|s| s.as_str()) {
|
let action = match args.get_one::<String>("action").map(|s| s.as_str()) {
|
||||||
Some("show_window") => ShortcutAction::ShowWindow,
|
Some("show_window") => ShortcutAction::ShowWindow,
|
||||||
Some("launch_terminal") => ShortcutAction::LaunchTerminal,
|
Some("launch_terminal") => ShortcutAction::LaunchTerminal,
|
||||||
|
@ -148,43 +148,6 @@ impl AwsSessionCredential {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, FromRow)]
|
|
||||||
pub struct AwsSessionRow {
|
|
||||||
version: i64,
|
|
||||||
base_id: Uuid,
|
|
||||||
access_key_id: String,
|
|
||||||
session_token: String,
|
|
||||||
secret_key_enc: Vec<u8>,
|
|
||||||
nonce: Vec<u8>,
|
|
||||||
expiration: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl PersistentCredential for AwsSessionCredential {
|
|
||||||
type Row = AwsSessionRow;
|
|
||||||
fn type_name() -> &'static str { "aws_session" }
|
|
||||||
fn into_credential(self) -> Credential { Credential::AwsSession(self) }
|
|
||||||
fn row_id(row: &AwsSessionRow) -> Uuid { row.base_id }
|
|
||||||
|
|
||||||
fn from_row(row: AwsSessionRow, crypto: &Crypto) -> Rsult<Self, LoadCredentialsError> {
|
|
||||||
let nonce = XNonce::clone_from_slice(&row.nonce);
|
|
||||||
let secret_key_bytes = crypto.decrypt(&nonce, &row.secret_key_enc)?;
|
|
||||||
let secret_access_key = String::from_utf8(secret_key_bytes)
|
|
||||||
.map_err(|_| LoadCredentialsError::InvalidData)?;
|
|
||||||
|
|
||||||
Ok(AwsSessionCredential {
|
|
||||||
version: row.version as usize,
|
|
||||||
access_key_id: row.access_key_id,
|
|
||||||
secret_access_key,
|
|
||||||
session_token: row.session_token,
|
|
||||||
expiration: DateTime::from_secs(row.expiration),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn save_details(&self, base_id: &Uuid, crypto: &Crypto, txn: &mut Transaction)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn default_credentials_version() -> usize { 1 }
|
fn default_credentials_version() -> usize { 1 }
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user