Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

big refactoring

  • Loading branch information...
commit 3fef84836bf496dcd10dd66189cdead3be68a523 1 parent e1116bb
PJ Gray authored
186 lib/appids.js
... ... @@ -1,96 +1,140 @@
  1 +var keychain = require('keychain');
  2 +var world = require('./world').World;
  3 +var authentication = require('./authentication');
  4 +
1 5 var createNewAppID = function (bundlename,bundleid) {
2   - // go to the App IDs section
3   - spooky.then(function() {
4   - this.clickLabel('App IDs','a');
5   - });
  6 + keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
  7 + keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
  8 + if (password == null) {
  9 + console.log("Not logged in");
  10 + } else {
  11 + world(function(world) {
6 12
7   - // click new app id
8   - spooky.then(function() {
9   - this.click('[href="/ios/manage/bundles/add.action"]');
10   - });
  13 + authentication.authenticate(username,password);
11 14
12   - // fill in new app id form
13   - spooky.then([{bundlename:bundlename,bundleid:bundleid},function() {
14   - this.fill('form#save', {
15   - 'bundleName': bundlename,
16   - 'bundleIdentifier': bundleid
17   - }, true);
18   - }]);
  15 + // go into the provisioning portal
  16 + spooky.then(function() {
  17 + this.clickLabel('iOS Provisioning Portal','a');
  18 + });
  19 +
  20 + // go to the App IDs section
  21 + spooky.then(function() {
  22 + this.clickLabel('App IDs','a');
  23 + });
  24 +
  25 + // click new app id
  26 + spooky.then(function() {
  27 + this.click('[href="/ios/manage/bundles/add.action"]');
  28 + });
19 29
  30 + // fill in new app id form
  31 + spooky.then([{bundlename:bundlename,bundleid:bundleid},function() {
  32 + this.fill('form#save', {
  33 + 'bundleName': bundlename,
  34 + 'bundleIdentifier': bundleid
  35 + }, true);
  36 + }]);
  37 +
  38 + spooky.run();
  39 +
  40 + });
  41 + }
  42 + });
  43 + });
