Skip to content

Commit

Permalink
fix: #1289 load credentials from json file instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuong Vu committed May 22, 2020
1 parent 86e7828 commit fc512d4
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 137 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ scripts/jest/.jest-cache

# credentials temp files, using in yarn scan-secrets
.temp-credentials

# credentials file to load
credentials.json
16 changes: 9 additions & 7 deletions packages/web-components-config-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
"lint:fix": "eslint --cache --ext=ts,js src --fix",
"test:ci": "cross-env TZ=UTC jest --ci --colors --coverage --silent --forceExit",
"test:dev": "cross-env TZ=UTC jest --watch --verbose",
"start:dev": "SLS_DEBUG=* serverless offline --verbose",
"build:serverless": "serverless webpack --out dist --stage dev",
"release:dev": "serverless deploy --stage dev",
"release:prod": "node ../../scripts/release/release-serverless.js web-components-config-server",
"start:dev": "yarn build:credentials && SLS_DEBUG=* serverless offline --verbose",
"build:serverless": "yarn build:credentials && serverless webpack --out dist --stage dev",
"release:dev": "yarn build:credentials && serverless deploy --stage dev",
"release:prod": "yarn build:credentials && node ../../scripts/release/release-serverless.js web-components-config-server",
"fetch-config": "yarn config-manager fetchConfig web-components-config-server",
"snyk-protect": "snyk protect",
"prepublish": "npm run snyk-protect"
"prepublish": "npm run snyk-protect",
"build:credentials": "node ./scripts/load-credentials.js"
},
"dependencies": {
"@aws/dynamodb-data-mapper": "^0.7.3",
"@aws/dynamodb-data-mapper-annotations": "^0.7.3",
"@reapit/cognito-auth": "^2.0.19",
"async": "^3.2.0",
"aws-sdk": "^2.682.0",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"color-convert": "^2.0.1",
Expand All @@ -44,17 +46,17 @@
"winston": "^3.2.1"
},
"devDependencies": {
"@reapit/foundations-ts-definitions": "2020-03-08",
"@babel/core": "^7.8.4",
"@babel/preset-env": "^7.8.4",
"@reapit/foundations-ts-definitions": "2020-03-08",
"@types/jest": "^25.1.2",
"@types/morgan": "^1.9.0",
"@types/node": "^13.13.2",
"@types/uuid": "^3.4.6",
"babel-loader": "^8.0.6",
"babel-runtime": "^6.26.0",
"bufferutil": "^4.0.1",
"copy-webpack-plugin": "^5.1.1",
"copy-webpack-plugin": "^6.0.1",
"jest": "^25.1.0",
"json-loader": "^0.5.7",
"serverless-http": "^2.3.2",
Expand Down
12 changes: 12 additions & 0 deletions packages/web-components-config-server/scripts/load-credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path')
const fs = require('fs')

const { AWS_REGION } = require(path.resolve(__dirname, '../config.json'))

const credentials = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: AWS_REGION,
}

fs.writeFileSync(path.resolve(__dirname, '../credentials.json'), JSON.stringify(credentials))
3 changes: 0 additions & 3 deletions packages/web-components-config-server/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ provider:
environment:
APP_ENV: ${self:custom.env.APP_ENV}
NODE_ENV: 'production'
# env from github secrets
AWS_ACCESS_KEY_ID: ${env:AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${env:AWS_SECRET_ACCESS_KEY}

package:
individually: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import path from 'path'
import AWS from 'aws-sdk'
import DynamoDB from 'aws-sdk/clients/dynamodb'
import { DataMapper } from '@aws/dynamodb-data-mapper'

AWS.config.loadFromPath(path.resolve(__dirname, '../../credentials.json'))

const dynamoDBClient = new DynamoDB({
region: process.env.AWS_REGION,
})
Expand Down
12 changes: 11 additions & 1 deletion packages/web-components-config-server/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path')
const slsw = require('serverless-webpack')
const CopyPlugin = require('copy-webpack-plugin')

module.exports = {
entry: slsw.lib.entries,
Expand Down Expand Up @@ -42,7 +43,16 @@ module.exports = {
},
],
},
plugins: [],
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, './credentials.json'),
to: path.resolve(__dirname, 'dist'),
},
],
}),
],
resolve: {
extensions: ['.ts', '.js', '.mjs', '.gql', '.graphql', '.json'],
alias: {
Expand Down
Loading

0 comments on commit fc512d4

Please sign in to comment.