Skip to content
This repository has been archived by the owner on Aug 10, 2020. It is now read-only.

Commit

Permalink
Remove getter and lookup by flag > env var > global user config
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWells committed Jul 16, 2019
1 parent 6af91ae commit 5b080b3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BaseCommand extends Command {
async init(err) {
const projectRoot = findRoot(process.cwd())
// Grab netlify API token
const token = this.configToken
const token = getConfigToken()

// Get site config from netlify.toml
const configPath = getConfigPath(projectRoot)
Expand Down Expand Up @@ -63,11 +63,6 @@ class BaseCommand extends Command {
this.netlify.api.accessToken = token
}

get configToken() {
const userId = globalConfig.get('userId')
return globalConfig.get(`users.${userId}.auth.token`)
}

async isLoggedIn() {
try {
await this.netlify.api.getCurrentUser()
Expand All @@ -78,7 +73,7 @@ class BaseCommand extends Command {
}

async authenticate(authToken) {
const token = authToken || process.env.NETLIFY_AUTH_TOKEN || this.configToken
const token = getConfigToken(authToken)
if (!token) {
return this.expensivelyAuthenticate()
} else {
Expand Down Expand Up @@ -152,4 +147,18 @@ class BaseCommand extends Command {
}
}

function getConfigToken(authTokenFromFlag) {
// 1. First honor command flag --auth
if (authTokenFromFlag) {
return authTokenFromFlag
}
// 2. then Check ENV var
if (process.env.NETLIFY_AUTH_TOKEN) {
return process.env.NETLIFY_AUTH_TOKEN
}
// 3. If no env var use global user setting
const userId = globalConfig.get('userId')
return globalConfig.get(`users.${userId}.auth.token`)
}

module.exports = BaseCommand

0 comments on commit 5b080b3

Please sign in to comment.