Skip to content

Commit

Permalink
Lots of spell and grammar checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gugzkumar committed Jan 7, 2020
1 parent d5c7fdf commit 289cb72
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 125 deletions.
2 changes: 2 additions & 0 deletions .env_templates/infrastructure.template.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# run this app locally, not host it to the public.
ENVIRONMENT=

# AWS credentials and region
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# Route53 Configurations
AWS_ROUTE53_HOSTED_ZONE_ID=
SITE_SUB_DOMAIN=
SITE_DOMAIN=
Expand Down
8 changes: 4 additions & 4 deletions .env_templates/local.template.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ ENVIRONMENT=local
CLIENT_UI_URL=http://localhost:4200
API_URL=http://localhost:3000

# AWS Credentials and regions
# AWS credentials and region
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# AWS Cognito configurations
# Cognito configurations
COGNITO_CLIENT_ID=
COGNITO_AUTH_URL=
COGNITO_JWKS_BASE64=

# Bucket where application data is saved
# Folder path where application data is saved
SHEET_DATA_S3_BUCKET=

# AWS Layer ARN, with necessary dependencies for the Python3.7 API
Expand All @@ -27,5 +27,5 @@ LAMBDA_LAYER=
# Tell SAM Local the Path of the API, so it can properly mount volumes
SAM_LOCAL_ABSOLUTE_PATH=

# Comment this out if your okay with SAM sending data
# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
13 changes: 8 additions & 5 deletions .env_templates/remote.template.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@
# This should match the environment of infrastructure it is going to
# be deployed to.
ENVIRONMENT=
SITE_SUB_DOMAIN=

# Should be the same as infrastructure.env
SITE_SUB_DOMAIN
SITE_DOMAIN=

# The Base url for the Frontend and Backend
CLIENT_UI_URL=
API_URL=

# AWS Credentials and regions
# AWS credentials and region
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# Cognito
# Cognito configurations
COGNITO_CLIENT_ID=
COGNITO_AUTH_URL=
COGNITO_JWKS_BASE64=

# Where application data is saved
# Folder path where application data is saved
SHEET_DATA_S3_BUCKET=

# AWS IAM Role ARN for Lambda function. The minimum requirement is for:
# - Read and Write Access to the Sheet Data S3 Bucket
# - Write logs to Cloud Watch
# - The ability to invoke itself
LAMBDA_IAM_ROLE=

Expand All @@ -35,5 +38,5 @@ LAMBDA_LAYER=
# Bucket that facilatates SAM deployments of the Api
API_DEPLOYMENT_S3_BUCKET=

# Comment this out if your okay with SAM sending data
# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
50 changes: 13 additions & 37 deletions .utils/create-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,37 @@ const util = require('util');
var request = require('request-promise-native');
var AWS = require('aws-sdk');

// Template for the infrastructure.env file generated
// Template for the remote.env file generated
const generateRemoteEnvString = (params) => {
return `` +
`# What unique environment is this code will be deployed to.
# This should match the environment of infrastructure it is going to
# be deployed to.
ENVIRONMENT=${params.ENVIRONMENT || ''}
SITE_SUB_DOMAIN=${params.SITE_SUB_DOMAIN || ''}
SITE_DOMAIN=${params.SITE_DOMAIN || ''}
# The Base url for the Frontend and Backend
CLIENT_UI_URL=${params.CLIENT_UI_URL || ''}
API_URL=${params.API_URL || ''}
# AWS Credentials and regions
# AWS credentials and region
AWS_DEFAULT_REGION=${params.AWS_DEFAULT_REGION || ''}
AWS_ACCESS_KEY_ID=${params.AWS_ACCESS_KEY_ID || ''}
AWS_SECRET_ACCESS_KEY=${params.AWS_SECRET_ACCESS_KEY || ''}
# Cognito
# Cognito configurations
COGNITO_CLIENT_ID=${params.COGNITO_CLIENT_ID || ''}
COGNITO_AUTH_URL=${params.COGNITO_AUTH_URL || ''}
COGNITO_JWKS_BASE64=${params.COGNITO_JWKS_BASE64 || ''}
# Where application data is saved
# Folder path where application data is saved
SHEET_DATA_S3_BUCKET=${params.SHEET_DATA_S3_BUCKET || ''}
# AWS IAM Role ARN for Lambda function. The minimum requirement is for:
# - Read and Write Access to the Sheet Data S3 Bucket
# - Write logs to Cloud Watch
# - The ability to invoke itself
LAMBDA_IAM_ROLE=${params.LAMBDA_IAM_ROLE || ''}
Expand All @@ -44,13 +46,14 @@ LAMBDA_IAM_ROLE=${params.LAMBDA_IAM_ROLE || ''}
# - cryptography==2.8
LAMBDA_LAYER=${params.LAMBDA_LAYER || ''}
# SHEET_DATA_S3_BUCKET: S3 bucket that stores all sheets
# Bucket that facilatates SAM deployments of the Api
API_DEPLOYMENT_S3_BUCKET=${params.API_DEPLOYMENT_S3_BUCKET || ''}
# Comment this out if your okay with SAM sending data
# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
`}

