Skip to content

Commit 18a00ee

Browse files
committed
fix: update to use latest heroku apis
1 parent 1a4fb2c commit 18a00ee

File tree

7 files changed

+184
-50
lines changed

7 files changed

+184
-50
lines changed

.eslintrc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
22
parserOptions: {
3-
ecmaVersion: 6,
4-
sourceType: 'script',
3+
ecmaVersion: 2017,
54
},
65
env: {
76
node: true,

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Heroku Deploys with strider
1+
# Heroku Deploys with Strider
22

3-
There's a lot that needs to be done here. See the [strider-extension-loader
4-
Readme](https://github.com/Strider-CD/strider-extension-loader/tree/1_4_refactor)
5-
for info on the api (under "job plugins").
3+
Prerequisites:
4+
5+
- [heroku cli](https://devcenter.heroku.com/articles/heroku-cli)
66

77
# Important config!
88

@@ -17,7 +17,13 @@ This is a screenshot of what you will see on your dashboard:
1717
If running locally we recommend using ngrok: `ngrok http 3000` and using the provided url as your host in Heroku and for `SERVER_NAME` env on Strider.
1818

1919
Add an API client for the url pattern: `https://yourhostnameofstrider/ext/heroku/oauth/callback`
20-
Once you have your `HEROKU_OAUTH_ID` and `HEROKU_OAUTH_SECRET`, you must configure Strider to use them like this:
20+
Copy values for `HEROKU_OAUTH_ID` and `HEROKU_OAUTH_SECRET`, you'll configure Strider to use them later.
21+
22+
Install the [heroku cli](https://devcenter.heroku.com/articles/heroku-cli), and login:
23+
24+
```sh
25+
heroku login
26+
```
2127

2228
## Running Strider locally:
2329

config/config.html

+43-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
1-
<h3>Heroku!</h3>
1+
<h3>Heroku</h3>
22
<div ng-show="userIsCreator">
3-
<a
4-
ng-hide="userConfig.accounts.length"
5-
href="/ext/heroku/oauth?redirect=/[[ project.name ]]/config"
6-
class="btn btn-success"
7-
>Add a Heroku Account</a
8-
>
3+
<div ng-hide="userConfig.accounts.length">
4+
<p>
5+
To get started setup Strider as an Api Client on Heroku. You can do this
6+
via the
7+
<a
8+
href="https://dashboard.heroku.com/account/applications"
9+
target="_blank"
10+
rel="noopenner noreferrer"
11+
>
12+
Applications
13+
</a>
14+
page under Account Settings.
15+
</p>
16+
17+
<p>
18+
Once you have the 'Client ID' and 'Client Secret' make sure to set them as
19+
environment variables for Strider (you'll have to restart Strider for
20+
this). Environment variables should be
21+
<code>PLUGIN_HEROKU_CLIENT_ID</code> and
22+
<code>PLUGIN_HEROKU_CLIENT_SECRET</code>.
23+
</p>
24+
25+
<p>
26+
Next you'll need to install the
27+
<a
28+
href="https://devcenter.heroku.com/articles/heroku-cli"
29+
target="_blank"
30+
rel="noopenner noreferrer"
31+
>
32+
Heroku CLI
33+
</a>
34+
and run <code>heroku login</code>. Now you are ready to "Add Heroku"
35+
below.
36+
</p>
37+
38+
<a
39+
href="/ext/heroku/oauth?redirect=/[[ project.name ]]/config"
40+
class="btn btn-success"
41+
>Add a Heroku Account</a
42+
>
43+
</div>
44+
945
<div ng-show="userConfig.accounts.length">
1046
<div class="accounts">
1147
<h4>Linked Accounts</h4>

lib/api.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
const fs = require('fs');
12
const superagent = require('superagent');
3+
const execa = require('execa');
4+
const tmp = require('tmp-promise');
5+
26
const API = 'https://api.heroku.com';
37

48
module.exports = {
@@ -34,21 +38,14 @@ function getApps(aid, token, done) {
3438
});
3539
}
3640

37-
function addKey(token, key, done) {
38-
superagent
39-
.post(API + '/account/keys')
40-
.set('Accept', 'application/vnd.heroku+json; version=3')
41-
.set('Authorization', 'Bearer ' + token)
42-
// .set('Content-type', 'text/ssh-authkey')
43-
.send({
44-
public_key: key,
45-
})
46-
.end(function (err, res) {
47-
if (err) {
48-
return done(err);
49-
}
50-
if (res.status !== 200)
51-
return done(new Error('Status: ' + res.status + '; ' + res.text));
52-
done();
53-
});
41+
async function addKey(key) {
42+
try {
43+
let { path, cleanup } = await tmp.file();
44+
fs.promises.writeFile(path, key);
45+
46+
await execa('heroku', ['keys:add', path]);
47+
cleanup();
48+
} catch (err) {
49+
throw new Error('failed creating temporary folder: ' + err.message);
50+
}
5451
}

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@
3939
}
4040
},
4141
"dependencies": {
42+
"execa": "^4.0.1",
4243
"passport-heroku": "1.0.0",
4344
"ssh-keypair": "^2.0.0",
4445
"step": "^1.0.0",
4546
"strider-git": "^1.0.3",
46-
"superagent": "^5.2.2"
47+
"superagent": "^5.2.2",
48+
"tmp-promise": "^3.0.2"
4749
},
4850
"devDependencies": {
4951
"eslint": "^7.0.0",

webapp.js

+24-15
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,35 @@ function validateAuth(req, token, refresh, profile, done) {
156156
}
157157
}
158158
api.getApps(profile.id, token, function (err, apps) {
159-
if (err)
159+
if (err) {
160160
return done(new Error('failed to retrieve apps list: ' + err.message));
161+
}
162+
161163
keypair(profile.email + ' - strider', function (err, priv, pub) {
162-
if (err)
164+
if (err) {
163165
return done(new Error('Failed to generate keypair; ' + err.message));
164-
api.addKey(token, pub, function (err) {
165-
if (err)
166+
}
167+
168+
api
169+
.addKey(pub)
170+
.then(() => {
171+
profile.emails.forEach((item) => {
172+
heroku.accounts.push({
173+
id: profile.id,
174+
token: token,
175+
email: item.value,
176+
privkey: priv,
177+
pubkey: pub,
178+
cache: [apps],
179+
});
180+
});
181+
req.user.jobPluginData('heroku', heroku, function (err) {
182+
done(err, req.user);
183+
});
184+
})
185+
.catch((err) => {
166186
return done(new Error('Failed to add ssh key: ' + err.message));
167-
heroku.accounts.push({
168-
id: profile.id,
169-
token: token,
170-
email: profile.email,
171-
privkey: priv,
172-
pubkey: pub,
173-
cache: [apps],
174187
});
175-
req.user.jobPluginData('heroku', heroku, function (err) {
176-
done(err, req.user);
177-
});
178-
});
179188
});
180189
});
181190
}

yarn.lock

+88-3
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ core-util-is@~1.0.0:
514514
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
515515
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
516516

517-
cross-spawn@^7.0.2:
517+
cross-spawn@^7.0.0, cross-spawn@^7.0.2:
518518
version "7.0.2"
519519
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
520520
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==
@@ -626,6 +626,13 @@ emoji-regex@^8.0.0:
626626
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
627627
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
628628

629+
end-of-stream@^1.1.0:
630+
version "1.4.4"
631+
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
632+
integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==
633+
dependencies:
634+
once "^1.4.0"
635+
629636
error-ex@^1.2.0, error-ex@^1.3.1:
630637
version "1.3.2"
631638
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
@@ -743,6 +750,21 @@ esutils@^2.0.2:
743750
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
744751
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
745752

753+
execa@^4.0.1:
754+
version "4.0.1"
755+
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.1.tgz#988488781f1f0238cd156f7aaede11c3e853b4c1"
756+
integrity sha512-SCjM/zlBdOK8Q5TIjOn6iEHZaPHFsMoTxXQ2nvUvtPnuohz3H2dIozSg+etNR98dGoYUp2ENSKLL/XaMmbxVgw==
757+
dependencies:
758+
cross-spawn "^7.0.0"
759+
get-stream "^5.0.0"
760+
human-signals "^1.1.1"
761+
is-stream "^2.0.0"
762+
merge-stream "^2.0.0"
763+
npm-run-path "^4.0.0"
764+
onetime "^5.1.0"
765+
signal-exit "^3.0.2"
766+
strip-final-newline "^2.0.0"
767+
746768
external-editor@^3.0.3:
747769
version "3.1.0"
748770
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495"
@@ -898,6 +920,13 @@ get-stdin@^4.0.1:
898920
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
899921
integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=
900922

923+
get-stream@^5.0.0:
924+
version "5.1.0"
925+
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9"
926+
integrity sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==
927+
dependencies:
928+
pump "^3.0.0"
929+
901930
902931
version "2.0.0"
903932
resolved "https://registry.yarnpkg.com/git-raw-commits/-/git-raw-commits-2.0.0.tgz#d92addf74440c14bcc5c83ecce3fb7f8a79118b5"
@@ -1010,6 +1039,11 @@ hosted-git-info@^2.1.4:
10101039
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488"
10111040
integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==
10121041

1042+
human-signals@^1.1.1:
1043+
version "1.1.1"
1044+
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
1045+
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==
1046+
10131047
iconv-lite@^0.4.24:
10141048
version "0.4.24"
10151049
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@@ -1136,6 +1170,11 @@ is-plain-obj@^1.1.0:
11361170
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
11371171
integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4=
11381172

1173+
is-stream@^2.0.0:
1174+
version "2.0.0"
1175+
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3"
1176+
integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==
1177+
11391178
is-text-path@^1.0.1:
11401179
version "1.0.1"
11411180
resolved "https://registry.yarnpkg.com/is-text-path/-/is-text-path-1.0.1.tgz#4e1aa0fb51bfbcb3e92688001397202c1775b66e"
@@ -1385,6 +1424,11 @@ meow@^7.0.0:
13851424
type-fest "^0.13.1"
13861425
yargs-parser "^18.1.3"
13871426

1427+
merge-stream@^2.0.0:
1428+
version "2.0.0"
1429+
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
1430+
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==
1431+
13881432
methods@^1.1.2:
13891433
version "1.1.2"
13901434
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
@@ -1492,6 +1536,13 @@ normalize-package-data@^2.3.0, normalize-package-data@^2.3.2, normalize-package-
14921536
semver "2 || 3 || 4 || 5"
14931537
validate-npm-package-license "^3.0.1"
14941538

1539+
npm-run-path@^4.0.0:
1540+
version "4.0.1"
1541+
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
1542+
integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==
1543+
dependencies:
1544+
path-key "^3.0.0"
1545+
14951546
null-check@^1.0.0:
14961547
version "1.0.0"
14971548
resolved "https://registry.yarnpkg.com/null-check/-/null-check-1.0.0.tgz#977dffd7176012b9ec30d2a39db5cf72a0439edd"
@@ -1512,7 +1563,7 @@ object-assign@^4.0.1:
15121563
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
15131564
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
15141565

1515-
once@^1.3.0:
1566+
once@^1.3.0, once@^1.3.1, once@^1.4.0:
15161567
version "1.4.0"
15171568
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
15181569
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
@@ -1670,7 +1721,7 @@ path-is-absolute@^1.0.0:
16701721
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
16711722
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
16721723

1673-
path-key@^3.1.0:
1724+
path-key@^3.0.0, path-key@^3.1.0:
16741725
version "3.1.1"
16751726
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
16761727
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
@@ -1733,6 +1784,14 @@ progress@^2.0.0:
17331784
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
17341785
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
17351786

1787+
pump@^3.0.0:
1788+
version "3.0.0"
1789+
resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"
1790+
integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==
1791+
dependencies:
1792+
end-of-stream "^1.1.0"
1793+
once "^1.3.1"
1794+
17361795
punycode@^2.1.0:
17371796
version "2.1.1"
17381797
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
@@ -1913,6 +1972,13 @@ [email protected]:
19131972
dependencies:
19141973
glob "^7.1.3"
19151974

1975+
rimraf@^3.0.0:
1976+
version "3.0.2"
1977+
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
1978+
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
1979+
dependencies:
1980+
glob "^7.1.3"
1981+
19161982
run-async@^2.4.0:
19171983
version "2.4.1"
19181984
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
@@ -2180,6 +2246,11 @@ strip-bom@^3.0.0:
21802246
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
21812247
integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=
21822248

2249+
strip-final-newline@^2.0.0:
2250+
version "2.0.0"
2251+
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
2252+
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==
2253+
21832254
strip-indent@^1.0.1:
21842255
version "1.0.1"
21852256
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2"
@@ -2275,13 +2346,27 @@ through@2, "through@>=2.2.7 <3", through@^2.3.6:
22752346
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
22762347
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
22772348

2349+
tmp-promise@^3.0.2:
2350+
version "3.0.2"
2351+
resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-3.0.2.tgz#6e933782abff8b00c3119d63589ca1fb9caaa62a"
2352+
integrity sha512-OyCLAKU1HzBjL6Ev3gxUeraJNlbNingmi8IrHHEsYH8LTmEuhvYfqvhn2F/je+mjf4N58UmZ96OMEy1JanSCpA==
2353+
dependencies:
2354+
tmp "^0.2.0"
2355+
22782356
tmp@^0.0.33:
22792357
version "0.0.33"
22802358
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
22812359
integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==
22822360
dependencies:
22832361
os-tmpdir "~1.0.2"
22842362

2363+
tmp@^0.2.0, tmp@^0.2.1:
2364+
version "0.2.1"
2365+
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14"
2366+
integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==
2367+
dependencies:
2368+
rimraf "^3.0.0"
2369+
22852370
trim-newlines@^1.0.0:
22862371
version "1.0.0"
22872372
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"

0 commit comments

Comments
 (0)