diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-11-09 10:31:53 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-11-09 10:31:53 +0200 |
commit | bb230ab8ba940d009995d0a9806b2a3ebf830fe3 (patch) | |
tree | 0cc18bd73249d3e5cdb242e3f3aea2632a4fe3c0 | |
parent | 73bcd737cfb51d617db8d059b6269a7c5a0e3127 (diff) | |
download | sshca-bb230ab8ba940d009995d0a9806b2a3ebf830fe3.tar.gz |
refactor: set host principals using builder pattern
Sponsored-by: author
-rw-r--r-- | src/cmd/host.rs | 6 | ||||
-rw-r--r-- | src/info.rs | 16 | ||||
-rw-r--r-- | src/store.rs | 2 |
3 files changed, 12 insertions, 12 deletions
diff --git a/src/cmd/host.rs b/src/cmd/host.rs index d93bb3d..2331a6b 100644 --- a/src/cmd/host.rs +++ b/src/cmd/host.rs @@ -130,7 +130,7 @@ impl Runnable for New { } else { self.principals.to_vec() }; - let host = info::Host::new(public, None, self.hostname.clone(), principals); + let host = info::Host::new(public, None, self.hostname.clone()).with_principals(principals); store.insert_host(host).map_err(CAError::KeyStoreError)?; Ok(()) } @@ -282,8 +282,8 @@ impl Runnable for Generate { pair.public().clone(), Some(pair.private().clone()), self.hostname.clone(), - principals, - ); + ) + .with_principals(principals); store.insert_host(host).map_err(CAError::KeyStoreError)?; Ok(()) } diff --git a/src/info.rs b/src/info.rs index 287f50c..16ed18d 100644 --- a/src/info.rs +++ b/src/info.rs @@ -67,22 +67,22 @@ pub struct Host { } impl Host { - pub fn new( - public: PublicKey, - private: Option<PrivateKey>, - name: String, - principals: Vec<String>, - ) -> Self { + pub fn new(public: PublicKey, private: Option<PrivateKey>, name: String) -> Self { Self { public, private, valid_until: None, name, - principals, + principals: vec![], } } - pub fn valid_until(mut self, timestamp: String) -> Self { + pub fn with_principals(mut self, principals: Vec<String>) -> Self { + self.principals = principals; + self + } + + pub fn with_valid_until(mut self, timestamp: String) -> Self { self.valid_until = Some(timestamp); self } diff --git a/src/store.rs b/src/store.rs index f3ed0d7..17982b0 100644 --- a/src/store.rs +++ b/src/store.rs @@ -294,8 +294,8 @@ mod test { PublicKey::new("dummy-public".into()), Some(PrivateKey::new("dummy-private".into())), "dummy-host".into(), - vec!["dummy-host".into()], ) + .with_principals(vec!["dummy-host".into()]) } fn dummy_user() -> User { |