DEV Community

Cover image for Cloud Function GitHub Update
Alex Patterson for CodingCatDev

Posted on • Originally published at codingcat.dev

Cloud Function GitHub Update

Authentication using Nodegit

nodegit
Authentication has become the biggest prolem with this entire process! I have added a comment to Issue 1035 but I don't know if it will get much traction as it seems there have been several issues out there already.

Failed Attempts

All of these attempts of course work for cloning, because I do not think it really checks

  • sshKeyNew
return NodeGit.Cred.sshKeyNew( "username", publicKeyContents, privateKeyContents, "").then(function(cred) { assert.ok(cred instanceof NodeGit.Cred); });

Enter fullscreen mode Exit fullscreen mode
  • userpassPlaintextNew sh return NodeGit.Cred.userpassPlaintextNew(GITHUB_TOKEN, "x-oauth-basic");
### Successful Attempt - **sshKeyFromAgent** ```

sh return nodegit.Cred.sshKeyFromAgent(userName);



Enter fullscreen mode Exit fullscreen mode

Cloud Funcitons

So the above sshKeyFromAgent works great while I am on my local Dev box (MacOS 10.14) after running the command ssh-add. I am currently running Node v10.14.1.I thought that it would be easy enough to do the same on a cloud function, but this took some digging. I then found out that Node 6 base image is on Debian, I thought it was Alpine.Interestingly they changed this in Node 8 base image to running Ubuntu 18.04, so I will have to keep an eye on this if Upgrading.

As many great things in life, sometimes you dribble down a lane that is direct into a double team...so you must pivot to score. (Wow it must be late, basketball analogies are showing up!)

simple-git aka git-js

I ended up switching to simple-git as nodegit ssh issues had me 2 days behind on trying to get out lesson 8. It provides a very simple interface to effectively accomplish everything I needed. It also allows me to use a personal token to do Git updates to GitHub which I liked a lot better.

Top comments (0)