-
Notifications
You must be signed in to change notification settings - Fork 14
Use Git + SSH to do authentication #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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,14 @@ then | |
| exit 1 | ||
| fi | ||
|
|
||
| echo "Check whether any of the user's private keys have access to github" | ||
| ssh -nA git@github.com > /dev/null | ||
| if [ $? -eq 1 ] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to change to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I will ensure everything is using |
||
| then | ||
| ssh_agent_forwarding="1" | ||
| echo "Skipping github credentials. Using ssh agent instead." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that this message is interesting for the end-user. I do think that a good variable name would make the code a lot better over a comment. What are your thoughts on
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
| fi | ||
|
|
||
| # Setting up github credentials caching | ||
| # There are 2 requirements for this: | ||
| # 1. git >= 1.7.9 | ||
|
|
@@ -39,7 +47,8 @@ fi | |
| # * https://www.kernel.org/pub/software/scm/git/docs/git-credential-store.html | ||
| # * https://help.github.com/articles/set-up-git | ||
| # | ||
| if [[ ! -e "$HOME/.git-credentials" && ! -e "$HOME/.no_prompting_for_git_credentials" ]] | ||
|
|
||
| if [[ -z $ssh_agent_forwarding && ! -e "$HOME/.git-credentials" && ! -e "$HOME/.no_prompting_for_git_credentials" ]] | ||
| then | ||
| echo "Should git manage github credentials?" | ||
| github_credentials_options=( | ||
|
|
@@ -87,7 +96,12 @@ cloned_repository="$DOCKER_GITHUB_REPOS/$docker_image" | |
|
|
||
| if [ ! -e "$cloned_repository" ] | ||
| then | ||
| $__exec "git clone https://github.com/${github_repo}.git $cloned_repository" | ||
| if [ -z "$ssh_agent_forwarding" ] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting the first part of the cloned URI would make the code a lot cleaner and thus easier to maintain. The only thing that is different is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I'll push a change. |
||
| then | ||
| $__exec "git clone https://github.com/${github_repo}.git $cloned_repository" | ||
| else | ||
| $__exec "git clone git@github.com:${github_repo}.git $cloned_repository" | ||
| fi | ||
| $__exec "cd $cloned_repository" | ||
| else | ||
| $__exec "cd $cloned_repository && git fetch" | ||
|
|
||
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.
I don't think that this message is useful for someone that just wants the end-result of this command. It's a detail which is relevant for the developer, sure, so a comment would be more appropriate IMO.
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.
I agree. Couldn't manage to have ssh not print the message down below. That's why I had this message. Any idea how to get this to go to /dev/null?
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.
I've only just noticed that you're checking for the exit code to be 1. The only successful error code is 0, so anything else points to an error. In this specific case, GitHub is saying that it doesn't allow shell access. Using 1 for the exit code is appropriate as given the ssh command, one would expect a TTY. I think this is more robust:
The ssh command explained.