function* run (context, heroku) { let git = require('../../lib/git')(context); let name = context.flags.app || context.args.app || process.env.HEROKU_APP; function createApp () { let params = { name, organization: context.org, region: context.flags.region, space: context.flags.space, stack: context.flags.stack, kernel: context.flags.kernel, locked: context.flags.locked, }; return heroku.request({ method: 'POST', path: (params.space || context.org) ? '/organizations/apps' : '/apps', body: params, }); } let addAddons = co.wrap(function* (app, addons) { for (let addon of addons) { addon = addon.trim(); let request = heroku.apps(app.name).addons().create({plan: addon}); yield cli.action(`Adding ${cli.color.green(addon)}`, request); } }); function addBuildpack (app, buildpack) { return cli.action(`Setting buildpack to ${cli.color.cyan(buildpack)}`, heroku.request({ method: 'PUT', path: `/apps/${app.name}/buildpack-installations`, headers: {Range: ''}, body: {updates: [{buildpack: buildpack}]}, })); } function createText(name, space) { let text = `Creating ${name ? cli.color.app(name) : 'app'}`; if (space) { text += ` in space ${space}`; } return text; } let app = yield cli.action(createText(name, context.flags.space), {success: false}, createApp()); if (context.flags.region) cli.console.error(`done, region is ${cli.color.yellow(app.region.name)}`); else cli.console.error(`done, stack is ${app.stack.name}`); if (context.flags.addons) yield addAddons(app, context.flags.addons.split(',')); if (context.flags.buildpack) yield addBuildpack(app, context.flags.buildpack); let remoteUrl = context.flags['ssh-git'] ? git.sshGitUrl(app.name) : git.gitUrl(app.name); if (git.inGitRepo() && !context.flags['no-remote']) yield git.createRemote(context.flags.remote || 'heroku', remoteUrl); cli.log(`${cli.color.cyan(app.web_url)} | ${cli.color.green(remoteUrl)}`); }
function * run (context, heroku) { function favoriteApps () { return heroku.request({ host: 'longboard.heroku.com', path: '/favorites', headers: {Range: ''} }).then((apps) => apps.map((app) => app.app_name)) } function fetchMetrics (apps) { const NOW = new Date().toISOString() const YESTERDAY = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)).toISOString() let date = `start_time=${YESTERDAY}&end_time=${NOW}&step=1h` return apps.map((app) => { let types = app.formation.map((p) => p.type) return { dynoErrors: types.map((type) => heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/formation/${type}/metrics/errors?${date}`, headers: {Range: ''}}).catch(() => null)), routerLatency: heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/router-metrics/latency?${date}&process_type=${types[0]}`, headers: {Range: ''}}).catch(() => null), routerErrors: heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/router-metrics/errors?${date}&process_type=${types[0]}`, headers: {Range: ''}}).catch(() => null), routerStatus: heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/router-metrics/status?${date}&process_type=${types[0]}`, headers: {Range: ''}}).catch(() => null) } }) } let apps, data, metrics yield cli.action('Loading', {success: false}, co(function * () { apps = yield favoriteApps() data = yield { orgs: heroku.request({path: '/organizations'}), notifications: heroku.request({host: 'telex.heroku.com', path: '/user/notifications'}), apps: apps.map((app) => ({ app: heroku.get(`/apps/${app}`), formation: heroku.get(`/apps/${app}/formation`), pipeline: heroku.get(`/apps/${app}/pipeline-couplings`).catch(() => null) })) } metrics = yield fetchMetrics(data.apps) })) process.stderr.write('\r') if (process.stderr.clearLine) process.stderr.clearLine() else cli.console.error('\n') if (apps.length > 0) displayApps(data.apps, metrics) else cli.warn(`Add apps to this dashboard by favoriting them with ${cli.color.cmd('heroku apps:favorites:add')}`) cli.log(` See all add-ons with ${cli.color.cmd('heroku addons')}`) let sampleOrg = _.sortBy(data.orgs.filter((o) => o.role !== 'collaborator'), (o) => new Date(o.created_at))[0] if (sampleOrg) cli.log(`See all apps in ${cli.color.yellow.dim(sampleOrg.name)} with ${cli.color.cmd('heroku apps --org ' + sampleOrg.name)}`) cli.log(`See all apps with ${cli.color.cmd('heroku apps --all')}`) displayNotifications(data.notifications) cli.log(` See other CLI commands with ${cli.color.cmd('heroku help')} `) }
function * run (context) { if (context.args.length === 0) { error.exit(1, 'Usage: heroku certs:chain CRT [CRT ...]\nMust specify at least one certificate file.') } let res = yield context.args.map(function (arg) { return readFile(arg) }) let body = yield sslDoctor('resolve-chain', res) cli.console.writeLog(body) }
function * run (context) { if (context.args.length < 2) { error.exit(1, 'Usage: heroku certs:key CRT KEY [KEY ...]\nMust specify one certificate file and at least one key file.') } let res = yield context.args.map(function (arg) { return readFile(arg) }) let body = JSON.parse(yield sslDoctor('resolve-chain-and-key', res, 'Testing for signing key')) cli.console.writeLog(body.key) }
function * run (context, heroku) { let hostname = context.args.hostname let domain = yield cli.action(`Adding ${cli.color.green(hostname)} to ${cli.color.app(context.app)}`, heroku.request({ path: `/apps/${context.app}/domains`, method: 'POST', body: {hostname} })) cli.warn(`Configure your app's DNS provider to point to the DNS Target ${cli.color.green(domain.cname)}. For help, see https://devcenter.heroku.com/articles/custom-domains`) if (domain.status !== 'none') { cli.console.error('') if (context.flags.wait) { yield waitForDomain(context, heroku, domain) } else { cli.console.error(`The domain ${cli.color.green(hostname)} has been enqueued for addition`) let command = `heroku domains:wait ${hostname}` cli.warn(`Run ${cli.color.cmd(command)} to wait for completion`) } } }
updateStatus (status, stop) { let msg = `Running ${cli.color.cyan.bold(this.command)} on ${this.app}... `; if (status) msg += `${cli.color.blue(status)}, ${this.dyno.name}`; if (!this.spinner) { this.spinner = new cli.Spinner({text: msg}); this.spinner.start(); } else this.spinner.update(msg); if (stop) { this.spinner.stop(); cli.console.error(); } }
function * run (context, heroku) { let app = context.app let recipient = context.args.recipient // App transfers in bulk if (context.flags.bulk) { let allApps = yield heroku.get('/apps') let selectedApps = yield getAppsToTransfer(_.sortBy(allApps, 'name')) cli.console.error(`Transferring applications to ${cli.color.magenta(recipient)}... `) for (let app of selectedApps.choices) { try { let appTransfer = new AppTransfer({ heroku: heroku, appName: app.name, recipient: recipient, personalToPersonal: Utils.isValidEmail(recipient) && !Utils.isOrgApp(app.owner), bulk: true }) yield appTransfer.start() } catch (err) { cli.error(err) } } } else { // Single app transfer let appInfo = yield heroku.get(`/apps/${app}`) // Shows warning when app is transferred from a team/org to a personal account if (Utils.isValidEmail(recipient) && Utils.isOrgApp(appInfo.owner.email)) { yield cli.confirmApp(app, context.flags.confirm, 'All collaborators will be removed from this app') } let appTransfer = new AppTransfer({ heroku: heroku, appName: appInfo.name, recipient: recipient, personalToPersonal: Utils.isValidEmail(recipient) && !Utils.isOrgApp(appInfo.owner.email) }) yield appTransfer.start() if (context.flags.locked) { yield lock.run(context) } } }
function* run (context, heroku) { let command = helpers.buildCommand(context.args); if (!command) { cli.error('Usage: heroku run COMMAND\n\nExample: heroku run bash'); process.exit(1); } let p = startDyno(heroku, context.app, context.flags.size, command, context.flags.env); let dyno = yield cli.action(`Running ${cli.color.cyan.bold(command)} on ${context.app}`, {success: false}, p); cli.console.error(` up, ${dyno.name}`); if (context.flags.tail) { yield logDisplayer(heroku, { app: context.app, dyno: dyno.name, tail: true, }); } else { cli.log(`Run ${cli.color.cyan.bold('heroku logs --app ' + dyno.app.name + ' --dyno '+dyno.name)} to view the output.`); } }
function * run (context, heroku) { if (requiresPrompt(context)) { context.flags.owner = yield cli.prompt('Owner of this certificate') context.flags.country = yield cli.prompt('Country of owner (two-letter ISO code)') context.flags.area = yield cli.prompt('State/province/etc. of owner') context.flags.city = yield cli.prompt('City of owner') } let subject = getSubject(context) let domain = context.args.domain let keysize = context.flags.keysize || 2048 let keyfile = `${domain}.key` let certs = yield endpoints(context.app, heroku) var command = getCommand(certs, domain) if (context.flags.selfsigned) { let crtfile = `${domain}.crt` yield openssl.spawn(['req', '-new', '-newkey', `rsa:${keysize}`, '-nodes', '-keyout', keyfile, '-out', crtfile, '-subj', subject, '-x509']) cli.console.error('Your key and self-signed certificate have been generated.') cli.console.error('Next, run:') cli.console.error(`$ heroku certs:${command} ${crtfile} ${keyfile}`) } else { let csrfile = `${domain}.csr` yield openssl.spawn(['req', '-new', '-newkey', `rsa:${keysize}`, '-nodes', '-keyout', keyfile, '-out', csrfile, '-subj', subject]) cli.console.error('Your key and certificate signing request have been generated.') cli.console.error(`Submit the CSR in '${csrfile}' to your preferred certificate authority.`) cli.console.error("When you've received your certificate, run:") cli.console.error(`$ heroku certs:${command} CERTFILE ${keyfile}`) } }
fallback: () => cli.console.error()
spawned.stderr.on('data', (chunk) => { cli.console.writeLog(chunk.toString()); });