This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
158 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
'use strict'; | ||
const cli = require('heroku-cli-util') | ||
const child = require('child_process') | ||
const log = require('../lib/log') | ||
|
||
const cli = require('heroku-cli-util'); | ||
const co = require('co'); | ||
const child = require('child_process'); | ||
const log = require('../lib/log'); | ||
|
||
module.exports = function(topic) { | ||
module.exports = function (topic) { | ||
return { | ||
topic: topic, | ||
command: 'login', | ||
flags: [{ name: 'verbose', char: 'v', hasValue: false }], | ||
flags: [{name: 'verbose', char: 'v', hasValue: false}], | ||
description: 'Logs in to the Heroku Docker registry', | ||
needsApp: false, | ||
needsAuth: true, | ||
run: cli.command(co.wrap(login)) | ||
}; | ||
}; | ||
run: cli.command(login) | ||
} | ||
} | ||
|
||
function* login(context, heroku) { | ||
let herokuHost = process.env.HEROKU_HOST || 'heroku.com'; | ||
let registry = `registry.${ herokuHost }`; | ||
let password = context.auth.password; | ||
async function login (context, heroku) { | ||
let herokuHost = process.env.HEROKU_HOST || 'heroku.com' | ||
let registry = `registry.${ herokuHost }` | ||
let password = context.auth.password | ||
|
||
try { | ||
let user = yield dockerLogin(registry, password, context.flags.verbose); | ||
let user = await dockerLogin(registry, password, context.flags.verbose) | ||
} | ||
catch (err) { | ||
cli.error(`Error: docker login exited with ${ err }`); | ||
cli.hush(err.stack || err); | ||
cli.error(`Error: docker login exited with ${ err }`) | ||
cli.hush(err.stack || err) | ||
} | ||
} | ||
|
||
function dockerLogin(registry, password, verbose) { | ||
function dockerLogin (registry, password, verbose) { | ||
return new Promise((resolve, reject) => { | ||
let args = [ | ||
'login', | ||
'--username=_', | ||
`--password=${ password }`, | ||
registry | ||
]; | ||
log(verbose, args); | ||
child.spawn('docker', args, { stdio: 'inherit' }) | ||
] | ||
log(verbose, args) | ||
child.spawn('docker', args, {stdio: 'inherit'}) | ||
.on('exit', (code, signal) => { | ||
if (signal || code) reject(signal || code); | ||
else resolve(); | ||
}); | ||
}); | ||
if (signal || code) reject(signal || code) | ||
else resolve() | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.