-
Notifications
You must be signed in to change notification settings - Fork 2
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
Made new-user commit its changes #14
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4591518
new-user changes to protonfile now committed
bookdude13 9144162
Cleaned up finding HEAD commit. Added test check for hanging commits
bookdude13 34abbfa
Suggestions. Modified commit_file to keep things in scope
bookdude13 d3d6a06
stuf
bookdude13 fc54755
Got rid of ugly Ok(())
bookdude13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ use self::openssl::crypto::rsa::RSA as openssl_RSA; | |
use self::openssl::crypto::hash::Type as openssl_HashType; | ||
use self::openssl::ssl::error::SslError as openssl_Error; | ||
|
||
use git2::Signature; | ||
|
||
use Error; | ||
use User; | ||
use utils; | ||
|
@@ -21,12 +23,21 @@ use utils; | |
/// | ||
/// Impure. | ||
pub fn new_user<P: AsRef<Path>>(public_key_path: P, name: &str) -> Result<(), Error> { | ||
// Add user | ||
let pub_key = try!(get_public_key(public_key_path)); | ||
let project = try!(utils::read_protonfile(None::<P>)); | ||
let new_project = try!(project.add_user(name, &pub_key)); | ||
utils::write_protonfile(&new_project, None::<P>) | ||
} | ||
let new_project = try!(project.add_user(&name, &pub_key)); | ||
try!(utils::write_protonfile(&new_project, None::<P>)); | ||
|
||
// Commit changes | ||
let signature = Signature::now("Proton Lights", "[email protected]").unwrap(); | ||
let msg = format!("Adding {} as new user", name); | ||
let pf_path = Path::new("Protonfile.json"); | ||
let repo_path: Option<P> = None; | ||
|
||
utils::commit_file(&pf_path, repo_path, &signature, &msg) | ||
.map(|_| ()) | ||
} | ||
/// Identifies a user by their private SSH key by finding the | ||
/// corresponding public key in the project. This private key | ||
/// acts like the user's password, and should be protected. | ||
|
@@ -77,4 +88,5 @@ fn invalid_pub_key_error(key: &str) -> Error { | |
|
||
fn ssl_error(e: openssl_Error) -> Error { | ||
Error::Ssl(e) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so I don't really like these changes. It seems like it got more complex. I think how you had it before was better. The only change I was looking for was that line 22 changed from a discarding assignment to a return.
I really dislike the code pattern where we have a bunch of stuff tryed! and then ended with an
Ok(())
. I think you should just get rid of the last try! and change it to a return with a.map(|_| OK(()))
. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it's ugly. Didn't know how to make the map work before, but figured it out. Lmk if still could be improved. Some/all of the
try!()
statements have to stay, in order to keeprepo
in scope.