20 44 };
21 45
22 46 var configureAppIDForDistPush = function (csr,bundlename) {
23 47
24   - // go to the App IDs section
25   - spooky.then(function() {
26   - this.clickLabel('App IDs','a');
27   - });
  48 + keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
  49 + keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
  50 + if (password == null) {
  51 + console.log("Not logged in");
  52 + } else {
  53 + world(function(world) {
  54 +
  55 + authentication.authenticate(username,password);
  56 +
  57 + // go into the provisioning portal
  58 + spooky.then(function() {
  59 + this.clickLabel('iOS Provisioning Portal','a');
  60 + });
  61 +
  62 + // go to the App IDs section
  63 + spooky.then(function() {
  64 + this.clickLabel('App IDs','a');
  65 + });
28 66
29   - spooky.then([{bundlename:bundlename},function() {
30   - var href = this.evaluate(function(bundlename) {
31   - return $('td.name:contains("' + bundlename + '")').parents('tr').children('td:last').children('a').attr('href');
32   - }, bundlename);
33   - console.log("HREF: " + href);
34   - this.click('[href="'+ href + '"]');
35   - }]);
  67 + spooky.then([{bundlename:bundlename},function() {
  68 + var href = this.evaluate(function(bundlename) {
  69 + return $('td.name:contains("' + bundlename + '")').parents('tr').children('td:last').children('a').attr('href');
  70 + }, bundlename);
  71 + console.log("HREF: " + href);
  72 + this.click('[href="'+ href + '"]');
  73 + }]);
36 74
37   - spooky.then(function() {
38   - this.click('[id="enablePush"]');
39   - });
  75 + spooky.then(function() {
  76 + this.click('[id="enablePush"]');
  77 + });
40 78
41   - spooky.then(function() {
42   - this.click('[id="aps-assistant-btn-prod-en"]');
43   - })
  79 + spooky.then(function() {
  80 + this.click('[id="aps-assistant-btn-prod-en"]');
  81 + })
44 82
45   - spooky.wait(5000, function() {
46   - this.echo("WAITED 5 SECS");
47   - });
  83 + spooky.wait(5000, function() {
  84 + this.echo("WAITED 5 SECS");
  85 + });
48 86
49   - spooky.then(function() {
50   - this.click('[id="ext-gen59"]');
51   - })
  87 + spooky.then(function() {
  88 + this.click('[id="ext-gen59"]');
  89 + })
52 90
53   - // pass in CSR filename
54   - spooky.then([{csr:csr},function() {
55   - this.fill('form#certsubmit', {
56   - 'upload': csr
57   - }, false);
58   - }]);
  91 + // pass in CSR filename
  92 + spooky.then([{csr:csr},function() {
  93 + this.fill('form#certsubmit', {
  94 + 'upload': csr
  95 + }, false);
  96 + }]);
59 97
60   - spooky.then(function() {
61   - this.click('[id="ext-gen75"]');
62   - })
  98 + spooky.then(function() {
  99 + this.click('[id="ext-gen75"]');
  100 + })
63 101
64   - spooky.wait(30000, function() {
65   - this.echo("WAITED 30 SECS");
66   - });
  102 + spooky.wait(30000, function() {
  103 + this.echo("WAITED 30 SECS");
  104 + });
67 105
68   - spooky.then(function() {
69   - this.click('[id="ext-gen59"]');
70   - });
  106 + spooky.then(function() {
  107 + this.click('[id="ext-gen59"]');
  108 + });
71 109
72   - spooky.then(function() {
73   - this.click('[id="ext-gen91"]');
74   - });
  110 + spooky.then(function() {
  111 + this.click('[id="ext-gen91"]');
  112 + });
75 113
76   - spooky.wait(3000, function() {
77   - this.echo("WAITED 3 SECS");
78   - });
  114 + spooky.wait(3000, function() {
  115 + this.echo("WAITED 3 SECS");
  116 + });
79 117
80   - // download apn cert
81   - spooky.then([{bundlename:bundlename},function() {
82   - var href = this.evaluate(function() {
83   - return $('td:contains("Production Push SSL Certificate")').first().parents('tr').children('td:last').find('#form_logginMemberCert_').attr('href');
84   - });
85   - console.log("HREF: " + href);
86   - this.download(href, bundlename + '_apns.cer');
87   - }]);
  118 + // download apn cert
  119 + spooky.then([{bundlename:bundlename},function() {
  120 + var href = this.evaluate(function() {
  121 + return $('td:contains("Production Push SSL Certificate")').first().parents('tr').children('td:last').find('#form_logginMemberCert_').attr('href');
  122 + });
  123 + console.log("HREF: " + href);
  124 + this.download(href, bundlename + '_apns.cer');
  125 + }]);
88 126
89   - // say cheeze!
90   - spooky.then(function() {
91   - this.capture('lightman.png');
92   - });
  127 + // say cheeze!
  128 + spooky.then(function() {
  129 + this.capture('lightman.png');
  130 + });
  131 +
  132 + spooky.run();
93 133
  134 + });
  135 + }
  136 + });
  137 + });
94 138 }
95 139
96 140 exports.configureAppIDForDistPush = configureAppIDForDistPush;
72 lib/authentication.js
... ... @@ -1,6 +1,31 @@
  1 +var keychain = require('keychain');
  2 +var program = require('commander');
1 3
  4 +var login = function (callback) {
  5 + program.prompt('Username: ', function(username){
  6 + program.password('Password: ', '*', function(password){
  7 + keychain.setPassword({ account: 'lightmanUsername', service: 'lightman', password: username }, function(err) {
  8 + keychain.setPassword({ account: 'lightmanPassword', service: 'lightman', password: password }, function(err) {
  9 + process.stdin.destroy();
  10 + console.log("Logged in as:" + username);
  11 + callback();
  12 + });
  13 + });
  14 + });
  15 + });
  16 +};