// Template for the local.env file generated
const generateLocalEnvString = (params) => {
return `` +
`# This env file does not deploy anything. It is only used for local
Expand All @@ -61,12 +64,12 @@ ENVIRONMENT=${params.ENVIRONMENT || ''}
CLIENT_UI_URL=${params.CLIENT_UI_URL || ''}
API_URL=${params.API_URL || ''}
# AWS Credentials and regions
# AWS credentials and region
AWS_DEFAULT_REGION=${params.AWS_DEFAULT_REGION || ''}
AWS_ACCESS_KEY_ID=${params.AWS_ACCESS_KEY_ID || ''}
AWS_SECRET_ACCESS_KEY=${params.AWS_SECRET_ACCESS_KEY || ''}
# AWS Cognito configurations
# Cognito configurations
COGNITO_CLIENT_ID=${params.COGNITO_CLIENT_ID || ''}
COGNITO_AUTH_URL=${params.COGNITO_AUTH_URL || ''}
COGNITO_JWKS_BASE64=${params.COGNITO_JWKS_BASE64 || ''}
Expand All @@ -82,30 +85,11 @@ LAMBDA_LAYER=${params.LAMBDA_LAYER || ''}
# Tell SAM Local the Path of the API, so it can properly mount volumes
SAM_LOCAL_ABSOLUTE_PATH=${params.SAM_LOCAL_ABSOLUTE_PATH || ''}
# Comment this out if your okay with SAM sending data
# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
`
}



const createEnv = (environment) => {
if(environment === 'local') {
var params = {
};
dotenv.config({path: '../infrastructure.env'});
AWS.config.region = 'us-east-1'
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
});
}
}

/**
* These are the question propmts for this CLI command
*/
Expand All @@ -123,12 +107,7 @@ const questions = [

];


// const describeStacksPromise = util.promisify(cloudformation.describeStacks);

// - Get Stack outputs


// Turn file writer into a promise
const writeFilePromise = util.promisify(fs.writeFile);

