Permalink
Browse files

heroku config working -- worker.js is just a shell atm

  • Loading branch information...
jaredly committed Oct 15, 2013
1 parent 0c7459f commit df4d73c30bc2f54c974ba70820bd03e6d74c9b36
Showing with 196 additions and 20 deletions.
  1. +1 −0 .gitignore
  2. +14 −7 config/config.html
  3. +11 −0 config/config.js
  4. +10 −0 config/config.less
  5. +4 −7 lib/api.js
  6. +43 −0 package.json
  7. +98 −0 static/icon.svg
  8. +7 −6 webapp.js
  9. +8 −0 worker.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -1,16 +1,23 @@
<h3>Heroku!</h3>
<div ng-show="userIsCreator">
- <a href="/ext/heroku/oauth?redirect=/[[ project.name ]]/config" class="btn btn-success">Add a Heroku Account</a>
- <div ng-show="accounts.length">
- Linked Accounts:
- <select ng-model="account" ng-options="account.email for account in userConfig.accounts"></select>
- <div>
+ <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-show="userConfig.accounts.length">
+ <div class="accounts">
+ <label>Linked Accounts</label>
+ <select ng-model="account"
+ ng-options="account.email for account in userConfig.accounts track by account.id"></select>
+ <a href="/ext/heroku/oauth?redirect=/[[ project.name ]]/config"
+ class="btn btn-success">Add a Heroku Account</a>
+ </div>
+ <div class="apps">
<label>Apps</label>
- <select ng-model="config.app" ng-options="app.name for app in account.cache"></select>
+ <select ng-model="config.app" ng-options="app.name for app in account.cache track by app.id"></select>
<button ng-click="getApps()" class="btn"><i class="icon-refresh"></i> Refresh Apps List</button>
</div>
+ <button ng-click="save()" class="btn btn-primary">Save</button>
</div>
- <button ng-click="save()" class="btn btn-primary">Save</button>
</div>
<p ng-hide="userIsCreator">
Only the creator can setup this project for heroku
View
@@ -2,9 +2,20 @@
app.controller('HerokuController', ['$scope', '$element', function ($scope, $element) {
$scope.$watch('userConfigs.heroku', function (value) {
$scope.userConfig = value;
+ if (!$scope.account) {
+ $scope.account = value.accounts[0];
+ }
});
$scope.$watch('configs[branch.name].heroku.config', function (value) {
$scope.config = value;
+ if (value.app && $scope.userConfig.accounts) {
+ for (var i=0; i<$scope.userConfig.accounts.length; i++) {
+ if ($scope.userConfig.accounts[i].id === value.app.account) {
+ $scope.account = $scope.userConfig.accounts[i];
+ break;
+ }
+ }
+ }
});
$scope.saving = false;
$scope.save = function () {
View
@@ -0,0 +1,10 @@
+
+#plugin-heroku {
+ select {
+ margin-bottom: 0;
+ }
+
+ .apps {
+ margin-bottom: 10px;
+ }
+}
View
@@ -10,7 +10,6 @@ module.exports = {
function getApps(aid, token, done) {
superagent.get(API + '/apps')
.set('Authorization', 'Bearer ' + token)
- .accept('application/vnd.heroku+json')
.end(function (res) {
if (res.status !== 200) return done(new Error('Status: ' + res.status + '; ' + res.text))
done(null, res.body.map(function (app) {
@@ -27,14 +26,12 @@ function getApps(aid, token, done) {
}
function addKey(token, key, done) {
- superagent.post(API + '/account/keys')
+ superagent.post(API + '/user/keys')
.set('Authorization', 'Bearer ' + token)
- .send({
- public_key: key
- })
- .accept('application/vnd.heroku+json')
+ .set('Content-type', 'text/ssh-authkey')
+ .send(key)
.end(function (res) {
- if (res.status !== 201) return done(new Error('Status: ' + res.status + '; ' + res.text))
+ if (res.status !== 200) return done(new Error('Status: ' + res.status + '; ' + res.text))
done()
})
}
View
@@ -0,0 +1,43 @@
+{
+ "name": "strider-heroku",
+ "version": "0.0.0",
+ "description": "Heroku deployment for Strider",
+ "main": "webapp.js",
+ "directories": {
+ "test": "test"
+ },
+ "scripts": {
+ "test": "make test"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/Strider-CD/strider-heroku.git"
+ },
+ "keywords": [
+ "strider",
+ "heroku",
+ "deploy",
+ "oauth",
+ "cd"
+ ],
+ "author": "Jared Forsyth <jared@jaredforsyth.com>",
+ "license": "MIT",
+ "gitHead": "0c7459f2fa57385c0b6bc71e98ef01be99fad226",
+ "readmeFilename": "Readme.md",
+ "strider": {
+ "id": "heroku",
+ "type": "job",
+ "title": "Heroku",
+ "webapp": "webapp.js",
+ "worker": "worker.js",
+ "icon": "icon.png",
+ "config": {
+ "controller": "HerokuController"
+ }
+ },
+ "dependencies": {
+ "ssh-keypair": "~1.0.0",
+ "superagent": "~0.15.5",
+ "passport-heroku": "0.0.2"
+ }
+}
View
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="744.09448819"
+ height="1052.3622047"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.48.2 r9819"
+ sodipodi:docname="New document 1">
+ <defs
+ id="defs4">
+ <clipPath
+ id="clipPath3018"
+ clipPathUnits="userSpaceOnUse">
+ <path
+ id="path3020"
+ d="M 0,31 88,31 88,0 0,0 0,31 z" />
+ </clipPath>
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="7.9195959"
+ inkscape:cx="371.95329"
+ inkscape:cy="521.66007"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:snap-bbox="true"
+ inkscape:snap-nodes="false"
+ inkscape:window-width="978"
+ inkscape:window-height="690"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:window-maximized="0">
+ <inkscape:grid
+ type="xygrid"
+ id="grid3072" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1">
+ <rect
+ style="fill:none;fill-opacity:1;stroke:none"
+ id="rect3076"
+ width="35"
+ height="35"
+ x="354.54724"
+ y="517.36218" />
+ <g
+ id="g3066"
+ transform="matrix(1.0877588,0,0,1.0877588,7.9787219,-44.219484)">
+ <g
+ transform="matrix(1.25,0,0,-1.25,346.61975,519.51781)"
+ id="g3026">
+ <path
+ id="path3028"
+ style="fill:#6862a7;fill-opacity:1;fill-rule:evenodd;stroke:none"
+ d="m 0,0 c 0,0.968 -0.785,1.754 -1.754,1.754 l -15.57,0 c -0.967,0 -1.754,-0.786 -1.754,-1.754 l 0,-20.551 c 0,-0.969 0.787,-1.754 1.754,-1.754 l 15.57,0 c 0.969,0 1.754,0.785 1.754,1.754 L 0,0 z m -1.613,-23.146 -15.852,0 c -1.355,0 -2.455,1.1 -2.455,2.456 l 0,20.83 c 0,1.356 1.1,2.455 2.455,2.455 l 15.852,0 c 1.357,0 2.455,-1.099 2.455,-2.455 l 0,-20.83 c 0,-1.356 -1.098,-2.456 -2.455,-2.456"
+ inkscape:connector-curvature="0" />
+ </g>
+ <g
+ transform="matrix(1.25,0,0,-1.25,327.79163,543.99968)"
+ id="g3030">
+ <path
+ id="path3032"
+ style="fill:#6862a7;fill-opacity:1;fill-rule:nonzero;stroke:none"
+ d="M 0,0 0,5.821 2.91,2.911 0,0 z m 9.801,14.991 -3.069,0 c 1.108,1.35 2.106,3.665 2.106,3.665 l 3.174,0 c 0,0 -0.543,-1.509 -2.211,-3.665 m -1.647,-15.009 0,10.223 c 0,0 0.664,2.445 -8.191,-1.002 -0.016,-0.043 -0.016,9.453 -0.016,9.453 l 2.893,0.017 0,-6.084 c 0,0 8.103,3.191 8.103,-2.42 l 0,-10.187 -2.789,0 z"
+ inkscape:connector-curvature="0" />
+ </g>
+ </g>
+ </g>
+</svg>
View
@@ -43,17 +43,18 @@ module.exports = {
throw new Error('Heroku plugin misconfigured. client_id and client_secret required')
}
passport.use(new HerokuStrategy({
- client_id: config.clientId,
- client_secret: config.clientSecret,
+ clientID: config.clientId,
+ clientSecret: config.clientSecret,
passReqToCallback: true,
+ scope: ['global'],
callbackURL: context.config.server_name + '/ext/heroku/oauth/callback'
}, validateAuth))
},
globalRoutes: function (app, context) {
app.get('/oauth', context.auth.requireUser, function (req, res, next) {
if (req.query.redirect) {
- req.session.set('heroku_auth_redirect', req.query.redirect)
+ req.session.heroku_auth_redirect = req.query.redirect
}
next()
}, context.passport.authenticate('heroku'));
@@ -62,7 +63,7 @@ module.exports = {
context.passport.authenticate('heroku', { failureRedirect: '/account#heroku' }),
function(req, res) {
// Successful authentication, redirect home.
- res.redirect(req.session.get('heroku_auth_redirect') || '/account#heroku');
+ res.redirect(req.session.heroku_auth_redirect || '/account#heroku');
});
app.get('/apps/:id', function (req, res) {
@@ -76,7 +77,7 @@ module.exports = {
}
}
if (!account) return res.send(404, 'Account not found')
- api.getApps(account.token, function (err, apps) {
+ api.getApps(account.id, account.token, function (err, apps) {
if (err) return res.send(500, 'failed to get apps from api: ' + err.message)
account.cache = apps
req.user.markModified('jobplugins')
@@ -92,7 +93,7 @@ module.exports = {
function validateAuth(req, token, refresh, profile, done) {
var heroku = req.user.jobplugins.heroku = req.user.jobplugins.heroku || {}
if (!heroku.accounts) heroku.accounts = []
- api.getApps(token, function (err, apps) {
+ api.getApps(profile.id, token, function (err, apps) {
if (err) return done(new Error('failed to retrieve apps list: ' + err.message))
keypair(profile.email + ' - strider', function (err, priv, pub) {
if (err) return done(new Error('Failed to generate keypair; ' + err.message))
View
@@ -0,0 +1,8 @@
+
+module.exports = {
+ init: function (config, job, context, cb) {
+ cb(null, {
+ deploy: 'echo "heroku deploy"'
+ })
+ }
+}

0 comments on commit df4d73c

Please sign in to comment.