2 17
3   -var login = function (username, password, team) {
  18 +var logout = function (callback) {
  19 + keychain.deletePassword({ account: 'lightmanUsername', service: 'lightman' }, function(err) {
  20 + keychain.deletePassword({ account: 'lightmanPassword', service: 'lightman' }, function(err) {
  21 + process.stdin.destroy();
  22 + console.log("Logged out.");
  23 + callback();
  24 + });
  25 + });
  26 +}
  27 +
  28 +var authenticate = function (username, password) {
4 29 // first go to dev center page
5 30 spooky.start('https://developer.apple.com/devcenter/ios/index.action');
6 31
@@ -16,50 +41,19 @@ var login = function (username, password, team) {
16 41 'theAccountPW': password
17 42 }, true);
18 43 }]);
19   -
20   - if (team) {
  44 +
  45 + if (program.team) {
21 46 spooky.thenEvaluate(function(teamId) {
22 47 document.querySelector('[name="memberDisplayId"]').value=teamId;
23   - },team);
  48 + },program.team);
24 49
25 50 // press continue button
26 51 spooky.then(function() {
27 52 this.click('[name="action:saveTeamSelection!save"]');
28   - });
29   - }
30   -
31   - // go into the provisioning portal
32   - spooky.then(function() {
33   - this.clickLabel('iOS Provisioning Portal','a');
34   - });
35   -};
36   -
37   -var listTeams = function (username, password) {
38   - // first go to dev center page
39   - spooky.start('https://developer.apple.com/devcenter/ios/index.action');
40   -
41   - // then click the blue button, i don't go directly here cause it has some appid thing
42   - spooky.then(function() {
43   - this.click('[class="button blue"]');
44   - });
45   -
46   - // login
47   - spooky.then([{username:username,password:password},function() {
48   - this.fill('form', {
49   - 'theAccountName': username,
50   - 'theAccountPW': password
51   - }, true);
52   - }]);
53   -
54   - // say cheeze!
55   - spooky.then(function() {
56   - this.capture('lightman.png');
57   - });
58   -
59   - spooky.then(function() {
60   - console.log(this.getHTML('[name="memberDisplayId"]'));
61   - });
  53 + });
  54 + }
62 55 };
63 56
64 57 exports.login = login;
65   -exports.listTeams = listTeams;
  58 +exports.logout = logout;
  59 +exports.authenticate = authenticate;
181 lib/certificates.js
... ... @@ -1,90 +1,131 @@
1   -
  1 +var keychain = require('keychain');
  2 +var world = require('./world').World;
  3 +var authentication = require('./authentication');
2 4
3 5 var createDistrobutionCertificate = function (csr) {
4   - // go to the certificates section
5   - spooky.then(function() {
6   - this.clickLabel('Certificates','a');
7   - });
  6 + keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
  7 + keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
  8 + if (password == null) {
  9 + console.log("Not logged in");
  10 + } else {
  11 + world(function(world) {
  12 +
  13 + authentication.authenticate(username,password);
  14 +
  15 + // go into the provisioning portal
  16 + spooky.then(function() {
  17 + this.clickLabel('iOS Provisioning Portal','a');
  18 + });
  19 + // go to the certificates section
  20 + spooky.then(function() {
  21 + this.clickLabel('Certificates','a');
  22 + });
8 23
9   - // go to the distrobution certificates section
10   - spooky.then(function() {
11   - this.click('[href="/ios/manage/certificates/team/distribute.action"]');
12   - });
  24 + // go to the distrobution certificates section
  25 + spooky.then(function() {
  26 + this.click('[href="/ios/manage/certificates/team/distribute.action"]');
  27 + });
13 28
14   - // click request dist certificate
15   - spooky.then(function() {
16   - this.click('img[alt="Request Certificate"]');
17   - });
  29 + // click request dist certificate
  30 + spooky.then(function() {
  31 + this.click('img[alt="Request Certificate"]');
  32 + });
18 33
19   - // pass in CSR filename
20   - spooky.then([{csr:csr},function() {
21   - this.fill('form#save', {
22   - 'upload': csr
23   - }, true);
24   - }]);
  34 + // pass in CSR filename
  35 + spooky.then([{csr:csr},function() {
  36 + this.fill('form#save', {
  37 + 'upload': csr
  38 + }, true);
  39 + }]);
25 40
26   - // for for pending issuence
27   - spooky.then(function() {
28   - if (!this.exists('img[alt="download"]')) {
29   - this.wait(5000, function() {
30   - console.log("*** WAITED 5 secs");
31   - this.click('[href="/ios/manage/certificates/team/index.action"]');
  41 + // for for pending issuence
  42 + spooky.then(function() {
  43 + if (!this.exists('img[alt="download"]')) {
  44 + this.wait(5000, function() {
  45 + console.log("*** WAITED 5 secs");
  46 + this.click('[href="/ios/manage/certificates/team/index.action"]');
32 47
33   - if (!this.exists('img[alt="download"]')) {
34   - this.wait(5000, function() {
35   - console.log("*** WAITED 5 secs");
36   - this.click('[href="/ios/manage/certificates/team/index.action"]');
37   - });
38   - }
39   - });
40   - }
41   - });
  48 + if (!this.exists('img[alt="download"]')) {
  49 + this.wait(5000, function() {
  50 + console.log("*** WAITED 5 secs");
  51 + this.click('[href="/ios/manage/certificates/team/index.action"]');
  52 + });
  53 + }
  54 + });
  55 + }
  56 + });
42 57
43   - // download dist cert
44   - spooky.then(function() {
45   - this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadDistCert.action"]', 'href'), 'distribution.cer');
46   - });
  58 + // download dist cert
  59 + spooky.then(function() {
  60 + this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadDistCert.action"]', 'href'), 'distribution.cer');
  61 + });
  62 +
  63 + spooky.run();
  64 + });
  65 + }
  66 + });
  67 + });
