From 6bd0c250c6d85e670945b5397c78c8fe2aa21e89 Mon Sep 17 00:00:00 2001 From: Tani <111664369+taniwha3@users.noreply.github.com> Date: Mon, 26 Sep 2022 23:36:22 -0700 Subject: [PATCH] the root directory of authn can now be specified Signed-off-by: Tani <111664369+taniwha3@users.noreply.github.com> --- authn/src/lib.rs | 14 +++++++------- authz/src/lib.rs | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/authn/src/lib.rs b/authn/src/lib.rs index e6d844f..bfb975d 100644 --- a/authn/src/lib.rs +++ b/authn/src/lib.rs @@ -45,6 +45,7 @@ trait AuthenticatorTrait { struct Authenticator { ca: Vec, + root_dir: String, } impl AuthenticatorTrait for Authenticator { @@ -63,7 +64,7 @@ impl AuthenticatorTrait for Authenticator { match self.ca.len() { 0 => { println!("no CA found, generating..."); - self.ca = match generate_root_ca() { + self.ca = match generate_root_ca(self.root_dir.to_owned()) { Ok(cert) => cert, err => return err, }; @@ -107,8 +108,8 @@ impl AuthenticatorTrait for Authenticator { } } -fn start() -> Result { - let mut authenticator = Authenticator { ca: vec![] }; +fn start(root_dir: &str) -> Result { + let mut authenticator = Authenticator { ca: vec![], root_dir: root_dir.to_owned() }; match authenticator.get_ca() { Ok(_) => Ok(authenticator), @@ -120,8 +121,7 @@ pub enum SomeError { FailedToRunOpenssl, } -fn generate_root_ca() -> Result, SomeError> { - let my_dir = env!("PWD"); +fn generate_root_ca(my_dir: String) -> Result, SomeError> { let ca_crt = format!("{}{}", &my_dir, "/pki/ca.crt"); let ca_key = format!("{}{}", &my_dir, "/pki/ca.key"); let output = Command::new("openssl") @@ -317,7 +317,7 @@ mod tests { #[test] fn test_new_ca() { - match generate_root_ca() { + match generate_root_ca(env!("PWD").to_owned()) { Ok(x) => { println!("ca:\n{:#?}", x) } @@ -341,7 +341,7 @@ mod tests { #[test] fn test_workflow() { - match start() { + match start(env!("PWD")) { Ok(mut authenticator) => { match authenticator.get_workload_certificate("hello") { Ok(cert) => { diff --git a/authz/src/lib.rs b/authz/src/lib.rs index b0a1b56..c7d58cd 100644 --- a/authz/src/lib.rs +++ b/authz/src/lib.rs @@ -27,4 +27,3 @@ * limitations under the License. * * * \* -------------------------------------------------------------------------- */ -