// Export CLI Command
Expand Down Expand Up @@ -178,9 +157,6 @@ module.exports = () => {
AWS.config.credentials = new AWS.Credentials(answers.AWS_ACCESS_KEY_ID, answers.AWS_SECRET_ACCESS_KEY);
const cloudformation = new AWS.CloudFormation({ apiVersion: '2010-05-15' });




// Read exports from CloudFormation
return cloudformation.describeStacks({ StackName: infrastructureStackName }).promise()
.then((data) => {
Expand Down
3 changes: 2 additions & 1 deletion .utils/create-infra-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ return `` +
# run this app locally, not host it to the public.
ENVIRONMENT=${params.ENVIRONMENT || ''}
# AWS Creds
# AWS credentials and region
AWS_DEFAULT_REGION=${params.AWS_DEFAULT_REGION || ''}
AWS_ACCESS_KEY_ID=${params.AWS_ACCESS_KEY_ID || ''}
AWS_SECRET_ACCESS_KEY=${params.AWS_SECRET_ACCESS_KEY || ''}
# Route53 Configurations
AWS_ROUTE53_HOSTED_ZONE_ID=${params.AWS_ROUTE53_HOSTED_ZONE_ID || ''}
SITE_SUB_DOMAIN=${params.SITE_SUB_DOMAIN || ''}
SITE_DOMAIN=${params.SITE_DOMAIN || ''}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Cheet Sheet is an open source Content Management System for developers and development teams to Create, Edit and Share code snippets. This accelerates software engineering by having a centralized place where one can see how they or teammates have solved common problems in the past.
<br/><br/>
Setting up Cheet Sheet for you or your organization is simple. All you need is Docker, node and an AWS account. It's 100% Serverless so your costs and infrastructure will automatically grow and shrink based on your needs with minimal effort on your part. ***Read [Getting Started](/docs/getting-started.md)***
Setting up Cheet Sheet for you or your organization is simple. All you need is Docker, Node and an AWS account. It's 100% Serverless so your costs and infrastructure will automatically grow and shrink based on your needs with minimal effort on your part. ***Read [Getting Started](/docs/getting-started.md)***
<br/><br/>
Here is my own instance of the application: https://cheet-sheet.gugz.net/
<br/><br/>
Expand All @@ -25,7 +25,7 @@ If you use the app and like it please leave a star. If you find bugs feel free t
width="700"
/>
</p>
Cheet Sheet is fairly simple to understand. Code snippets are are organized as sheets with self defined category (ex: Programming Language, Framework, tool, etc). Each sheet has two columns of index cards. Every index card has a code snippet. You can copy the entire content of the card by clicking on the copy icon. Everything here is read only.
Cheet Sheet is fairly simple to understand. Code snippets are are organized as sheets with a self defined category (ex: Programming Language, Framework, tool, etc). Each sheet has two columns of index cards. Every index card has a code snippet. You can copy the entire content of the card by clicking on the copy icon. Everything here is read only.

<h2>Personal View</h2>
<p align="left">
Expand Down Expand Up @@ -57,9 +57,9 @@ You can enter Edit mode by manually toggling it on and off. When on, you can add
/>
</p>

Team workspaces are also available for logged in users. Everything you can do on a Personal workspace applies here except that this workspace can be viewed and edited by anyone who is on your team. To create a new workspace all you need to do is simply make a group in the Cognito user pool and add users to it. The name of the group is the name of team.
Team workspaces are also available for logged in users. Everything you can do on a Personal workspace applies here, except that this workspace can be viewed and edited by anyone who is on your team. To create a new Team workspace all you need to do is make a group in the Cognito user pool and add users to it. The name of the group is the name of team.
<br/><br/>
The sheets and index cards that are viewable by the public, are part of the Public Workspace. For a user to modify the sheets in this workspace they must be added to the `admin` user group in cognito.
The sheets and index cards that are viewable by the public, are a part of the Public workspace. For a user to modify the sheets in this workspace they must be added to the `admin` user group in Cognito.

<h2>Built With</h2>
Here are some of the publicly available tools Cheet Sheet was built with:
Expand Down
6 changes: 2 additions & 4 deletions api/src/__core__/authentication_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
from jwt.algorithms import RSAAlgorithm

def apply(event):
"""
"""
headers = event['headers']

if ('Authorization' in headers) and (headers['Authorization']):
try:
# Parse Web Keys and Headers of Access and Id JWT tokens
# Parse Web Keys and Headers of Access JWT tokens
web_keys = { token['kid']: token for token in decode_base64_to_json(COGNITO_JWKS_BASE64)['keys'] }
access_token = headers['Authorization'].replace('Bearer ', '')
access_token_header = jwt.get_unverified_header(access_token)

# Verify Access and Id Token
# Verify Access Token
public_access_key = RSAAlgorithm.from_jwk(json.dumps(web_keys[access_token_header['kid']]))
decoded_access_token = jwt.decode(access_token, public_access_key, algorithms='RS256', verify=True)

Expand Down
16 changes: 4 additions & 12 deletions docker-compose.deploy.code.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# ------------------------------------------------------------------------------
# CODE DOCKER COMPOSE
#
# This Docker Compose is meant to deploy frontend code and backend code
# to a remote environment.
#
# What this deploys:
# - Angular code to an S3 bucket
# - Lambda Function that connects to an API Gateway
# This Docker Compose is meant to deploy/update frontend code and backend code
# to a remote environment. With this we create the Code Cloud Formation stack.
#
# Prerequisites:
# - Cognito Userpool
# - API Gateway
# - S3 Bucket for UI hosting
# - S3 Bucket for App Data Storage
# - IAM Role for a Lambda Function
# Should have permission to update the App Data Storage bucket
# - Infrastructure Stack
# - Lambda Layer with pyjwt==1.7.1 & cryptography==2.8
#
# ------------------------------------------------------------------------------
# # Temporarily set to version 3.2 to support circle CI
Expand Down
19 changes: 8 additions & 11 deletions docker-compose.deploy.infrastructure.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# ------------------------------------------------------------------------------
# INFRASTRUCTURE DOCKER COMPOSE
#
# This Docker Compose is meant provision the necessary AWS resources
# for a user. This includes VPC's, Subnets, Roles and Policies.
# This Docker Compose can deploy the Infrastructure Stack and the Networking Stack
#
# What this sets up:
# - Cognito Userpool
# - S3 Bucket for UI hosting
# - S3 Bucket for App Data Storage
# - S3 Bucket for Code Deployment Artifacts
# Infrastructure Stack Prerequisites:
# - None, this is the first stack deployed
#
# Networking Stack Prerequisites:
# - Infrastructure Stack
# - ACM Certifcate
# - Route53 Domain
#
# Prerequisites:
# - AWS VPC
# - Route53 Domains
# - AWS Certificate Manager
# ------------------------------------------------------------------------------
version: '3.7'
services:
Expand Down
8 changes: 4 additions & 4 deletions docs/architecture-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
/>
</p>
<br/>
When the user visits our web page, the frontend loads from an S3 bucket that saves all of our published Angular Code. Once on the website, REST requests get send to Api Gate way which asks a Lambda function to handle it. Lambda then queries our Sheet Data S3 bucket to read and change our application's state (this is where all our sheets and index cards are saved). We are able to support package dependencies through a Lambda Layer.
When the user visits our web page, the frontend loads from an S3 bucket that saves all of our published Angular Code. When the website get's used, REST requests get send to Api Gateway which asks a Lambda function to handle it. Lambda then queries our Sheet Data S3 bucket to read and change our application's state (this is where all our sheets and index cards are saved). We are able to support package dependencies through a Lambda Layer.
<br/><br/>
Our api uses a monolithic function, this means all requests are handled by the same function.
Our Api uses a monolithic function, this means all requests are handled by the same function.
<br/><br/>
Authentication is handled by Cognito. When the user is a verified, a secure JWT token is received and saved in the browser. Then when making authenticated requests to the api, lambda makes sure that the token is properly signed and encrypted. This is what prevents a user from accessing and editing Workspaces they don't belong to.
<br/><br/>
The Api Deployment does not play an active role in the Infrastructure. But, it is something that is needed when we want to make updates to our API logic.
The Api Deployment bucket does not play an active role in the Infrastructure. But, it is something that is needed when we want to make updates to our API logic.

### Deployment Process
<p align="left">
Expand Down Expand Up @@ -78,7 +78,7 @@ Other things to note:
/>
</p>

This repo also supports local development. This is so we can develop and test new features on our own machine before deploying it. To do this the Api and the UI are dockerized. Both services use mounted volumes so code changes can be reflected in real time.
This repo also supports local development. This is so we can develop and test new features on our own machine before deploying them. To do this the Api and the UI are dockerized. Both services use mounted volumes so code changes can be reflected in real time.

The Api Service uses SAM local. Anytime a request is sent to the Api, SAM will run a temporary Docker container to simulate the Lambda function.

Expand Down
Loading

0 comments on commit 289cb72

Please sign in to comment.