Move flag requirements for credentials to subcommands that need it.
This commit is contained in:
parent
88234c156c
commit
48da92e278
65
Cargo.lock
generated
65
Cargo.lock
generated
@ -53,7 +53,7 @@ version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"byteorder 1.3.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -76,7 +76,7 @@ checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
|
||||
dependencies = [
|
||||
"block-padding",
|
||||
"byte-tools",
|
||||
"byteorder",
|
||||
"byteorder 1.3.4",
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
@ -111,6 +111,12 @@ version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.3.4"
|
||||
@ -123,7 +129,7 @@ version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"byteorder 1.3.4",
|
||||
"either",
|
||||
"iovec",
|
||||
]
|
||||
@ -494,7 +500,7 @@ version = "0.1.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"byteorder 1.3.4",
|
||||
"bytes 0.4.12",
|
||||
"fnv",
|
||||
"futures",
|
||||
@ -645,7 +651,7 @@ dependencies = [
|
||||
"itoa",
|
||||
"log 0.4.8",
|
||||
"net2",
|
||||
"rustc_version",
|
||||
"rustc_version 0.2.3",
|
||||
"time",
|
||||
"tokio 0.1.22",
|
||||
"tokio-buf",
|
||||
@ -881,7 +887,7 @@ version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
"rustc_version 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1010,6 +1016,12 @@ dependencies = [
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "1.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "4.2.3"
|
||||
@ -1102,7 +1114,7 @@ checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
"parking_lot_core",
|
||||
"rustc_version",
|
||||
"rustc_version 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1115,7 +1127,7 @@ dependencies = [
|
||||
"cloudabi",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"rustc_version",
|
||||
"rustc_version 0.2.3",
|
||||
"smallvec 0.6.13",
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
@ -1286,6 +1298,18 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "procinfo"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f42e8578852a3306838981aedad8c5642ba794929aa12af0c9eb6c072b77af6c"
|
||||
dependencies = [
|
||||
"byteorder 0.5.3",
|
||||
"libc",
|
||||
"nom 1.2.4",
|
||||
"rustc_version 0.1.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prometheus"
|
||||
version = "0.7.0"
|
||||
@ -1295,6 +1319,8 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"fnv",
|
||||
"lazy_static 1.4.0",
|
||||
"libc",
|
||||
"procinfo",
|
||||
"protobuf",
|
||||
"quick-error",
|
||||
"spin",
|
||||
@ -1574,13 +1600,22 @@ dependencies = [
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
|
||||
dependencies = [
|
||||
"semver 0.1.20",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver",
|
||||
"semver 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1684,6 +1719,12 @@ dependencies = [
|
||||
"core-foundation-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.1.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
@ -1932,7 +1973,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dafb35214e317d6c0a72b16d1aa667bbc0fea57e302798e7bc520e0f39988006"
|
||||
dependencies = [
|
||||
"base64 0.10.1",
|
||||
"byteorder",
|
||||
"byteorder 1.3.4",
|
||||
"chrono",
|
||||
"rand 0.6.5",
|
||||
"serde",
|
||||
@ -2257,7 +2298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a0c2bd5aeb7dcd2bb32e472c8872759308495e5eccc942e929a513cd8d36110"
|
||||
dependencies = [
|
||||
"base64 0.11.0",
|
||||
"byteorder",
|
||||
"byteorder 1.3.4",
|
||||
"bytes 0.4.12",
|
||||
"http 0.1.21",
|
||||
"httparse",
|
||||
@ -2592,7 +2633,7 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bb43f70885151e629e2a19ce9e50bd730fd436cfd4b666894c9ce4de9141164"
|
||||
dependencies = [
|
||||
"nom",
|
||||
"nom 4.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@ -20,4 +20,7 @@ stderrlog = "0.4.3"
|
||||
structopt = "0.3.9"
|
||||
yup-oauth2 = "^3.1"
|
||||
warp = "0.1"
|
||||
prometheus = "0.7.0"
|
||||
|
||||
[dependencies.prometheus]
|
||||
features = ["process"]
|
||||
version = "0.7.0"
|
||||
|
||||
37
src/main.rs
37
src/main.rs
@ -23,12 +23,18 @@ mod web;
|
||||
enum Command {
|
||||
/// List albums for the user of the given credentials. Optionally title filter.
|
||||
ListAlbums {
|
||||
#[structopt(flatten)]
|
||||
auth: Auth,
|
||||
title_filter: Option<Regex>,
|
||||
},
|
||||
SearchMediaItems {
|
||||
#[structopt(flatten)]
|
||||
auth: Auth,
|
||||
album_id: String,
|
||||
},
|
||||
Sync {
|
||||
#[structopt(flatten)]
|
||||
auth: Auth,
|
||||
/// Optional album title to filter. Default will mirror all albums.
|
||||
#[structopt(short, long)]
|
||||
title_filter: Option<Regex>,
|
||||
@ -44,6 +50,16 @@ enum Command {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
struct Auth {
|
||||
/// Path to json file containing Google client ID and secrets for out of band auth flow.
|
||||
#[structopt(long)]
|
||||
credentials: PathBuf,
|
||||
/// Path to json file where photosync will store auth tokens refreshed from Google.
|
||||
#[structopt(long)]
|
||||
token_cache: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(
|
||||
name = "photosync",
|
||||
@ -54,13 +70,6 @@ struct Opt {
|
||||
#[structopt(short, parse(from_occurrences))]
|
||||
verbose: usize,
|
||||
|
||||
/// Path to json file containing Google client ID and secrets for out of band auth flow.
|
||||
#[structopt(long)]
|
||||
credentials: PathBuf,
|
||||
/// Path to json file where photosync will store auth tokens refreshed from Google.
|
||||
#[structopt(long)]
|
||||
token_cache: PathBuf,
|
||||
|
||||
#[structopt(subcommand)]
|
||||
cmd: Command,
|
||||
}
|
||||
@ -300,20 +309,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.init()
|
||||
.unwrap();
|
||||
debug!("opt: {:?}", opt);
|
||||
let client = new_client(&opt.credentials, &opt.token_cache)?;
|
||||
match opt.cmd {
|
||||
Command::ListAlbums { title_filter } => {
|
||||
Command::ListAlbums { auth, title_filter } => {
|
||||
let client = new_client(&auth.credentials, &auth.token_cache)?;
|
||||
print_albums(list_albums(&client, title_filter)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::SearchMediaItems { album_id } => {
|
||||
Command::SearchMediaItems { auth, album_id } => {
|
||||
let client = new_client(&auth.credentials, &auth.token_cache)?;
|
||||
print_media_items(search_media_items(&client, &album_id)?);
|
||||
Ok(())
|
||||
}
|
||||
Command::Sync {
|
||||
auth,
|
||||
title_filter,
|
||||
output,
|
||||
} => sync_albums(&client, title_filter, output),
|
||||
} => {
|
||||
let client = new_client(&auth.credentials, &auth.token_cache)?;
|
||||
sync_albums(&client, title_filter, output)?;
|
||||
Ok(())
|
||||
}
|
||||
Command::Serve { addr, root } => serve(addr, root),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ use std::error::Error;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use log::info;
|
||||
use prometheus::Encoder;
|
||||
use warp;
|
||||
use warp::http::header::{HeaderMap, HeaderValue};
|
||||
@ -37,7 +38,7 @@ pub fn run(addr: SocketAddr, root: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
//let api = api.or(index);
|
||||
let api = index;
|
||||
|
||||
let api = api.with(warp::log("moviewatcher"));
|
||||
let api = api.with(warp::log("photosync"));
|
||||
// We don't want metrics & heath checking filling up the logs, so we add this handler after
|
||||
// wrapping with the log filter.
|
||||
let routes = metrics().or(api);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user