Browse Source

Prevent `--token` from overwriting the user config (#851)

* Respect currently scoped team

* Allow `--token` to overwrite the config token

* Fixed syntax

* Print an error when switching team
master
Leo Lamprecht 8 years ago
committed by Matheus Fernandes
parent
commit
734c78f8fc
  1. 14
      src/now.js
  2. 4
      src/providers/sh/commands/logout.js
  3. 2
      src/providers/sh/commands/logs.js
  4. 2
      src/providers/sh/commands/teams.js

14
src/now.js

@ -22,6 +22,7 @@ const providers = require('./providers')
const configFiles = require('./util/config-files')
const checkForUpdates = require('./util/updates')
const getUser = require('./util/get-user')
const exit = require('./util/exit')
const NOW_DIR = getNowDir()
const NOW_CONFIG_PATH = configFiles.getConfigFilePath()
@ -386,12 +387,17 @@ const main = async (argv_) => {
// no credentials are defined
ctx.argv = ctx.argv.splice(0, 3)
} else {
console.log(error('No existing credentials found. Please ' +
console.error(error('No existing credentials found. Please ' +
'`now login` to log in or pass `--token`'))
process.exit(1)
await exit(1)
}
}
if (hasToken && subcommand === 'switch') {
console.error(error('This command doesn\'t work with `--token`. Please use `--team`.'))
await exit(1)
}
if (hasToken) {
const {argv} = ctx
const tokenIndex = argv.indexOf(hasToken) + 1
@ -399,7 +405,7 @@ const main = async (argv_) => {
if (!token) {
console.log(error(`You defined ${param(hasToken)}, but it\'s missing a value`))
process.exit(1)
await exit(1)
}
const obj = {
@ -426,7 +432,7 @@ const main = async (argv_) => {
token
})
ctx.config.sh = {user}
ctx.config.sh = Object.assign(ctx.config.sh, { user })
}
try {

4
src/providers/sh/commands/logout.js

@ -141,7 +141,7 @@ const logout = async () => {
let tokenId
try {
tokenId = await getTokenId(argv.token || related.token)
tokenId = await getTokenId(related.token)
} catch (err) {
spinner.fail('Not able to get token id on logout')
process.exit(1)
@ -152,7 +152,7 @@ const logout = async () => {
}
try {
await revokeToken(argv.token || related.token, tokenId)
await revokeToken(related.token, tokenId)
} catch (err) {
spinner.fail('Could not revoke token on logout')
process.exit(1)

2
src/providers/sh/commands/logs.js

@ -125,7 +125,7 @@ const main = async ctx => {
types = argv.all ? [] : ['command', 'stdout', 'stderr', 'exit']
const {authConfig: { credentials }, config: { sh }} = ctx
const {token} = argv.token || credentials.find(item => item.provider === 'sh')
const {token} = credentials.find(item => item.provider === 'sh')
await printLogs({ token, sh })
}

2
src/providers/sh/commands/teams.js

@ -94,7 +94,7 @@ const main = async ctx => {
}
const {authConfig: { credentials }, config} = ctx
const {token} = argv.token || credentials.find(item => item.provider === 'sh')
const {token} = credentials.find(item => item.provider === 'sh')
try {
await run({ token, config })

Loading…
Cancel
Save