Browse Source

Google Cloud Platform support is working again

master
Leo Lamprecht 7 years ago
parent
commit
665e36eddf
  1. 44
      src/now.js
  2. 21
      src/providers/gcp/login.js

44
src/now.js

@ -28,7 +28,7 @@ const NOW_AUTH_CONFIG_PATH = configFiles.getAuthConfigFilePath()
const GLOBAL_COMMANDS = new Set(['help']) const GLOBAL_COMMANDS = new Set(['help'])
const main = async (argv_): Promise<number> => { const main = async (argv_) => {
await checkForUpdates() await checkForUpdates()
const argv = mri(argv_, { const argv = mri(argv_, {
@ -64,7 +64,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
if (!nowDirExists) { if (!nowDirExists) {
@ -91,7 +91,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
let config let config
@ -107,7 +107,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
try { try {
@ -119,7 +119,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
} else { } else {
config = getDefaultCfg() config = getDefaultCfg()
@ -133,7 +133,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
} }
@ -149,7 +149,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
let authConfig = null let authConfig = null
@ -165,7 +165,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
try { try {
@ -178,7 +178,7 @@ const main = async (argv_): Promise<number> => {
'No `credentials` list found inside' 'No `credentials` list found inside'
) )
) )
return 1 return
} }
for (const [i, { provider }] of authConfig.credentials.entries()) { for (const [i, { provider }] of authConfig.credentials.entries()) {
@ -189,7 +189,7 @@ const main = async (argv_): Promise<number> => {
`Missing \`provider\` key in entry with index ${i}` `Missing \`provider\` key in entry with index ${i}`
) )
) )
return 1 return
} }
if (!(provider in providers)) { if (!(provider in providers)) {
@ -199,7 +199,7 @@ const main = async (argv_): Promise<number> => {
`Unknown provider "${provider}"` `Unknown provider "${provider}"`
) )
) )
return 1 return
} }
} }
} catch (err) { } catch (err) {
@ -210,7 +210,7 @@ const main = async (argv_): Promise<number> => {
)}": ` + err.message )}": ` + err.message
) )
) )
return 1 return
} }
} else { } else {
authConfig = getDefaultAuthCfg() authConfig = getDefaultAuthCfg()
@ -225,7 +225,7 @@ const main = async (argv_): Promise<number> => {
err.message err.message
) )
) )
return 1 return
} }
} }
@ -250,7 +250,7 @@ const main = async (argv_): Promise<number> => {
`An unexpected error occurred in config ${subcommand}: ${err.stack}` `An unexpected error occurred in config ${subcommand}: ${err.stack}`
) )
) )
return 1 return
} }
} }
@ -269,7 +269,7 @@ const main = async (argv_): Promise<number> => {
'Both a directory and a provider are known' 'Both a directory and a provider are known'
) )
) )
return 1 return
} }
suppliedProvider = targetOrSubcommand suppliedProvider = targetOrSubcommand
@ -299,12 +299,13 @@ const main = async (argv_): Promise<number> => {
`"${NOW_CONFIG_PATH}" is not a valid provider` `"${NOW_CONFIG_PATH}" is not a valid provider`
) )
) )
return 1 return
} }
} }
} }
const provider: Object = providers[suppliedProvider || defaultProvider] const providerName = suppliedProvider || defaultProvider
const provider: Object = providers[providerName]
let subcommand let subcommand
@ -324,7 +325,7 @@ const main = async (argv_): Promise<number> => {
'Both a directory and a subcommand are known' 'Both a directory and a subcommand are known'
) )
) )
return 1 return
} }
if (subcommandExists) { if (subcommandExists) {
@ -353,14 +354,17 @@ const main = async (argv_): Promise<number> => {
} }
try { try {
return provider[subcommand](ctx) await provider[subcommand](ctx)
} catch (err) { } catch (err) {
console.error( console.error(
error( error(
`An unexpected error occurred in provider ${subcommand}: ${err.stack}` `An unexpected error occurred in provider ${subcommand}: ${err.stack}`
) )
) )
return 1 }
if (providerName === 'gcp') {
process.exit()
} }
} }

21
src/providers/gcp/login.js

@ -57,8 +57,7 @@ const serverListen = ({ server, port }) => {
}) })
} }
function login(ctx) { const login = ctx => new Promise(async resolve => {
return new Promise(async resolve => {
let credentialsIndex = ctx.authConfig.credentials.findIndex( let credentialsIndex = ctx.authConfig.credentials.findIndex(
cred => cred.provider === 'gcp' cred => cred.provider === 'gcp'
) )
@ -81,7 +80,7 @@ function login(ctx) {
if (!yes) { if (!yes) {
console.log(aborted('No changes made.')) console.log(aborted('No changes made.'))
resolve(0) return
} }
} }
@ -104,7 +103,7 @@ function login(ctx) {
if (_error) { if (_error) {
// the user didn't give us permission // the user didn't give us permission
console.log(aborted(`No changes made.`)) console.log(aborted(`No changes made.`))
return resolve(1) return
} }
if (code) { if (code) {
@ -145,7 +144,7 @@ function login(ctx) {
`Got unexpected status code from Google: ${response.status}` `Got unexpected status code from Google: ${response.status}`
) )
) )
return resolve(1) return
} }
} catch (err) { } catch (err) {
debug( debug(
@ -158,7 +157,7 @@ function login(ctx) {
err.stack err.stack
) )
) )
return resolve(1) return
} }
try { try {
@ -179,7 +178,7 @@ function login(ctx) {
err.message err.message
) )
) )
resolve(1) return
} }
const now = new Date() const now = new Date()
@ -228,8 +227,9 @@ function login(ctx) {
`Credentials and project saved in ${param(humanize(getNowDir()))}.` `Credentials and project saved in ${param(humanize(getNowDir()))}.`
) )
) )
resolve(1)
} }
resolve()
}) })
let shouldRetry = true let shouldRetry = true
@ -257,7 +257,7 @@ function login(ctx) {
` ${PORTS.join(', ').replace()}` ` ${PORTS.join(', ').replace()}`
) )
) )
return resolve(1) return
} }
const query = { const query = {
@ -270,7 +270,6 @@ function login(ctx) {
} }
opn(USER_URL + '?' + encodeQuery(query)) opn(USER_URL + '?' + encodeQuery(query))
}) })
}
module.exports = login module.exports = login

Loading…
Cancel
Save