From dd3e8e042613466a409ded907313028428170049 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Fri, 30 Jan 2015 12:54:45 -0700 Subject: [PATCH 1/3] make cred-New functions all sync --- generate/input/descriptor.json | 8 +++++++- test/tests/cred.js | 12 +++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 1301dbcfb..77e245df4 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -364,13 +364,16 @@ "cred": { "cType": "git_cred", "functions": { + "git_cred_default_new": { + "isAsync": false + }, "git_cred_ssh_custom_new": { "ignore": true }, "git_cred_ssh_interactive_new": { "ignore": true }, - "git_cred_ssh_key_from_agent":{ + "git_cred_ssh_key_from_agent": { "isAsync": false }, "git_cred_ssh_key_new": { @@ -378,6 +381,9 @@ }, "git_cred_userpass": { "ignore": true + }, + "git_cred_userpass_plaintext_new": { + "isAsync": false } } }, diff --git a/test/tests/cred.js b/test/tests/cred.js index 49cf86798..39d54ee4c 100644 --- a/test/tests/cred.js +++ b/test/tests/cred.js @@ -7,9 +7,8 @@ describe("Cred", function() { var sshPrivateKey = path.resolve("./id_rsa"); it("can create default credentials", function() { - NodeGit.Cred.defaultNew().then(function (defaultCreds) { - assert(defaultCreds instanceof NodeGit.Cred); - }); + var defaultCreds = NodeGit.Cred.defaultNew(); + assert(defaultCreds instanceof NodeGit.Cred); }); it("can create ssh credentials using passed keys", function() { @@ -23,9 +22,8 @@ describe("Cred", function() { }); it("can create credentials using plaintext", function() { - NodeGit.Cred.userpassPlaintextNew("username", "password") - .then(function (plaintextCreds) { - assert(plaintextCreds instanceof NodeGit.Cred); - }); + var plaintextCreds = NodeGit.Cred.userpassPlaintextNew + ("username", "password"); + assert(plaintextCreds instanceof NodeGit.Cred); }); }); From 12c0e5ec4449f3fda5cab8b268964a3884f6509d Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Fri, 30 Jan 2015 13:40:25 -0700 Subject: [PATCH 2/3] add example for using 2 factor auth --- examples/cloneFromGithubWith2Factor.js | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/cloneFromGithubWith2Factor.js diff --git a/examples/cloneFromGithubWith2Factor.js b/examples/cloneFromGithubWith2Factor.js new file mode 100644 index 000000000..f456c5d90 --- /dev/null +++ b/examples/cloneFromGithubWith2Factor.js @@ -0,0 +1,44 @@ +var nodegit = require("../"); +var promisify = require("promisify-node"); +var fse = promisify(require("fs-extra")); +var path = "/tmp/nodegit-github-2factor-demo"; + +var token = "{Your GitHub user token}"; +var repoOwner = "{The orgname or username that owns the repo}"; +var repoName = "{The name of the repo}"; + +// The token has to be included in the URL if the repo is private. +// Otherwise, github just wont respond, so a normal credential callback +// wont work. +var repoUrl = "https://" + token + + ":-oauth-basic@github.com/" + + repoOwner + "/" + + repoName + ".git"; + +var opts = { ignoreCertErrors: 1}; + +// If the repo is public, you can use a callback instead +var repoUrl = "https://github.com/" + repoOwner + "/" + repoName + ".git"; + +var opts = { + ignoreCertErrors: 1, + remoteCallbacks: { + credentials: function() { + return NodeGit.Cred.userpassPlaintextNew (token, "x-oauth-basic"); + } + } +} + +fse.remove(path).then(function() { + var entry; + + nodegit.Clone.clone(repoUrl, path, opts) + .done(function(repo) { + if (repo instanceof nodegit.Repository) { + console.info("We cloned the repo!"); + } + else { + console.error("Something borked :("); + } + }); +}); From 21c383d8e1c970679963c387a12637f37f8d790f Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Fri, 30 Jan 2015 13:46:08 -0700 Subject: [PATCH 3/3] fix linter --- examples/cloneFromGithubWith2Factor.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/cloneFromGithubWith2Factor.js b/examples/cloneFromGithubWith2Factor.js index f456c5d90..7b0dd6792 100644 --- a/examples/cloneFromGithubWith2Factor.js +++ b/examples/cloneFromGithubWith2Factor.js @@ -7,6 +7,10 @@ var token = "{Your GitHub user token}"; var repoOwner = "{The orgname or username that owns the repo}"; var repoName = "{The name of the repo}"; +// To clone with 2 factor auth enabled, you have to use a github oauth token +// over https, it can't be done with actual 2 factor. +// https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth + // The token has to be included in the URL if the repo is private. // Otherwise, github just wont respond, so a normal credential callback // wont work. @@ -24,14 +28,12 @@ var opts = { ignoreCertErrors: 1, remoteCallbacks: { credentials: function() { - return NodeGit.Cred.userpassPlaintextNew (token, "x-oauth-basic"); + return nodegit.Cred.userpassPlaintextNew (token, "x-oauth-basic"); } } -} +}; fse.remove(path).then(function() { - var entry; - nodegit.Clone.clone(repoUrl, path, opts) .done(function(repo) { if (repo instanceof nodegit.Repository) {