aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-19 20:26:35 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-19 20:26:35 -0400
commit44f0f76c906d3fabe592958c208c0782a1d9305a (patch)
tree55079205aafcfcc3fdcaae7eb1323bc042b93a2f
parentca2f934b014a733121d57475e793e0dad53f7aa9 (diff)
downloadrbw-44f0f76c906d3fabe592958c208c0782a1d9305a.tar.gz
rbw-44f0f76c906d3fabe592958c208c0782a1d9305a.zip
allow creating entries with associated uris
-rw-r--r--src/actions.rs6
-rw-r--r--src/api.rs11
-rw-r--r--src/bin/rbw/commands.rs17
-rw-r--r--src/bin/rbw/main.rs26
4 files changed, 56 insertions, 4 deletions
diff --git a/src/actions.rs b/src/actions.rs
index 0a5bee4..f0d5d21 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -77,9 +77,10 @@ pub fn add(
username: Option<&str>,
password: Option<&str>,
notes: Option<&str>,
+ uris: &[String],
) -> Result<(Option<String>, ())> {
with_exchange_refresh_token(access_token, refresh_token, |access_token| {
- add_once(access_token, name, username, password, notes)
+ add_once(access_token, name, username, password, notes, uris)
})
}
@@ -89,11 +90,12 @@ fn add_once(
username: Option<&str>,
password: Option<&str>,
notes: Option<&str>,
+ uris: &[String],
) -> Result<()> {
let config = crate::config::Config::load()?;
let client =
crate::api::Client::new(&config.base_url(), &config.identity_url());
- client.add(access_token, name, username, password, notes)?;
+ client.add(access_token, name, username, password, notes, uris)?;
Ok(())
}
diff --git a/src/api.rs b/src/api.rs
index 44e53a4..aa36f47 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -150,6 +150,12 @@ struct CiphersPostReq {
struct CiphersPostReqLogin {
username: Option<String>,
password: Option<String>,
+ uris: Vec<CiphersPostReqLoginUri>,
+}
+
+#[derive(serde::Serialize, Debug)]
+struct CiphersPostReqLoginUri {
+ uri: String,
}
#[derive(serde::Serialize, Debug)]
@@ -292,6 +298,7 @@ impl Client {
username: Option<&str>,
password: Option<&str>,
notes: Option<&str>,
+ uris: &[String],
) -> Result<()> {
let req = CiphersPostReq {
ty: 1,
@@ -300,6 +307,10 @@ impl Client {
login: CiphersPostReqLogin {
username: username.map(std::string::ToString::to_string),
password: password.map(std::string::ToString::to_string),
+ uris: uris
+ .iter()
+ .map(|s| CiphersPostReqLoginUri { uri: s.to_string() })
+ .collect(),
},
};
let client = reqwest::blocking::Client::new();
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs
index 839dca3..2385163 100644
--- a/src/bin/rbw/commands.rs
+++ b/src/bin/rbw/commands.rs
@@ -129,7 +129,11 @@ pub fn get(name: &str, user: Option<&str>, full: bool) -> anyhow::Result<()> {
Ok(())
}
-pub fn add(name: &str, username: Option<&str>) -> anyhow::Result<()> {
+pub fn add(
+ name: &str,
+ username: Option<&str>,
+ uris: Vec<&str>,
+) -> anyhow::Result<()> {
unlock()?;
let email = config_email()?;
@@ -154,6 +158,10 @@ pub fn add(name: &str, username: Option<&str>) -> anyhow::Result<()> {
let notes = notes
.map(|notes| crate::actions::encrypt(&notes))
.transpose()?;
+ let uris: Vec<String> = uris
+ .iter()
+ .map(|uri| crate::actions::encrypt(&uri))
+ .collect::<anyhow::Result<_>>()?;
if let (Some(access_token), ()) = rbw::actions::add(
&access_token,
@@ -162,6 +170,7 @@ pub fn add(name: &str, username: Option<&str>) -> anyhow::Result<()> {
username.as_deref(),
password.as_deref(),
notes.as_deref(),
+ &uris,
)? {
db.access_token = Some(access_token);
db.save(&email).context("failed to save database")?;
@@ -175,6 +184,7 @@ pub fn add(name: &str, username: Option<&str>) -> anyhow::Result<()> {
pub fn generate(
name: Option<&str>,
username: Option<&str>,
+ uris: Vec<&str>,
len: usize,
ty: rbw::pwgen::Type,
) -> anyhow::Result<()> {
@@ -196,6 +206,10 @@ pub fn generate(
.map(|username| crate::actions::encrypt(username))
.transpose()?;
let password = crate::actions::encrypt(&password)?;
+ let uris: Vec<String> = uris
+ .iter()
+ .map(|uri| crate::actions::encrypt(&uri))
+ .collect::<anyhow::Result<_>>()?;
if let (Some(access_token), ()) = rbw::actions::add(
&access_token,
@@ -204,6 +218,7 @@ pub fn generate(
username.as_deref(),
Some(&password),
None,
+ &uris,
)? {
db.access_token = Some(access_token);
db.save(&email).context("failed to save database")?;
diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs
index 31f7fd0..051a7bc 100644
--- a/src/bin/rbw/main.rs
+++ b/src/bin/rbw/main.rs
@@ -36,13 +36,29 @@ fn main() {
.subcommand(
clap::SubCommand::with_name("add")
.arg(clap::Arg::with_name("name").required(true))
- .arg(clap::Arg::with_name("user")),
+ .arg(clap::Arg::with_name("user"))
+ .arg(
+ clap::Arg::with_name("uri")
+ .long("uri")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1)
+ .use_delimiter(false),
+ ),
)
.subcommand(
clap::SubCommand::with_name("generate")
.arg(clap::Arg::with_name("len").required(true))
.arg(clap::Arg::with_name("name"))
.arg(clap::Arg::with_name("user"))
+ .arg(
+ clap::Arg::with_name("uri")
+ .long("uri")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1)
+ .use_delimiter(false),
+ )
.arg(clap::Arg::with_name("no-symbols").long("no-symbols"))
.arg(
clap::Arg::with_name("only-numbers").long("only-numbers"),
@@ -111,6 +127,10 @@ fn main() {
("add", Some(smatches)) => commands::add(
smatches.value_of("name").unwrap(),
smatches.value_of("user"),
+ smatches
+ .values_of("uri")
+ .map(|it| it.collect())
+ .unwrap_or_else(|| vec![]),
)
.context("add"),
("generate", Some(smatches)) => {
@@ -131,6 +151,10 @@ fn main() {
Ok(len) => commands::generate(
smatches.value_of("name"),
smatches.value_of("user"),
+ smatches
+ .values_of("uri")
+ .map(|it| it.collect())
+ .unwrap_or_else(|| vec![]),
len,
ty,
)