Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-lite #229

Merged
merged 17 commits into from
Feb 2, 2024
Merged
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [ 14.x, 16.x, 18.x ]
node-version: [ 16.x, 18.x, 20.x ]
os: [ windows-latest, ubuntu-latest, macOS-latest ]

# Go
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Notify
uses: sarisia/actions-status-discord@v1
# Only fire alert once
if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '14.x' && matrix.os == 'ubuntu-latest'
if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '20.x' && matrix.os == 'ubuntu-latest'
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "build and test"
Expand Down
73 changes: 31 additions & 42 deletions banner/index.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,49 @@
let chalk = require('chalk')
let chars = require('../chars')
let initAWS = require('./init-aws')

module.exports = function printBanner (params = {}) {
let {
cwd = process.cwd(),
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
initAWS({ inventory, needsValidCreds })

// App name
let name = process.env.ARC_APP_NAME || 'Architect project manifest not found'
log('App', name)

// Region
let region = process.env.AWS_REGION || '@aws region / AWS_REGION not configured'
if (!disableRegion) {
log('Region', region)
}

// Profile
let profile = process.env.ARC_AWS_CREDS === 'env'
? 'Set via environment'
: process.env.AWS_PROFILE || '@aws profile / AWS_PROFILE not configured'
if (!disableProfile) {
log('Profile', profile)
}

// Caller version
// Also: set deprecation status for legacy Arc installs
log('Version', version)

// cwd
log('cwd', cwd)

// Space
// Boilerplate
let log = (label, value) => {
if (!quiet) {
console.log()
console.log(chalk.grey(`${label.padStart(12)} ${chars.buzz}`), chalk.cyan(value))
}
}

// 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()
}
116 changes: 0 additions & 116 deletions banner/init-aws.js

This file was deleted.

20 changes: 20 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

---

## [4.0.0] 2023-10-19

### Added

- Added `checkCreds` method for manually performing basic AWS credential checks


### Changed

- Initializing the Architect banner is significantly faster, as it no longer has any interactions with `aws-sdk`
- Breaking change: banner initialization no longer has any direct responsibility for credential checking
- Related: banner initialization no longer mutates `AWS_PROFILE`, or uses `ARC_AWS_CREDS` as a signal to other modules about credential loading
- Modules relying on the banner for credential-related operations must review the changes and refactor accordingly
- Banner initialization no longer utilizes `disableRegion` or `disableProfile` params when printing
- Transitioned from `aws-sdk` to [`aws-lite`](https://aws-lite.org)
- Added Node.js 20.x to test matrix
- Breaking change: removed support for Node.js 14.x (now EOL, and no longer available to created in AWS Lambda)

---

## [3.1.7 - 3.1.9] 2023-04-22

### Changed
Expand Down
29 changes: 29 additions & 0 deletions check-creds/index.js
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
}
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let banner = require('./banner')
let chars = require('./chars')
let checkCreds = require('./check-creds')
let deepFrozenCopy = require('./deep-frozen-copy')
let fingerprint = require('./fingerprint')
let getLambdaName = require('./get-lambda-name')
Expand All @@ -8,8 +9,9 @@ let toLogicalID = require('./to-logical-id')
let updater = require('./updater')

module.exports = {
banner, // Prints banner and loads basic env vars and AWS creds
banner, // Prints banner
chars, // Returns platform appropriate characters for CLI UI printing
checkCreds, // Performs basic AWS credential check
deepFrozenCopy, // Fast deep frozen object copy
fingerprint, // Generates public/static.json for `@static fingerprint true`
getLambdaName, // Get Lambda name from Arc path
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@architect/utils",
"version": "3.1.9",
"version": "4.0.0-RC.4",
"description": "Common utility functions",
"main": "index.js",
"repository": {
Expand All @@ -20,8 +20,9 @@
"author": "Brian LeRoux <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"@aws-lite/client": "^0.15.1",
"chalk": "4.1.2",
"glob": "~10.2.2",
"glob": "~10.3.10",
"path-sort": "~0.1.0",
"restore-cursor": "3.1.0",
"run-series": "~1.1.9",
Expand All @@ -30,15 +31,13 @@
},
"devDependencies": {
"@architect/eslint-config": "~2.1.2",
"@architect/inventory": "~3.4.3",
"aws-sdk": "^2.1363.0",
"@architect/inventory": "~3.6.5",
"cross-env": "~7.0.3",
"eslint": "~8.49.0",
"eslint": "~8.56.0",
"proxyquire": "~2.1.3",
"sinon": "~15.0.4",
"tap-arc": "~1.0.0",
"tape": "~5.6.6",
"temp-write": "4.0.0"
"sinon": "~17.0.1",
"tap-arc": "1.1.0",
"tape": "~5.7.4"
},
"eslintConfig": {
"extends": "@architect/eslint-config"
Expand Down
Loading
Loading