Skip to content

Commit

Permalink
fix: update to use latest heroku apis
Browse files Browse the repository at this point in the history
  • Loading branch information
knownasilya committed May 21, 2020
1 parent 1a4fb2c commit 18a00ee
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 50 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
parserOptions: {
ecmaVersion: 6,
sourceType: 'script',
ecmaVersion: 2017,
},
env: {
node: true,
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Heroku Deploys with strider
# Heroku Deploys with Strider

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

- [heroku cli](https://devcenter.heroku.com/articles/heroku-cli)

# Important config!

Expand All @@ -17,7 +17,13 @@ This is a screenshot of what you will see on your dashboard:
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.

Add an API client for the url pattern: `https://yourhostnameofstrider/ext/heroku/oauth/callback`
Once you have your `HEROKU_OAUTH_ID` and `HEROKU_OAUTH_SECRET`, you must configure Strider to use them like this:
Copy values for `HEROKU_OAUTH_ID` and `HEROKU_OAUTH_SECRET`, you'll configure Strider to use them later.

Install the [heroku cli](https://devcenter.heroku.com/articles/heroku-cli), and login:

```sh
heroku login
```

## Running Strider locally:

Expand Down
50 changes: 43 additions & 7 deletions config/config.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
<h3>Heroku!</h3>
<h3>Heroku</h3>
<div ng-show="userIsCreator">
<a
ng-hide="userConfig.accounts.length"
href="/ext/heroku/oauth?redirect=/[[ project.name ]]/config"
class="btn btn-success"
>Add a Heroku Account</a
>
<div ng-hide="userConfig.accounts.length">
<p>
To get started setup Strider as an Api Client on Heroku. You can do this
via the
<a
href="https://dashboard.heroku.com/account/applications"
target="_blank"
rel="noopenner noreferrer"
>
Applications
</a>
page under Account Settings.
</p>

<p>
Once you have the 'Client ID' and 'Client Secret' make sure to set them as
environment variables for Strider (you'll have to restart Strider for
this). Environment variables should be
<code>PLUGIN_HEROKU_CLIENT_ID</code> and
<code>PLUGIN_HEROKU_CLIENT_SECRET</code>.
</p>

<p>
Next you'll need to install the
<a
href="https://devcenter.heroku.com/articles/heroku-cli"
target="_blank"
rel="noopenner noreferrer"
>
Heroku CLI
</a>
and run <code>heroku login</code>. Now you are ready to "Add Heroku"
below.
</p>

<a
href="/ext/heroku/oauth?redirect=/[[ project.name ]]/config"
class="btn btn-success"
>Add a Heroku Account</a
>
</div>

<div ng-show="userConfig.accounts.length">
<div class="accounts">
<h4>Linked Accounts</h4>
Expand Down
31 changes: 14 additions & 17 deletions lib/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const fs = require('fs');
const superagent = require('superagent');
const execa = require('execa');
const tmp = require('tmp-promise');

const API = 'https://api.heroku.com';

module.exports = {
Expand Down Expand Up @@ -34,21 +38,14 @@ function getApps(aid, token, done) {
});
}

function addKey(token, key, done) {
superagent
.post(API + '/account/keys')
.set('Accept', 'application/vnd.heroku+json; version=3')
.set('Authorization', 'Bearer ' + token)
// .set('Content-type', 'text/ssh-authkey')
.send({
public_key: key,
})
.end(function (err, res) {
if (err) {
return done(err);
}
if (res.status !== 200)
return done(new Error('Status: ' + res.status + '; ' + res.text));
done();
});
async function addKey(key) {
try {
let { path, cleanup } = await tmp.file();
fs.promises.writeFile(path, key);

await execa('heroku', ['keys:add', path]);
cleanup();
} catch (err) {
throw new Error('failed creating temporary folder: ' + err.message);
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
}
},
"dependencies": {
"execa": "^4.0.1",
"passport-heroku": "1.0.0",
"ssh-keypair": "^2.0.0",
"step": "^1.0.0",
"strider-git": "^1.0.3",
"superagent": "^5.2.2"
"superagent": "^5.2.2",
"tmp-promise": "^3.0.2"
},
"devDependencies": {
"eslint": "^7.0.0",
Expand Down
39 changes: 24 additions & 15 deletions webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,35 @@ function validateAuth(req, token, refresh, profile, done) {
}
}
api.getApps(profile.id, token, function (err, apps) {
if (err)
if (err) {
return done(new Error('failed to retrieve apps list: ' + err.message));
}

keypair(profile.email + ' - strider', function (err, priv, pub) {
if (err)
if (err) {
return done(new Error('Failed to generate keypair; ' + err.message));
api.addKey(token, pub, function (err) {
if (err)
}

api
.addKey(pub)
.then(() => {
profile.emails.forEach((item) => {
heroku.accounts.push({
id: profile.id,
token: token,
email: item.value,
privkey: priv,
pubkey: pub,
cache: [apps],
});
});
req.user.jobPluginData('heroku', heroku, function (err) {
done(err, req.user);
});
})
.catch((err) => {
return done(new Error('Failed to add ssh key: ' + err.message));
heroku.accounts.push({
id: profile.id,
token: token,
email: profile.email,
privkey: priv,
pubkey: pub,
cache: [apps],
});
req.user.jobPluginData('heroku', heroku, function (err) {
done(err, req.user);
});
});
});
});
}
91 changes: 88 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cross-spawn@^7.0.2:
cross-spawn@^7.0.0, cross-spawn@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==
Expand Down Expand Up @@ -626,6 +626,13 @@ emoji-regex@^8.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==

end-of-stream@^1.1.0:
version "1.4.4"
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==
dependencies:
once "^1.4.0"

error-ex@^1.2.0, error-ex@^1.3.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
Expand Down Expand Up @@ -743,6 +750,21 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

execa@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.1.tgz#988488781f1f0238cd156f7aaede11c3e853b4c1"
integrity sha512-SCjM/zlBdOK8Q5TIjOn6iEHZaPHFsMoTxXQ2nvUvtPnuohz3H2dIozSg+etNR98dGoYUp2ENSKLL/XaMmbxVgw==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
human-signals "^1.1.1"
is-stream "^2.0.0"
merge-stream "^2.0.0"
npm-run-path "^4.0.0"
onetime "^5.1.0"
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"

external-editor@^3.0.3:
version "3.1.0"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495"
Expand Down Expand Up @@ -898,6 +920,13 @@ get-stdin@^4.0.1:
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=

get-stream@^5.0.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9"
integrity sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==
dependencies:
pump "^3.0.0"

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/git-raw-commits/-/git-raw-commits-2.0.0.tgz#d92addf74440c14bcc5c83ecce3fb7f8a79118b5"
Expand Down Expand Up @@ -1010,6 +1039,11 @@ hosted-git-info@^2.1.4:
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488"
integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==

human-signals@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==

iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down Expand Up @@ -1136,6 +1170,11 @@ is-plain-obj@^1.1.0:
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4=

is-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3"
integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==

is-text-path@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-text-path/-/is-text-path-1.0.1.tgz#4e1aa0fb51bfbcb3e92688001397202c1775b66e"
Expand Down Expand Up @@ -1385,6 +1424,11 @@ meow@^7.0.0:
type-fest "^0.13.1"
yargs-parser "^18.1.3"

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

methods@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
Expand Down Expand Up @@ -1492,6 +1536,13 @@ normalize-package-data@^2.3.0, normalize-package-data@^2.3.2, normalize-package-
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"

npm-run-path@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==
dependencies:
path-key "^3.0.0"

null-check@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/null-check/-/null-check-1.0.0.tgz#977dffd7176012b9ec30d2a39db5cf72a0439edd"
Expand All @@ -1512,7 +1563,7 @@ object-assign@^4.0.1:
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=

once@^1.3.0:
once@^1.3.0, once@^1.3.1, once@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
Expand Down Expand Up @@ -1670,7 +1721,7 @@ path-is-absolute@^1.0.0:
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=

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

pump@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"
integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==
dependencies:
end-of-stream "^1.1.0"
once "^1.3.1"

punycode@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
Expand Down Expand Up @@ -1913,6 +1972,13 @@ [email protected]:
dependencies:
glob "^7.1.3"

rimraf@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
dependencies:
glob "^7.1.3"

run-async@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
Expand Down Expand Up @@ -2180,6 +2246,11 @@ strip-bom@^3.0.0:
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=

strip-final-newline@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==

strip-indent@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2"
Expand Down Expand Up @@ -2275,13 +2346,27 @@ through@2, "through@>=2.2.7 <3", through@^2.3.6:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=

tmp-promise@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-3.0.2.tgz#6e933782abff8b00c3119d63589ca1fb9caaa62a"
integrity sha512-OyCLAKU1HzBjL6Ev3gxUeraJNlbNingmi8IrHHEsYH8LTmEuhvYfqvhn2F/je+mjf4N58UmZ96OMEy1JanSCpA==
dependencies:
tmp "^0.2.0"

tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==
dependencies:
os-tmpdir "~1.0.2"

tmp@^0.2.0, tmp@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14"
integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==
dependencies:
rimraf "^3.0.0"

trim-newlines@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
Expand Down

0 comments on commit 18a00ee

Please sign in to comment.