Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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:
Expand Down
19 changes: 14 additions & 5 deletions lib/middlewares/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ 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`
var IS_GITHUB_ENTERPRISE = process.env.IS_GITHUB_ENTERPRISE

// Passport session setup.
// To support persistent login sessions, Passport needs to be able to
Expand Down Expand Up @@ -50,7 +54,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
))
Expand All @@ -64,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
Expand Down
2 changes: 2 additions & 0 deletions lib/models/apis/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -389,6 +390,7 @@ Github.prototype._runQueryAgainstCache = function (options, cb) {
self.httpSend = self._httpSend
}
if (err) {
logger.log.trace({err, opts, options}, 'ERROR when calling gh')
if (err.code && err.message) {
return cb(Boom.create(err.code, err.message))
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/models/mongo/context-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ ContextVersionSchema.statics.createWithNewInfraCode = function (props, infraCode
})
.catch((err) => {
log.error({ err }, 'failed to save infraCodeVersion or contextVersion')
infraCodeVersion.bucket().removeSourceDir(noop)
infraCodeVersion.bucket()
infraCodeVersion.removeSourceDir(noop)
throw err
})
}
Expand Down
32 changes: 19 additions & 13 deletions scripts/seed-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -96,7 +102,6 @@ const sources = [{
}]
sinon.stub(messenger)

var ctx = {}
var createdBy

/*
Expand All @@ -117,8 +122,13 @@ 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)
})
.tap(function (res) {
const blankIcv = res[0]
return Promise.each(sources, function (source) {
return findOrCreateContext(source)
.then(context => {
Expand All @@ -137,7 +147,7 @@ function main () {
})
})
.catch(err => {
console.error('hello runnable error', err)
console.log('Error seeding versions', err)
throw err
})
.finally(() => {
Expand All @@ -154,19 +164,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]
})
})
}
Expand Down Expand Up @@ -253,3 +258,4 @@ function createOrUpdateInstance (user, data, build) {
}, user)
})
}