Skip to content

Instantly share code, notes, and snippets.

@ozten
Created October 3, 2012 20:06
Show Gist options
  • Select an option

  • Save ozten/3829510 to your computer and use it in GitHub Desktop.

Select an option

Save ozten/3829510 to your computer and use it in GitHub Desktop.
REST Discussion
Problem I use a CLI to start a build on jenkins.mozilla.org, which is password authenticated
and requires me to be [email protected]
Example Usage:
$ ./start-build.js [email protected] --project=mozilla/browserid --branch=train-2012-04-12
Password: 324klj234kl3j4
Build Success, 42 unit tests passed, rpm built, have a nice day
$
=====================================================
start-build.js Sketch:
#!/bin/env node
// Our Jenkin's instance
var RP = 'https://jenkins.mozilla.org';
var args = require('./lib/args'),
persona = require('persona-cli'),
jenkins = require('jenkins');
var buildCallback = function (err, buildOutput) {
if (err) {
console.error("Build failed!");
console.error(buildOutput);
process.exit(1);
} else {
console.log(buildOutput);
}
};
persona.login(RP, args.user, function (assertion) {
jenkins.startBuild({
assertion: assertion,
project: args.project,
branch: args.branch,
jenkinsHost: RP
}, buildCallback);
}):
=====================================================
persona.js Sketch:
var bid = require('lib/browserid');
exports.login = function (relyingParty, email) {
// Use Secondary? Use Primary?
bid.checkPrimary(email, function (isPrimary, primaryUrls) {
var urls;
if (isPrimary) {
urls = primaryUrls;
} else {
urls = {
auth: "https://login.persona.org/auth",
prov: "https://login.persona.org/provision"
}
}
});
process.stdout.write('Password');
var pass = "";
while (var c = process.stdin.read()) {
pass += c;
}
}
=====================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment