Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root directory can now be specified #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions authn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ trait AuthenticatorTrait {

struct Authenticator {
ca: Vec<u8>,
root_dir: String,
}

impl AuthenticatorTrait for Authenticator {
Expand All @@ -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,
};
Expand Down Expand Up @@ -107,8 +108,8 @@ impl AuthenticatorTrait for Authenticator {
}
}

fn start() -> Result<Authenticator, SomeError> {
let mut authenticator = Authenticator { ca: vec![] };
fn start(root_dir: &str) -> Result<Authenticator, SomeError> {
let mut authenticator = Authenticator { ca: vec![], root_dir: root_dir.to_owned() };

match authenticator.get_ca() {
Ok(_) => Ok(authenticator),
Expand All @@ -120,8 +121,7 @@ pub enum SomeError {
FailedToRunOpenssl,
}

fn generate_root_ca() -> Result<Vec<u8>, SomeError> {
let my_dir = env!("PWD");
fn generate_root_ca(my_dir: String) -> Result<Vec<u8>, SomeError> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not a &str?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was getting lifetime issues and i don't quite understand them yet.

let ca_crt = format!("{}{}", &my_dir, "/pki/ca.crt");
let ca_key = format!("{}{}", &my_dir, "/pki/ca.key");
let output = Command::new("openssl")
Expand Down Expand Up @@ -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)
}
Expand All @@ -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) => {
Expand Down
1 change: 0 additions & 1 deletion authz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@
* limitations under the License. *
* *
\* -------------------------------------------------------------------------- */