Skip to content

Commit

Permalink
utils and fix docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
gugzkumar committed Dec 22, 2019
1 parent 34c2ff5 commit 7c3cf69
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 836 deletions.
3 changes: 3 additions & 0 deletions .utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodemon
package-lock.json
node_modules
10 changes: 0 additions & 10 deletions .utils/construct_env.js

This file was deleted.

62 changes: 62 additions & 0 deletions .utils/create-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const dotenv = require('dotenv');
var AWS = require('aws-sdk');
// const cloudformation = new AWS.CloudFormation({apiVersion: '2010-05-15'});
AWS.config.region = 'us-east-1'

LOCAL_ENV_VARS = {
AWS_DEFAULT_REGION:'',
AWS_ACCESS_KEY_ID:'',
AWS_SECRET_ACCESS_KEY:'',
SAM_LOCAL_ABSOLUTE_PATH:'',
SAM_CLI_TELEMETRY:'',
LAMBDA_LAYER:'',
APP_ADMIN_USER:'',
PUBLIC_SHEETS_FOLDER:'',
SHEET_DATA_S3_BUCKET:'',
COGNITO_ID_JWK_BASE4:'',
COGNITO_ACCESS_JWK_BASE4:''
}

const createLocalEnv = () => {

}

const createEnv = (environment) => {
if(environment === 'local') {
var params = {
};
dotenv.config({path: '../infrastructure.env'});
AWS.config.credentials = new AWS.Credentials(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY);
const cloudformation = new AWS.CloudFormation({
apiVersion: '2010-05-15'
});
cloudformation.listExports(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
}

module.exports = {
createEnv
};


// const readline = require('readline').createInterface({
// input: process.stdin,
// output: process.stdout
// })
//
// readline.question(`What's your name?`, (name) => {
// console.log(`Hi ${name}!`)
// readline.close()
// })
// console.log('HELLO');
// AWS_DEFAULT_REGION=
// AWS_ACCESS_KEY_ID=
// AWS_SECRET_ACCESS_KEY=
// SAM_LOCAL_ABSOLUTE_PATH=
// SAM_CLI_TELEMETRY=0
// PUBLIC_SHEETS_FOLDER=
// SHEET_DATA_S3_BUCKET=
// COGNITO_JWKS_BASE4=
50 changes: 50 additions & 0 deletions .utils/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const program = require('commander');
const { createEnv } = require('./create-env');
const { prompt } = require('inquirer');
const request = require('request');

program
.description('Cheet Sheet Utility Functions');

program
.command('create-env <environment>')
.description('Add a contact')
.action( (environment) => {
createEnv(environment);
});

program
.command('generate COGNITO_JWKS_BASE64')
.description('Add a contact')
.action( (environment) => {

prompt([
{
type : 'input',
name : 'cognitoUserPoolId',
message : 'Where is your Cognito User Pool ID'
},
{
type : 'input',
name : 'awsRegion',
message : 'What is your AWS region'
}
]).then(answers => {
const { cognitoUserPoolId, awsRegion } = answers
request(`https://cognito-idp.${awsRegion}.amazonaws.com/${cognitoUserPoolId}/.well-known/jwks.json`, { json: false }, (err, res, body) => {

if (err) { return console.log(err); }
console.log('Retreived the following Json Web Key Set (JWKS) from AWS');
console.log(body);
let buff = Buffer.from(body);
console.log();
console.log('Here is the JWKS converted to Base64. Set this as the value of COGNITO_JWKS_BASE64 in local.env or remote.env.');
let base64body = buff.toString('base64');
console.log(base64body);
});
});

});


program.parse(process.argv);
18 changes: 18 additions & 0 deletions .utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "cheet-sheet-utils",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "node main.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"dependencies": {
"aws-sdk": "^2.592.0",
"commander": "^4.0.1",
"dotenv": "^8.2.0",
"inquirer": "^7.0.1",
"request": "^2.88.0"
}
}
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ services:
build: ./client-ui
container_name: serverless-angular-client-ui
env_file:
local.env
.env
volumes:
- ./client-ui:/usr/src/app
- /usr/src/app/node_modules
ports:
- "4200:4200"
command: sh -c "node build-env.js && npm start"
# --------------------------------------------------------------------------
# BACKEND WRITTEN IN AWS SAM LOCAL
# --------------------------------------------------------------------------
serverless-lambda-api:
build: ./api
container_name: serverless-lambda-api
env_file:
local.env
.env
volumes:
- ./api:/app
- /var/run/docker.sock:/var/run/docker.sock
Expand Down
Loading

0 comments on commit 7c3cf69

Please sign in to comment.