47 68
48 69 };
49 70
50 71 var createDevelopmentCertificate = function (csr) {
51   - // go to the certificates section
52   - spooky.then(function() {
53   - this.clickLabel('Certificates','a');
54   - });
  72 + keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
  73 + keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
  74 + if (password == null) {
  75 + console.log("Not logged in");
  76 + } else {
  77 + world(function(world) {
  78 +
  79 + authentication.authenticate(username,password);
  80 +
  81 + // go into the provisioning portal
  82 + spooky.then(function() {
  83 + this.clickLabel('iOS Provisioning Portal','a');
  84 + });
  85 +
  86 + // go to the certificates section
  87 + spooky.then(function() {
  88 + this.clickLabel('Certificates','a');
  89 + });
  90 +
  91 + // click request development certificate
  92 + spooky.then(function() {
  93 + this.click('img[alt="Request Certificate"]');
  94 + });
55 95
56   - // click request development certificate
57   - spooky.then(function() {
58   - this.click('img[alt="Request Certificate"]');
59   - });
  96 + // pass in CSR filename
  97 + spooky.then([{csr:csr},function() {
  98 + this.fill('form#save', {
  99 + 'upload': csr
  100 + }, true);
  101 + }]);
60 102
61   - // pass in CSR filename
62   - spooky.then([{csr:csr},function() {
63   - this.fill('form#save', {
64   - 'upload': csr
65   - }, true);
66   - }]);
  103 + // for for pending issuence
  104 + spooky.then(function() {
  105 + if (!this.exists('img[alt="download"]')) {
  106 + this.wait(5000, function() {
  107 + console.log("*** WAITED 5 secs");
  108 + this.click('[href="/ios/manage/certificates/team/index.action"]');
67 109
68   - // for for pending issuence
69   - spooky.then(function() {
70   - if (!this.exists('img[alt="download"]')) {
71   - this.wait(5000, function() {
72   - console.log("*** WAITED 5 secs");
73   - this.click('[href="/ios/manage/certificates/team/index.action"]');
  110 + if (!this.exists('img[alt="download"]')) {
  111 + this.wait(5000, function() {
  112 + console.log("*** WAITED 5 secs");
  113 + this.click('[href="/ios/manage/certificates/team/index.action"]');
  114 + });
  115 + }
  116 + });
  117 + }
  118 + });
74 119
75   - if (!this.exists('img[alt="download"]')) {
76   - this.wait(5000, function() {
77   - console.log("*** WAITED 5 secs");
78   - this.click('[href="/ios/manage/certificates/team/index.action"]');
79   - });
80   - }
81   - });
82   - }
83   - });
  120 + // download dev cert
  121 + spooky.then(function() {
  122 + this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadCert.action"]', 'href'), 'development.cer');
  123 + });
84 124
85   - // download dev cert
86   - spooky.then(function() {
87   - this.download(this.getElementAttribute('[href^="/ios/manage/certificates/team/downloadCert.action"]', 'href'), 'development.cer');
  125 + spooky.run();
  126 + });
  127 + }
  128 + });
88 129 });
89 130 };
90 131
40 lib/lightman.js
@@ -2,44 +2,30 @@ var Spooky = require('spooky');
2 2 var program = require('commander');
3 3
4 4 program.version('0.0.1')
5   - .usage('[options] <createDevCert|createDistCert|createAppID>')
6   - .option('-p, --password <password>', 'Use password [blah]')
7   - .option('-u, --username <username>', 'Use username [blah]')
  5 + .usage('[options] <command>')
