From f841be909b5663ec49b82b397b69f62611c519dc Mon Sep 17 00:00:00 2001 From: thejsj Date: Fri, 13 Jan 2017 17:04:41 -0800 Subject: [PATCH 01/15] Add console.log9 --- lib/middlewares/validate-auth-redirect.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/middlewares/validate-auth-redirect.js b/lib/middlewares/validate-auth-redirect.js index 57317bd2b..fe77c7043 100644 --- a/lib/middlewares/validate-auth-redirect.js +++ b/lib/middlewares/validate-auth-redirect.js @@ -10,6 +10,7 @@ var url = require('url') var log = require('middlewares/logger')(__filename).log +console.log('PROCESS.ENV', process.env) var validRedirectTLDs = process.env.VALID_REDIR_TLDS.split(',') module.exports = function (req, res, next) { From da3f3dcb34a4c1c61a72b72f1d9fceb912ce89cd Mon Sep 17 00:00:00 2001 From: thejsj Date: Thu, 19 Jan 2017 14:53:14 -0800 Subject: [PATCH 02/15] Change error level --- configs/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/.env b/configs/.env index 006c523df..f5d483a72 100644 --- a/configs/.env +++ b/configs/.env @@ -30,7 +30,7 @@ HASHIDS_LENGTH=6 HASHIDS_SALT=VvCCYj8x3xaHs44QiDp9 HELLO_RUNNABLE_GITHUB_ID=10224339 LOG_ERRORS=true -LOG_LEVEL=error +LOG_LEVEL=trace MAX_FILE_DOWNLOAD=52428800 MAX_PAGE_LIMIT=200 MESSENGER_NAMESPACE=runnable:api:messenger: From 3d58d9abaa359856075a5c191e85f8b65205ca72 Mon Sep 17 00:00:00 2001 From: thejsj Date: Thu, 19 Jan 2017 15:05:52 -0800 Subject: [PATCH 03/15] Add console.log --- lib/logger/index.js | 2 +- lib/models/mongo/context-version.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/logger/index.js b/lib/logger/index.js index 046b254f2..2435c884a 100644 --- a/lib/logger/index.js +++ b/lib/logger/index.js @@ -134,7 +134,7 @@ var serializers = assignAndCompose(bunyan.stdSerializers, { var logger = bunyan.createLogger({ name: process.env.APP_NAME, streams: [{ - level: process.env.LOG_LEVEL, + level: 'trace', // process.env.LOG_LEVEL, stream: process.stdout }], serializers: serializers, diff --git a/lib/models/mongo/context-version.js b/lib/models/mongo/context-version.js index 2e86dbbb2..20d6e1250 100644 --- a/lib/models/mongo/context-version.js +++ b/lib/models/mongo/context-version.js @@ -282,8 +282,9 @@ ContextVersionSchema.statics.createWithNewInfraCode = function (props, infraCode }) }) .catch((err) => { - log.error({ err }, 'failed to save infraCodeVersion or contextVersion') - infraCodeVersion.bucket().removeSourceDir(noop) + var bucket = infraCodeVersion.bucket() + log.error({ err, bucket }, 'failed to save infraCodeVersion or contextVersion') + bucket.removeSourceDir(noop) throw err }) } From d8261b4bf7b82e8d15b30b5b45e744b9eefedc55 Mon Sep 17 00:00:00 2001 From: thejsj Date: Thu, 19 Jan 2017 15:12:06 -0800 Subject: [PATCH 04/15] Fix issues with APIg --- lib/models/mongo/context-version.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/models/mongo/context-version.js b/lib/models/mongo/context-version.js index 20d6e1250..41d20b8f3 100644 --- a/lib/models/mongo/context-version.js +++ b/lib/models/mongo/context-version.js @@ -282,9 +282,9 @@ ContextVersionSchema.statics.createWithNewInfraCode = function (props, infraCode }) }) .catch((err) => { - var bucket = infraCodeVersion.bucket() - log.error({ err, bucket }, 'failed to save infraCodeVersion or contextVersion') - bucket.removeSourceDir(noop) + log.error({ err }, 'failed to save infraCodeVersion or contextVersion') + infraCodeVersion.bucket() + infraCodeVersion.removeSourceDir(noop) throw err }) } From cf6e1b46ea726c0e900edd483eb87ddd665cf879 Mon Sep 17 00:00:00 2001 From: thejsj Date: Tue, 24 Jan 2017 15:28:28 -0800 Subject: [PATCH 05/15] Changing seed script --- scripts/seed-version.js | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/scripts/seed-version.js b/scripts/seed-version.js index 01b93b6a1..faf5cd6b2 100644 --- a/scripts/seed-version.js +++ b/scripts/seed-version.js @@ -27,7 +27,13 @@ const rabbitMQ = require('models/rabbitmq/index') const sinon = require('sinon') const User = require('models/mongo/user') -const sources = [{ +const blankSource = { + name: 'Blank', + isSource: true, + body: '# Empty Dockerfile!\n' +} +const sources = [ + { name: 'PHP', isTemplate: true, isSource: true, @@ -117,21 +123,22 @@ function main () { .then(user => { createdBy = { github: user.accounts.github.id } return findOrCreateBlankContext() - .tap(function (blankIcv) { - ctx.blankIcv = blankIcv + .tap((res) => { + let blankIcv = res[0] + let blankContext = res[1] + return createContextVersion(blankSource, blankContext, blankIcv) + .then(cv => createAndBuildBuild(user, blankSource, cv)) + .then(build => createOrUpdateInstance(user, blankSource, build)) + }) + .tap(function (res) { + const blankIcv = res[0] return Promise.each(sources, function (source) { return findOrCreateContext(source) .then(context => { return createNewIcv(source, context, blankIcv) - .then(icv => { - return createContextVersion(source, context, icv) - }) - .then(cv => { - return createAndBuildBuild(user, source, cv) - }) - .then(build => { - return createOrUpdateInstance(user, source, build) - }) + .then(icv => createContextVersion(source, context, icv)) + .then(cv => createAndBuildBuild(user, source, cv)) + .then(build => createOrUpdateInstance(user, source, build)) }) }) }) @@ -154,19 +161,14 @@ function main () { } function findOrCreateBlankContext () { - const blankData = { - name: 'Blank', - isSource: true, - body: '# Empty Dockerfile!\n' - } - return findOrCreateContext(blankData) + return findOrCreateContext(blankSource) .then(blankContext => { return InfraCodeVersion.findOneAsync({ context: blankContext.id }) .then(blankIcv => { if (!blankIcv) { - return createNewIcv(blankData, blankContext) + return createNewIcv(blankSource, blankContext) } - return blankIcv + return [blankIcv, blankContext] }) }) } From 9a695ce297a7c88cf825ebeff3c9b3d565f7c65c Mon Sep 17 00:00:00 2001 From: thejsj Date: Tue, 24 Jan 2017 15:44:25 -0800 Subject: [PATCH 06/15] Fix script --- scripts/seed-version.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/seed-version.js b/scripts/seed-version.js index faf5cd6b2..fe409e9a2 100644 --- a/scripts/seed-version.js +++ b/scripts/seed-version.js @@ -102,7 +102,6 @@ const sources = [ }] sinon.stub(messenger) -var ctx = {} var createdBy /* @@ -128,7 +127,6 @@ function main () { let blankContext = res[1] return createContextVersion(blankSource, blankContext, blankIcv) .then(cv => createAndBuildBuild(user, blankSource, cv)) - .then(build => createOrUpdateInstance(user, blankSource, build)) }) .tap(function (res) { const blankIcv = res[0] @@ -254,4 +252,4 @@ function createOrUpdateInstance (user, data, build) { owner: createdBy }, user) }) -} + From d282ff5290900da99e04fc4b14c0ee9a3d8e58a2 Mon Sep 17 00:00:00 2001 From: thejsj Date: Wed, 1 Feb 2017 11:22:52 -0800 Subject: [PATCH 07/15] Remove console.log and trace --- lib/logger/index.js | 2 +- lib/middlewares/validate-auth-redirect.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/logger/index.js b/lib/logger/index.js index 2435c884a..046b254f2 100644 --- a/lib/logger/index.js +++ b/lib/logger/index.js @@ -134,7 +134,7 @@ var serializers = assignAndCompose(bunyan.stdSerializers, { var logger = bunyan.createLogger({ name: process.env.APP_NAME, streams: [{ - level: 'trace', // process.env.LOG_LEVEL, + level: process.env.LOG_LEVEL, stream: process.stdout }], serializers: serializers, diff --git a/lib/middlewares/validate-auth-redirect.js b/lib/middlewares/validate-auth-redirect.js index fe77c7043..57317bd2b 100644 --- a/lib/middlewares/validate-auth-redirect.js +++ b/lib/middlewares/validate-auth-redirect.js @@ -10,7 +10,6 @@ var url = require('url') var log = require('middlewares/logger')(__filename).log -console.log('PROCESS.ENV', process.env) var validRedirectTLDs = process.env.VALID_REDIR_TLDS.split(',') module.exports = function (req, res, next) { From e2224d242988539164bdb8cd4fd3548439cc993c Mon Sep 17 00:00:00 2001 From: thejsj Date: Wed, 1 Feb 2017 11:27:11 -0800 Subject: [PATCH 08/15] Making the code uglier so no one calls me out in the code review --- scripts/seed-version.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/seed-version.js b/scripts/seed-version.js index fe409e9a2..4fecb5642 100644 --- a/scripts/seed-version.js +++ b/scripts/seed-version.js @@ -126,7 +126,9 @@ function main () { let blankIcv = res[0] let blankContext = res[1] return createContextVersion(blankSource, blankContext, blankIcv) - .then(cv => createAndBuildBuild(user, blankSource, cv)) + .then(cv => { + return createAndBuildBuild(user, blankSource, cv) + }) }) .tap(function (res) { const blankIcv = res[0] @@ -134,9 +136,15 @@ function main () { return findOrCreateContext(source) .then(context => { return createNewIcv(source, context, blankIcv) - .then(icv => createContextVersion(source, context, icv)) - .then(cv => createAndBuildBuild(user, source, cv)) - .then(build => createOrUpdateInstance(user, source, build)) + .then(icv => { + return createContextVersion(source, context, icv) + }) + .then(cv => { + return createAndBuildBuild(user, source, cv) + }) + .then(build => { + return createOrUpdateInstance(user, source, build) + }) }) }) }) From 2c1da5ce4dc13a93a142ed06b3842bc3bf18dffa Mon Sep 17 00:00:00 2001 From: Myztiq Date: Wed, 1 Feb 2017 16:12:16 -0800 Subject: [PATCH 09/15] Added new URL's --- lib/middlewares/passport.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/middlewares/passport.js b/lib/middlewares/passport.js index e791d87ed..32ed5f0f4 100644 --- a/lib/middlewares/passport.js +++ b/lib/middlewares/passport.js @@ -19,10 +19,13 @@ var logger = require('middlewares/logger')(__filename) // Example: // https://github.com/jaredhanson/passport-github/blob/master/examples/login/app.js +var GITHUB_AUTHORIZATION_URL = `${process.env.GITHUB_URL}/login/oauth/authorize` var GITHUB_CALLBACK_URL = process.env.GITHUB_CALLBACK_URL var GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID var GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET var GITHUB_SCOPE = process.env.GITHUB_SCOPE +var GITHUB_TOKEN_URL = `${process.env.GITHUB_URL}/login/oauth/access_token` +var GITHUB_USER_PROFILE_URL = `${process.env.GITHUB_API_URL}/user` // Passport session setup. // To support persistent login sessions, Passport needs to be able to @@ -50,7 +53,10 @@ passport.use(new GitHubStrategy({ clientID: GITHUB_CLIENT_ID, clientSecret: GITHUB_CLIENT_SECRET, callbackURL: GITHUB_CALLBACK_URL, - scope: GITHUB_SCOPE + scope: GITHUB_SCOPE, + authorizationURL: GITHUB_AUTHORIZATION_URL, + tokenURL: GITHUB_TOKEN_URL, + userProfileURL: GITHUB_USER_PROFILE_URL }, manageUser )) From 4488427a90c2db06a860169129199d739437b676 Mon Sep 17 00:00:00 2001 From: Myztiq Date: Wed, 1 Feb 2017 16:28:57 -0800 Subject: [PATCH 10/15] removed GH enterprise validation of emails --- lib/middlewares/passport.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/middlewares/passport.js b/lib/middlewares/passport.js index 32ed5f0f4..c247613c4 100644 --- a/lib/middlewares/passport.js +++ b/lib/middlewares/passport.js @@ -26,6 +26,7 @@ var GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET var GITHUB_SCOPE = process.env.GITHUB_SCOPE var GITHUB_TOKEN_URL = `${process.env.GITHUB_URL}/login/oauth/access_token` var GITHUB_USER_PROFILE_URL = `${process.env.GITHUB_API_URL}/user` +var IS_GITHUB_ENTERPRISE = process.env.IS_GITHUB_ENTERPRISE // Passport session setup. // To support persistent login sessions, Passport needs to be able to @@ -70,10 +71,12 @@ function manageUser (accessToken, refreshToken, profile, done) { function updateOrCreateUser (user, cb) { var primaryEmail = find(profile.emails, hasProps({ primary: true })) - if (!primaryEmail) { - return cb(Boom.badRequest('GitHub account is missing primary email')) - } else if (!primaryEmail.verified) { - return cb(Boom.badRequest('GitHub primary email is not verified')) + if (!IS_GITHUB_ENTERPRISE) { + if (!primaryEmail) { + return cb(Boom.badRequest('GitHub account is missing primary email')) + } else if (!primaryEmail.verified) { + return cb(Boom.badRequest('GitHub primary email is not verified')) + } } profile.accessToken = accessToken profile.refreshToken = refreshToken From c5c3b3eb40ee12f848970a73377bd548753037fd Mon Sep 17 00:00:00 2001 From: Myztiq Date: Thu, 2 Feb 2017 13:40:58 -0800 Subject: [PATCH 11/15] Added temp logging --- lib/models/apis/github.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/models/apis/github.js b/lib/models/apis/github.js index ea0ca4f45..ae1c7c897 100644 --- a/lib/models/apis/github.js +++ b/lib/models/apis/github.js @@ -389,6 +389,7 @@ Github.prototype._runQueryAgainstCache = function (options, cb) { self.httpSend = self._httpSend } if (err) { + logger.log.trace({err}, 'ERROR when calling gh') if (err.code && err.message) { return cb(Boom.create(err.code, err.message)) } else { From 601cad074f9fa143a49f718a361e24ac58512fc3 Mon Sep 17 00:00:00 2001 From: Myztiq Date: Thu, 2 Feb 2017 13:48:21 -0800 Subject: [PATCH 12/15] Added opts --- lib/models/apis/github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/apis/github.js b/lib/models/apis/github.js index ae1c7c897..ac1984f14 100644 --- a/lib/models/apis/github.js +++ b/lib/models/apis/github.js @@ -389,7 +389,7 @@ Github.prototype._runQueryAgainstCache = function (options, cb) { self.httpSend = self._httpSend } if (err) { - logger.log.trace({err}, 'ERROR when calling gh') + logger.log.trace({err, opts}, 'ERROR when calling gh') if (err.code && err.message) { return cb(Boom.create(err.code, err.message)) } else { From 9e89d0f3e0011848dd099ca604e0744c3b356922 Mon Sep 17 00:00:00 2001 From: Myztiq Date: Thu, 2 Feb 2017 13:54:08 -0800 Subject: [PATCH 13/15] Added options --- lib/models/apis/github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/apis/github.js b/lib/models/apis/github.js index ac1984f14..03d656b04 100644 --- a/lib/models/apis/github.js +++ b/lib/models/apis/github.js @@ -389,7 +389,7 @@ Github.prototype._runQueryAgainstCache = function (options, cb) { self.httpSend = self._httpSend } if (err) { - logger.log.trace({err, opts}, 'ERROR when calling gh') + logger.log.trace({err, opts, options}, 'ERROR when calling gh') if (err.code && err.message) { return cb(Boom.create(err.code, err.message)) } else { From cde716d93e2f87f9a98e514a6f2e868eab824e1b Mon Sep 17 00:00:00 2001 From: Myztiq Date: Thu, 2 Feb 2017 14:06:53 -0800 Subject: [PATCH 14/15] Added log --- lib/models/apis/github.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/models/apis/github.js b/lib/models/apis/github.js index 03d656b04..45dab6754 100644 --- a/lib/models/apis/github.js +++ b/lib/models/apis/github.js @@ -58,6 +58,7 @@ function Github (opts) { debug: false, // envIs('development', 'test'), requestMedia: 'application/json' }) + logger.log.info({opts}, 'Github initialized with params') GithubApi.call(this, opts) if (opts.token) { logger.log.info('Github authenticate with token') From 19b8591540f97b6718f718e558d0cc75b0647c34 Mon Sep 17 00:00:00 2001 From: thejsj Date: Fri, 10 Feb 2017 12:41:27 -0800 Subject: [PATCH 15/15] Fix seed-version --- scripts/seed-version.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/seed-version.js b/scripts/seed-version.js index 4fecb5642..84fbc0bca 100644 --- a/scripts/seed-version.js +++ b/scripts/seed-version.js @@ -126,9 +126,6 @@ function main () { let blankIcv = res[0] let blankContext = res[1] return createContextVersion(blankSource, blankContext, blankIcv) - .then(cv => { - return createAndBuildBuild(user, blankSource, cv) - }) }) .tap(function (res) { const blankIcv = res[0] @@ -150,7 +147,7 @@ function main () { }) }) .catch(err => { - console.error('hello runnable error', err) + console.log('Error seeding versions', err) throw err }) .finally(() => { @@ -260,4 +257,5 @@ function createOrUpdateInstance (user, data, build) { owner: createdBy }, user) }) +}