· 6 years ago · Apr 08, 2019, 08:46 PM
1// std dependencies
2use std::path::PathBuf;
3
4// internal dependencies
5use crate::config::Merger;
6
7// external dependencies
8use structopt::StructOpt;
9
10#[derive(Debug, StructOpt)]
11pub struct Opt {
12 #[structopt(long = "jwt-secret-key", env = "JWT_SECRET_KEY")]
13 pub secret_key: Option<String>,
14
15 #[structopt(long = "jwt-secret-key-file", env = "JWT_SECRET_KEY_FILE")]
16 pub secret_key_file: Option<PathBuf>,
17
18 /// Duration of life for newly generated JWT tokens
19 #[structopt(
20 long = "jwt-token-life-duration",
21 env = "JWT_TOKEN_LIFE_DURATION",
22 value_name = "DURATION"
23 )]
24 pub token_life_duration: Option<String>,
25}
26
27impl Merger for Opt {
28 fn merge(self, other_opt: Option<Self>) -> Self {
29 if let Some(other_opt) = other_opt {
30 let secret_key = self.secret_key.or(other_opt.secret_key);
31 let secret_key_file = self.secret_key_file.or(other_opt.secret_key_file);
32 let token_life_duration = self.token_life_duration.or(other_opt.token_life_duration);
33
34 return Self {
35 secret_key,
36 secret_key_file,
37 token_life_duration,
38 };
39 }
40
41 self
42 }
43}