8 6 .option('-t, --team [team]', 'Use team')
9 7 .option('-c, --csr [csr file]', 'Use csr file')
10 8 .option('-bn, --bundlename [bundle name]', 'Use bundle name')
11 9 .option('-bi, --bundleid [bundle id]', 'Use bundle id')
12 10 .parse(process.argv);
13 11
14   -var world = require('./world').World;
15 12 var certificates = require('./certificates');
16 13 var authentication = require('./authentication');
17 14 var appids = require('./appids');
  15 +var teams = require('./teams');
18 16
19   -world(function(world) {
20   -
21   - if (program.args[0] == "listTeams") {
22   - authentication.listTeams(program.username,program.password);
23   - } else {
24   - authentication.login(program.username,program.password,program.team);
25   -
26   - if (program.args[0] == "createDevCert") {
  17 +if (program.args[0] == "login") {
  18 + authentication.login(function() {});
  19 +} else if (program.args[0] == "logout") {
  20 + authentication.logout(function() {});
  21 +} else if (program.args[0] == "teams:list") {
  22 + teams.listTeams();
  23 +} else if (program.args[0] == "certs:create:dev") {
27 24 certificates.createDevelopmentCertificate(program.csr);
28   - } else if (program.args[0] == "createDistCert") {
  25 +} else if (program.args[0] == "certs:create:dist") {
29 26 certificates.createDistrobutionCertificate(program.csr);
30   - } else if (program.args[0] == "createAppID") {
  27 +} else if (program.args[0] == "appid:create") {
31 28 appids.createNewAppID(program.bundlename,program.bundleid);
32   - } else if (program.args[0] == "configureAppIDForDistPush") {
  29 +} else if (program.args[0] == "appid:configure:push") {
33 30 appids.configureAppIDForDistPush(program.csr,program.bundlename);
34   - }
35   - }
36   -
37   - // // say cheeze!
38   - // spooky.then(function() {
39   - // this.capture('lightman.png');
40   - // });
41   -
42   - spooky.run();
43   -});
44   -
45   -
  31 +}
27 lib/teams.js
... ... @@ -0,0 +1,27 @@
  1 +var keychain = require('keychain');
  2 +var world = require('./world').World;
  3 +var authentication = require('./authentication');
  4 +
  5 +var listTeams = function () {
  6 +
  7 + keychain.getPassword({ account: 'lightmanUsername', service: 'lightman' }, function(err,username) {
  8 + keychain.getPassword({ account: 'lightmanPassword', service: 'lightman' }, function(err,password) {
  9 + if (password == null) {
  10 + console.log("Not logged in");
  11 + } else {
  12 + world(function(world) {
  13 +
  14 + authentication.authenticate(username,password);
  15 +
  16 + spooky.then(function() {
  17 + console.log(this.getHTML('[name="memberDisplayId"]'));
  18 + });
  19 +
  20 + spooky.run();
  21 + });
  22 + }
  23 + });
  24 + });
  25 +};
  26 +
  27 +exports.listTeams = listTeams;
3  package.json
@@ -17,7 +17,8 @@
17 17 },
18 18 "dependencies": {
19 19 "spooky": "~0.2.0",
20   - "commander": "*"
  20 + "commander": "*",
  21 + "keychain": "*"
21 22 },
22 23 "devDependencies": {
23 24 }
3  utils/createCSR.sh
@@ -12,5 +12,4 @@
12 12
13 13 openssl genrsa -out $1.key 2048
14 14 openssl req -new -key $1.key -out $1.certSigningRequest -subj "/emailAddress=$2, CN=$3, C=US"
15   -security create-keychain $1.keychain
16   -security import $1.key -k $1.keychain -t priv
  15 +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.