-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor credential checker into its own utility method
- Loading branch information
Showing
7 changed files
with
110 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,65 +1,49 @@ | ||
let chalk = require('chalk') | ||
let chars = require('../chars') | ||
let credCheck = require('./cred-check') | ||
|
||
module.exports = function printBanner (params = {}) { | ||
let { | ||
cwd = process.cwd(), | ||
checkCreds, | ||
inventory, | ||
disableBanner, | ||
disableRegion, | ||
disableProfile, | ||
needsValidCreds, | ||
version = '–', | ||
} = params | ||
let quiet = process.env.ARC_QUIET || process.env.QUIET || params.quiet | ||
|
||
if (disableBanner) return | ||
else { | ||
// Boilerplate | ||
let log = (label, value) => { | ||
if (!quiet) { | ||
console.log(chalk.grey(`${label.padStart(12)} ${chars.buzz}`), chalk.cyan(value)) | ||
} | ||
} | ||
|
||
// Initialize config | ||
process.env.ARC_APP_NAME = inventory.inv.app | ||
|
||
// Check creds | ||
let credError = credCheck({ checkCreds, inventory, needsValidCreds }) | ||
|
||
// App name | ||
let name = process.env.ARC_APP_NAME || 'Architect project manifest not found' | ||
log('App', name) | ||
|
||
// Region | ||
let region = inventory.inv?.aws?.region || process.env.AWS_REGION || 'Region not configured' | ||
if (!disableRegion) { | ||
log('Region', region) | ||
} | ||
|
||
// Profile | ||
let profile = process.env.AWS_ACCESS_KEY_ID && | ||
process.env.ARC_AWS_CREDS !== 'dummy' | ||
? 'Set via environment' | ||
: inventory.inv?.aws?.profile || process.env.AWS_PROFILE || 'Profile not configured' | ||
if (!disableProfile) { | ||
log('Profile', profile) | ||
// Boilerplate | ||
let log = (label, value) => { | ||
if (!quiet) { | ||
console.log(chalk.grey(`${label.padStart(12)} ${chars.buzz}`), chalk.cyan(value)) | ||
} | ||
|
||
// Caller version | ||
// Also: set deprecation status for legacy Arc installs | ||
log('Version', version) | ||
|
||
// cwd | ||
log('cwd', cwd) | ||
|
||
// Blow up (if necessary) after printing basic diagnostic stuff | ||
if (credError) throw credError | ||
|
||
// Space | ||
if (!quiet) console.log() | ||
} | ||
|
||
// App name | ||
let name = inventory.inv.app || 'Architect project manifest not found' | ||
log('App', name) | ||
|
||
// Region | ||
let region = inventory.inv?.aws?.region || | ||
process.env.AWS_REGION || | ||
'Region not configured' | ||
log('Region', region) | ||
|
||
// Profile | ||
let credsViaEnv = process.env.AWS_ACCESS_KEY_ID ? 'Set via environment' : undefined | ||
let profile = credsViaEnv || | ||
inventory.inv?.aws?.profile || | ||
process.env.AWS_PROFILE || | ||
'Not configured / default' | ||
log('Profile', profile) | ||
|
||
// Caller version | ||
// Also: set deprecation status for legacy Arc installs | ||
log('Version', version) | ||
|
||
// cwd | ||
log('cwd', cwd) | ||
|
||
// Space | ||
if (!quiet) console.log() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Credential check | ||
* - aws-lite requires credentials to initialize | ||
* - Architect needs credentials for some things (e.g. Deploy), but also has a variety of offline workflows that interface with AWS service API emulators (e.g. Sandbox) | ||
* - Thus, sometimes it's ok to use dummy creds, but sometimes we need to halt (via this util) | ||
*/ | ||
module.exports = function checkAwsCredentials (params, callback) { | ||
// eslint-disable-next-line | ||
let awsLite = require('@aws-lite/client') | ||
let { inventory } = params | ||
|
||
let promise | ||
if (!callback) { | ||
promise = new Promise((res, rej) => { | ||
callback = (err, result) => err ? rej(err) : res(result) | ||
}) | ||
} | ||
|
||
let errMsg = 'Valid AWS credentials needed to continue; missing or invalid credentials' | ||
awsLite({ | ||
autoloadPlugins: false, | ||
profile: inventory.inv?.aws?.profile, // aws-lite falls back to AWS_PROFILE or 'default' if undefined | ||
region: 'us-west-1', | ||
}) | ||
.then(() => callback()) | ||
.catch(() => callback(Error(errMsg))) | ||
|
||
return promise | ||
} |
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