Skip to content
Browse files

big refactoring

  • Loading branch information...
1 parent e1116bb commit 3fef84836bf496dcd10dd66189cdead3be68a523 @pj4533 committed Jan 25, 2013
Showing with 302 additions and 210 deletions.
  1. +115 −71 lib/appids.js
  2. +33 −39 lib/authentication.js
  3. +111 −70 lib/certificates.js
  4. +13 −27 lib/lightman.js
  5. +27 −0 lib/teams.js
  6. +2 −1 package.json
  7. +1 −2 utils/createCSR.sh
View
186 lib/appids.js
@@ -1,96 +1,140 @@
+var keychain = require('keychain');
+var world = require('./world').World;
+var authentication = require('./authentication');
+
var createNewAppID = function (bundlename,bundleid) {
- // go to the App IDs section
- spooky.then(function() {
- this.clickLabel('App IDs','a');
- });
+ keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
+ keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
+ if (password == null) {
+ console.log("Not logged in");
+ } else {
+ world(function(world) {
- // click new app id
- spooky.then(function() {
- this.click('[href="/ios/manage/bundles/add.action"]');
- });
+ authentication.authenticate(username,password);
- // fill in new app id form
- spooky.then([{bundlename:bundlename,bundleid:bundleid},function() {
- this.fill('form#save', {
- 'bundleName': bundlename,
- 'bundleIdentifier': bundleid
- }, true);
- }]);
+ // go into the provisioning portal
+ spooky.then(function() {
+ this.clickLabel('iOS Provisioning Portal','a');
+ });
+
+ // go to the App IDs section
+ spooky.then(function() {
+ this.clickLabel('App IDs','a');
+ });
+
+ // click new app id
+ spooky.then(function() {
+ this.click('[href="/ios/manage/bundles/add.action"]');
+ });
+ // fill in new app id form
+ spooky.then([{bundlename:bundlename,bundleid:bundleid},function() {
+ this.fill('form#save', {
+ 'bundleName': bundlename,
+ 'bundleIdentifier': bundleid
+ }, true);
+ }]);
+
+ spooky.run();
+
+ });
+ }
+ });
+ });
};
var configureAppIDForDistPush = function (csr,bundlename) {
- // go to the App IDs section
- spooky.then(function() {
- this.clickLabel('App IDs','a');
- });
+ keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
+ keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
+ if (password == null) {
+ console.log("Not logged in");
+ } else {
+ world(function(world) {
+
+ authentication.authenticate(username,password);
+
+ // go into the provisioning portal
+ spooky.then(function() {
+ this.clickLabel('iOS Provisioning Portal','a');
+ });
+
+ // go to the App IDs section
+ spooky.then(function() {
+ this.clickLabel('App IDs','a');
+ });
- spooky.then([{bundlename:bundlename},function() {
- var href = this.evaluate(function(bundlename) {
- return $('td.name:contains("' + bundlename + '")').parents('tr').children('td:last').children('a').attr('href');
- }, bundlename);
- console.log("HREF: " + href);
- this.click('[href="'+ href + '"]');
- }]);
+ spooky.then([{bundlename:bundlename},function() {
+ var href = this.evaluate(function(bundlename) {
+ return $('td.name:contains("' + bundlename + '")').parents('tr').children('td:last').children('a').attr('href');
+ }, bundlename);
+ console.log("HREF: " + href);
+ this.click('[href="'+ href + '"]');
+ }]);
- spooky.then(function() {
- this.click('[id="enablePush"]');
- });
+ spooky.then(function() {
+ this.click('[id="enablePush"]');
+ });
- spooky.then(function() {
- this.click('[id="aps-assistant-btn-prod-en"]');
- })
+ spooky.then(function() {
+ this.click('[id="aps-assistant-btn-prod-en"]');
+ })
- spooky.wait(5000, function() {
- this.echo("WAITED 5 SECS");
- });
+ spooky.wait(5000, function() {
+ this.echo("WAITED 5 SECS");
+ });
- spooky.then(function() {
- this.click('[id="ext-gen59"]');
- })
+ spooky.then(function() {
+ this.click('[id="ext-gen59"]');
+ })
- // pass in CSR filename
- spooky.then([{csr:csr},function() {
- this.fill('form#certsubmit', {
- 'upload': csr
- }, false);
- }]);
+ // pass in CSR filename
+ spooky.then([{csr:csr},function() {
+ this.fill('form#certsubmit', {
+ 'upload': csr
+ }, false);
+ }]);
- spooky.then(function() {
- this.click('[id="ext-gen75"]');
- })
+ spooky.then(function() {
+ this.click('[id="ext-gen75"]');
+ })
- spooky.wait(30000, function() {
- this.echo("WAITED 30 SECS");
- });
+ spooky.wait(30000, function() {
+ this.echo("WAITED 30 SECS");
+ });
- spooky.then(function() {
- this.click('[id="ext-gen59"]');
- });
+ spooky.then(function() {
+ this.click('[id="ext-gen59"]');
+ });
- spooky.then(function() {
- this.click('[id="ext-gen91"]');
- });
+ spooky.then(function() {
+ this.click('[id="ext-gen91"]');
+ });
- spooky.wait(3000, function() {
- this.echo("WAITED 3 SECS");
- });
+ spooky.wait(3000, function() {
+ this.echo("WAITED 3 SECS");
+ });
- // download apn cert
- spooky.then([{bundlename:bundlename},function() {
- var href = this.evaluate(function() {
- return $('td:contains("Production Push SSL Certificate")').first().parents('tr').children('td:last').find('#form_logginMemberCert_').attr('href');
- });
- console.log("HREF: " + href);
- this.download(href, bundlename + '_apns.cer');
- }]);
+ // download apn cert
+ spooky.then([{bundlename:bundlename},function() {
+ var href = this.evaluate(function() {
+ return $('td:contains("Production Push SSL Certificate")').first().parents('tr').children('td:last').find('#form_logginMemberCert_').attr('href');
+ });
+ console.log("HREF: " + href);
+ this.download(href, bundlename + '_apns.cer');
+ }]);
- // say cheeze!
- spooky.then(function() {
- this.capture('lightman.png');
- });
+ // say cheeze!
+ spooky.then(function() {
+ this.capture('lightman.png');
+ });
+
+ spooky.run();
+ });
+ }
+ });
+ });
}
exports.configureAppIDForDistPush = configureAppIDForDistPush;
View
72 lib/authentication.js
@@ -1,6 +1,31 @@
+var keychain = require('keychain');
+var program = require('commander');
+var login = function (callback) {
+ program.prompt('Username: ', function(username){
+ program.password('Password: ', '*', function(password){
+ keychain.setPassword({ account: 'lightmanUsername', service: 'lightman', password: username }, function(err) {
+ keychain.setPassword({ account: 'lightmanPassword', service: 'lightman', password: password }, function(err) {
+ process.stdin.destroy();
+ console.log("Logged in as:" + username);
+ callback();
+ });
+ });
+ });
+ });
+};
-var login = function (username, password, team) {
+var logout = function (callback) {
+ keychain.deletePassword({ account: 'lightmanUsername', service: 'lightman' }, function(err) {
+ keychain.deletePassword({ account: 'lightmanPassword', service: 'lightman' }, function(err) {
+ process.stdin.destroy();
+ console.log("Logged out.");
+ callback();
+ });
+ });
+}
+
+var authenticate = function (username, password) {
// first go to dev center page
spooky.start('https://developer.apple.com/devcenter/ios/index.action');
@@ -16,50 +41,19 @@ var login = function (username, password, team) {
'theAccountPW': password
}, true);
}]);
-
- if (team) {
+
+ if (program.team) {
spooky.thenEvaluate(function(teamId) {
document.querySelector('[name="memberDisplayId"]').value=teamId;
- },team);
+ },program.team);
// press continue button
spooky.then(function() {
this.click('[name="action:saveTeamSelection!save"]');
- });
- }
-
- // go into the provisioning portal
- spooky.then(function() {
- this.clickLabel('iOS Provisioning Portal','a');
- });
-};
-
-var listTeams = function (username, password) {
- // first go to dev center page
- spooky.start('https://developer.apple.com/devcenter/ios/index.action');
-
- // then click the blue button, i don't go directly here cause it has some appid thing
- spooky.then(function() {
- this.click('[class="button blue"]');
- });
-
- // login
- spooky.then([{username:username,password:password},function() {
- this.fill('form', {
- 'theAccountName': username,
- 'theAccountPW': password
- }, true);
- }]);
-
- // say cheeze!
- spooky.then(function() {
- this.capture('lightman.png');
- });
-
- spooky.then(function() {
- console.log(this.getHTML('[name="memberDisplayId"]'));
- });
+ });
+ }
};
exports.login = login;
-exports.listTeams = listTeams;
+exports.logout = logout;
+exports.authenticate = authenticate;
View
181 lib/certificates.js
@@ -1,90 +1,131 @@
-
+var keychain = require('keychain');
+var world = require('./world').World;
+var authentication = require('./authentication');
var createDistrobutionCertificate = function (csr) {
- // go to the certificates section
- spooky.then(function() {
- this.clickLabel('Certificates','a');
- });
+ keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
+ keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
+ if (password == null) {
+ console.log("Not logged in");
+ } else {
+ world(function(world) {
+
+ authentication.authenticate(username,password);
+
+ // go into the provisioning portal
+ spooky.then(function() {
+ this.clickLabel('iOS Provisioning Portal','a');
+ });
+ // go to the certificates section
+ spooky.then(function() {
+ this.clickLabel('Certificates','a');
+ });
- // go to the distrobution certificates section
- spooky.then(function() {
- this.click('[href="/ios/manage/certificates/team/distribute.action"]');
- });
+ // go to the distrobution certificates section
+ spooky.then(function() {
+ this.click('[href="/ios/manage/certificates/team/distribute.action"]');
+ });
- // click request dist certificate
- spooky.then(function() {
- this.click('img[alt="Request Certificate"]');
- });
+ // click request dist certificate
+ spooky.then(function() {
+ this.click('img[alt="Request Certificate"]');
+ });
- // pass in CSR filename
- spooky.then([{csr:csr},function() {
- this.fill('form#save', {
- 'upload': csr
- }, true);
- }]);
+ // pass in CSR filename
+ spooky.then([{csr:csr},function() {
+ this.fill('form#save', {
+ 'upload': csr
+ }, true);
+ }]);
- // for for pending issuence
- spooky.then(function() {
- if (!this.exists('img[alt="download"]')) {
- this.wait(5000, function() {
- console.log("*** WAITED 5 secs");
- this.click('[href="/ios/manage/certificates/team/index.action"]');
+ // for for pending issuence
+ spooky.then(function() {
+ if (!this.exists('img[alt="download"]')) {
+ this.wait(5000, function() {
+ console.log("*** WAITED 5 secs");
+ this.click('[href="/ios/manage/certificates/team/index.action"]');
- if (!this.exists('img[alt="download"]')) {
- this.wait(5000, function() {
- console.log("*** WAITED 5 secs");
- this.click('[href="/ios/manage/certificates/team/index.action"]');
- });
- }
- });
- }
- });
+ if (!this.exists('img[alt="download"]')) {
+ this.wait(5000, function() {
+ console.log("*** WAITED 5 secs");
+ this.click('[href="/ios/manage/certificates/team/index.action"]');
+ });
+ }
+ });
+ }
+ });
- // download dist cert
- spooky.then(function() {
- this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadDistCert.action"]', 'href'), 'distribution.cer');
- });
+ // download dist cert
+ spooky.then(function() {
+ this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadDistCert.action"]', 'href'), 'distribution.cer');
+ });
+
+ spooky.run();
+ });
+ }
+ });
+ });
};
var createDevelopmentCertificate = function (csr) {
- // go to the certificates section
- spooky.then(function() {
- this.clickLabel('Certificates','a');
- });
+ keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
+ keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
+ if (password == null) {
+ console.log("Not logged in");
+ } else {
+ world(function(world) {
+
+ authentication.authenticate(username,password);
+
+ // go into the provisioning portal
+ spooky.then(function() {
+ this.clickLabel('iOS Provisioning Portal','a');
+ });
+
+ // go to the certificates section
+ spooky.then(function() {
+ this.clickLabel('Certificates','a');
+ });
+
+ // click request development certificate
+ spooky.then(function() {
+ this.click('img[alt="Request Certificate"]');
+ });
- // click request development certificate
- spooky.then(function() {
- this.click('img[alt="Request Certificate"]');
- });
+ // pass in CSR filename
+ spooky.then([{csr:csr},function() {
+ this.fill('form#save', {
+ 'upload': csr
+ }, true);
+ }]);
- // pass in CSR filename
- spooky.then([{csr:csr},function() {
- this.fill('form#save', {
- 'upload': csr
- }, true);
- }]);
+ // for for pending issuence
+ spooky.then(function() {
+ if (!this.exists('img[alt="download"]')) {
+ this.wait(5000, function() {
+ console.log("*** WAITED 5 secs");
+ this.click('[href="/ios/manage/certificates/team/index.action"]');
- // for for pending issuence
- spooky.then(function() {
- if (!this.exists('img[alt="download"]')) {
- this.wait(5000, function() {
- console.log("*** WAITED 5 secs");
- this.click('[href="/ios/manage/certificates/team/index.action"]');
+ if (!this.exists('img[alt="download"]')) {
+ this.wait(5000, function() {
+ console.log("*** WAITED 5 secs");
+ this.click('[href="/ios/manage/certificates/team/index.action"]');
+ });
+ }
+ });
+ }
+ });
- if (!this.exists('img[alt="download"]')) {
- this.wait(5000, function() {
- console.log("*** WAITED 5 secs");
- this.click('[href="/ios/manage/certificates/team/index.action"]');
- });
- }
- });
- }
- });
+ // download dev cert
+ spooky.then(function() {
+ this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadCert.action"]', 'href'), 'development.cer');
+ });
- // download dev cert
- spooky.then(function() {
- this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadCert.action"]', 'href'), 'development.cer');
+ spooky.run();
+ });
+ }
+ });
});
};
View
40 lib/lightman.js
@@ -2,44 +2,30 @@ var Spooky = require('spooky');
var program = require('commander');
program.version('0.0.1')
- .usage('[options] <createDevCert|createDistCert|createAppID>')
- .option('-p, --password <password>', 'Use password [blah]')
- .option('-u, --username <username>', 'Use username [blah]')
+ .usage('[options] <command>')
.option('-t, --team [team]', 'Use team')
.option('-c, --csr [csr file]', 'Use csr file')
.option('-bn, --bundlename [bundle name]', 'Use bundle name')
.option('-bi, --bundleid [bundle id]', 'Use bundle id')
.parse(process.argv);
-var world = require('./world').World;
var certificates = require('./certificates');
var authentication = require('./authentication');
var appids = require('./appids');
+var teams = require('./teams');
-world(function(world) {
-
- if (program.args[0] == "listTeams") {
- authentication.listTeams(program.username,program.password);
- } else {
- authentication.login(program.username,program.password,program.team);
-
- if (program.args[0] == "createDevCert") {
+if (program.args[0] == "login") {
+ authentication.login(function() {});
+} else if (program.args[0] == "logout") {
+ authentication.logout(function() {});
+} else if (program.args[0] == "teams:list") {
+ teams.listTeams();
+} else if (program.args[0] == "certs:create:dev") {
certificates.createDevelopmentCertificate(program.csr);
- } else if (program.args[0] == "createDistCert") {
+} else if (program.args[0] == "certs:create:dist") {
certificates.createDistrobutionCertificate(program.csr);
- } else if (program.args[0] == "createAppID") {
+} else if (program.args[0] == "appid:create") {
appids.createNewAppID(program.bundlename,program.bundleid);
- } else if (program.args[0] == "configureAppIDForDistPush") {
+} else if (program.args[0] == "appid:configure:push") {
appids.configureAppIDForDistPush(program.csr,program.bundlename);
- }
- }
-
- // // say cheeze!
- // spooky.then(function() {
- // this.capture('lightman.png');
- // });
-
- spooky.run();
-});
-
-
+}
View
27 lib/teams.js
@@ -0,0 +1,27 @@
+var keychain = require('keychain');
+var world = require('./world').World;
+var authentication = require('./authentication');
+
+var listTeams = function () {
+
+ keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
+ keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
+ if (password == null) {
+ console.log("Not logged in");
+ } else {
+ world(function(world) {
+
+ authentication.authenticate(username,password);
+
+ spooky.then(function() {
+ console.log(this.getHTML('[name="memberDisplayId"]'));
+ });
+
+ spooky.run();
+ });
+ }
+ });
+ });
+};
+
+exports.listTeams = listTeams;
View
3 package.json
@@ -17,7 +17,8 @@
},
"dependencies": {
"spooky": "~0.2.0",
- "commander": "*"
+ "commander": "*",
+ "keychain": "*"
},
"devDependencies": {
}
View
3 utils/createCSR.sh
@@ -12,5 +12,4 @@
openssl genrsa -out $1.key 2048
openssl req -new -key $1.key -out $1.certSigningRequest -subj "/emailAddress=$2, CN=$3, C=US"
-security create-keychain $1.keychain
-security import $1.key -k $1.keychain -t priv
+security import $1.key -k login.keychain -t priv

0 comments on commit 3fef848

Please sign in to comment.
Something went wrong with that request. Please try again.