Skip to content
Open
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
18 changes: 16 additions & 2 deletions libexec/dockerize-github
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ then
exit 1
fi

echo "Check whether any of the user's private keys have access to github"

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Author

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?

Pseudo-terminal will not be allocated because stdin is not a terminal.
Hi sourishkrout! You've successfully authenticated, but GitHub does not provide shell access.
Skipping github credentials. Using ssh agent instead.

Copy link
Copy Markdown
Contributor

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:

github_ssh_connection="$(ssh -Aq -o BatchMode=yes -o ConnectTimeout=1 git@github.com 2>&1)"

if [[ $github_ssh_connection =~ "successfully authenticated" ]]
then
  # ...
fi

The ssh command explained.

ssh -nA git@github.com > /dev/null
if [ $? -eq 1 ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[[ are preferable over [ in bash scripting - good explanation on the differences. POSIX portability is less important for Dockerize over consistency and improved behaviour.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Happy to change to [[. However, aren't all the other if's using [ too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're right, I will ensure everything is using [[ consistently in a separate commit. Thanks for pointing it out.

then
ssh_agent_forwarding="1"
echo "Skipping github credentials. Using ssh agent instead."

Copy link
Copy Markdown
Contributor

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 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 authenticate_with_ssh_key="yes"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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=(
Expand Down Expand Up @@ -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" ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 https://github.com/ vs git@github.com:. How about setting this when we check for successful ssh authentication, something along the lines: clone_url_type="git@github.com:" if ssh auth is successful, clone_url_type="https://github.com/" otherwise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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"
Expand Down