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

CloudFront integration v2 #198

Merged
merged 56 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0636c1a
feat: rollout as a code (#161)
Dec 7, 2023
fb79578
fix: remove CodePipeline part from mgmt code
Dec 7, 2023
ed7d52d
fix: remove CodePipeline client
Dec 7, 2023
82c053b
feat: add event and ctx types
Dec 7, 2023
379ec65
fix: set correct type for public URL events
Dec 7, 2023
a60bee4
feat: update secrets manager to V3, retrieve secret in mgmt-lambda
Dec 8, 2023
ec13d5f
feat: introduce deployment settings
Dec 8, 2023
c473539
feat: add endpoints structure and error handlers
Dec 11, 2023
38b445f
feat: add lambda function update
Dec 11, 2023
b1d0d72
fix: remove aws-sdk v2 usage
Dec 12, 2023
0bb22ce
feat: use AWS SDK v3 Client mock for testing
Dec 13, 2023
07664bc
fix: update logging
Dec 13, 2023
aeb49c8
fix: update handleResult tests with comparing hrefs
Dec 14, 2023
02fea3e
chore: remove unused test function
Dec 15, 2023
1aa3dc8
feat: pass AWS clients into handlers
Dec 18, 2023
d5823f2
test: add tests for mgmt-lambda handlers
Dec 18, 2023
8f43aa1
test: add basic test for update handler
Dec 18, 2023
0257aae
test: add basic tests for lambda call
Dec 18, 2023
bc94c65
test: update app test
Dec 18, 2023
a767db4
test: fix mgmt-lambda app test
Dec 18, 2023
1562ec4
ci: update coverage source
Dec 18, 2023
ae47160
chore: lint fix
Dec 18, 2023
ddf8ac7
test: add more test for mgmt-lambda handler
Dec 18, 2023
0fcf92e
chore: address review comments, fix tests
Dec 19, 2023
0b29764
feat: reworked getting env, updated tests
Dec 19, 2023
09820f7
chore: else block
Dec 19, 2023
403680c
feat: update lambda existence check
Dec 19, 2023
ab3caa5
feat: add settings secret, update mgmt lambda permissions (#162)
Dec 20, 2023
c884027
feat: introduce mgmt-token scheme for authorization (#176)
Dec 20, 2023
2818c30
feat: upgrade Lambda functions runtime to Node 20
Dec 20, 2023
1e0ae54
feat: increase timeout for Fingerprint lambda
Dec 20, 2023
429fcc3
ci: update node version to v20
Dec 20, 2023
bf7d7aa
test: update guard rules for the template
Dec 20, 2023
5db4df9
chore: change URLs to Lambda functions v2 (#179)
Dec 21, 2023
3736d14
feat: improve error handling in mgmt-lambda
Dec 22, 2023
2c5e2af
chore: fix exception name
Dec 22, 2023
6929756
feat(mgmt-lambda-update): introduce error codes
Orkuncakilkaya Dec 28, 2023
c8cec1b
test: add mgmt lambda update endpoint tests
Orkuncakilkaya Jan 2, 2024
1fa0e42
chore: review changes for inter-482
Orkuncakilkaya Jan 3, 2024
b8953f9
chore: lambda check null or undefined
Orkuncakilkaya Jan 4, 2024
51a4dbe
chore: xErrorCode to code and verbose error code names
Orkuncakilkaya Jan 4, 2024
5b89dca
chore: use readonly instead of getter for code field
Orkuncakilkaya Jan 8, 2024
09d209d
chore: make code field public
Orkuncakilkaya Jan 8, 2024
64a947b
test: use await expect instead of assertions
Orkuncakilkaya Jan 8, 2024
5a57276
test: add all cases for update endpoint
Orkuncakilkaya Jan 9, 2024
a88941c
feat: rework logging (#184)
Jan 24, 2024
efddf15
ci: publish template.yml into S3 bucket (#185)
Feb 11, 2024
2970364
feat: update all cache behavior that has fingerprint pro association …
Feb 14, 2024
a32e4ff
fix: cloudformation templatex (#188)
Feb 14, 2024
5135b1b
feat: update package management (#189)
Feb 20, 2024
b13e517
chore: update linter (#193)
Feb 23, 2024
c7c8f30
chore: remove @aws types from tsconfig
Feb 26, 2024
b567a8b
chore: remove whatwg-fetch
Feb 26, 2024
dce602c
chore: uncomment tests
Feb 26, 2024
51780d4
test: adjust tests to the new mocker
Feb 28, 2024
4f8196d
chore: rename Cloudfront -> CloudFront
Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/check-cloudformation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Rules to check CloudFormation template

on:
pull_request:
paths:
- cloudformation/*

jobs:
validate:
name: Validate template
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install cfn-guard
run: curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/aws-cloudformation/cloudformation-guard/main/install-guard.sh | sh

- name: Validate
run: ~/.guard/bin/cfn-guard validate --rules cloudformation/rules.guard --data cloudformation/template.yml


2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
name: Build project and run CI checks
uses: fingerprintjs/dx-team-toolkit/.github/workflows/build-typescript-project.yml@v1
with:
nodeVersion: 16
nodeVersion: 20
2 changes: 1 addition & 1 deletion .github/workflows/coverage-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
pull-requests: write
uses: fingerprintjs/dx-team-toolkit/.github/workflows/coverage-diff.yml@v1
with:
nodeVersion: 16
nodeVersion: 20
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: fingerprintjs/dx-team-toolkit/.github/workflows/docs-and-coverage.yml@v1
with:
skip-docs-step: true
node-version: 16
node-version: 20
prepare-gh-pages-commands: |
mv coverage/lcov-report ./gh-pages/coverage

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
name: 'Build project, run CI checks and publish new release'
uses: fingerprintjs/dx-team-toolkit/.github/workflows/release-typescript-project.yml@v1
with:
nodeVersion: 16
nodeVersion: 20
secrets:
GH_RELEASE_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20
24 changes: 20 additions & 4 deletions buildspec.release-lambda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,50 @@ phases:
- zip -r latest.zip fingerprintjs-pro-cloudfront-lambda-function.js
- zip -r latest_mgmt.zip fingerprintjs-pro-cloudfront-mgmt-lambda-function.js

- aws s3api get-object --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/lambda_latest.zip previous.zip
- aws s3api get-object --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/mgmt_lambda_latest.zip previous_mgmt.zip
- aws s3api get-object --bucket fingerprint-pro-cloudfront-integration-lambda-function --key releaseV2/lambda_latest.zip previous.zip
- aws s3api get-object --bucket fingerprint-pro-cloudfront-integration-lambda-function --key releaseV2/mgmt_lambda_latest.zip previous_mgmt.zip
- aws s3api get-object --bucket fingerprint-pro-cloudfront-integration-lambda-function --key releaseV2/template.yml previous-template.yml

- unzip previous.zip -d previous
- unzip previous_mgmt.zip -d previous_mgmt

- diff previous/fingerprintjs-pro-cloudfront-lambda-function.js fingerprintjs-pro-cloudfront-lambda-function.js; diffStatus=$?
- diff previous_mgmt/fingerprintjs-pro-cloudfront-mgmt-lambda-function.js fingerprintjs-pro-cloudfront-mgmt-lambda-function.js; mgmtDiffStatus=$?
- diff previous-template.yml template.yml; templateDiffStatus=$?

- echo $diffStatus
- echo $mgmtDiffStatus
- echo $templateDiffStatus

- >-
echo "Processing fingerprintjs-pro-cloudfront-lambda-function.js"
if [ $diffStatus -eq 0 ]; then
echo "Files are the same. Don't need to upload the file."
elif [ $diffStatus -eq 1 ]; then
echo "Files are different. Uploading new version."
aws s3api put-object --body latest.zip --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/lambda_latest.zip
aws s3api put-object --body latest.zip --bucket fingerprint-pro-cloudfront-integration-lambda-function --key releaseV2/lambda_latest.zip
else
echo "There was something wrong with the diff command."
fi

- >-
echo "Processing fingerprintjs-pro-cloudfront-mgmt-lambda-function.js"
if [ $mgmtDiffStatus -eq 0 ]; then
echo "Files are the same. Don't need to upload the file."
elif [ $mgmtDiffStatus -eq 1 ]; then
echo "Files are different. Uploading new version."
aws s3api put-object --body latest_mgmt.zip --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/mgmt_lambda_latest.zip
aws s3api put-object --body latest_mgmt.zip --bucket fingerprint-pro-cloudfront-integration-lambda-function --key releaseV2/mgmt_lambda_latest.zip
else
echo "There was something wrong with the diff command."
fi

- >-
echo "Processing template.yml"
if [ $templateDiffStatus -eq 0 ]; then
echo "Files are the same. Don't need to upload the file."
elif [ $templateDiffStatus -eq 1 ]; then
echo "Files are different. Uploading new version."
aws s3api put-object --body template.yml --bucket fingerprint-pro-cloudfront-integration-lambda-function --key releaseV2/template.yml
else
echo "There was something wrong with the diff command."
fi
97 changes: 0 additions & 97 deletions cloudformation/minimal-template.yml

This file was deleted.

101 changes: 101 additions & 0 deletions cloudformation/rules.guard
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
let SecretName = "FingerprintIntegrationSettings"
let DistributionId = "ABCDEF123456"
let FpjsBehaviorPath = "fpjs"
let FpjsGetResultPath = "result"
let FpjsAgentDownloadPath = "agent"
let FpjsPreSharedSecret = "secret-string-123"

rule check_conditions {
Conditions.CreateCloudFrontDistribution exists
Conditions.CreateCloudFrontDistribution is_struct

Conditions.AttachDomainToCloudFront exists
Conditions.AttachDomainToCloudFront is_struct
}

rule check_secret {
Resources.FingerprintIntegrationSettingsSecret {
Type == "AWS::SecretsManager::Secret"
Properties {
SecretString !empty
}
}
}

rule check_lambda {
Resources.FingerprintProCloudFrontLambda {
Type == "AWS::Serverless::Function"
Properties {
Handler == "fingerprintjs-pro-cloudfront-lambda-function.handler"
Runtime == "nodejs20.x"
CodeUri == "s3://fingerprint-pro-cloudfront-integration-lambda-function/releaseV2/lambda_latest.zip"
Timeout == 10
}
}
}

rule check_lambda_role {
Resources.FpIntLambdaFunctionExecutionRole {
Properties {
AssumeRolePolicyDocument {
some Statement[*].Principal.Service == "lambda.amazonaws.com"
some Statement[*].Principal.Service == "edgelambda.amazonaws.com"
}
}
}
}

rule check_lambda_version {
Resources.FingerprintProCloudFrontLambdaVersion {
Type == "AWS::Lambda::Version"
}
}

rule check_mgmt_lambda {
Resources.FingerprintProMgmtLambda {
Type == "AWS::Serverless::Function"
Properties {
Handler == "fingerprintjs-pro-cloudfront-mgmt-lambda-function.handler"
Runtime == "nodejs20.x"
CodeUri == "s3://fingerprint-pro-cloudfront-integration-lambda-function/releaseV2/mgmt_lambda_latest.zip"
Timeout == 120
}
}
}

rule check_mgmt_lambda_role {
Resources.FpMgmtLambdaFunctionExecutionRole {
Properties {
AssumeRolePolicyDocument {
some Statement[*].Principal.Service == "lambda.amazonaws.com"
}
}
}
}

rule check_cache_policy {
Resources.FingerprintProCDNCachePolicy {
Type == "AWS::CloudFront::CachePolicy"
Properties {
CachePolicyConfig.MinTTL == 0
CachePolicyConfig.MaxTTL == 180
CachePolicyConfig.DefaultTTL == 180
}
}
}

rule check_cloudfront_distribution {
Resources.CloudFrontDistribution {
Type == "AWS::CloudFront::Distribution"
Condition exists
}
}

rule check_output {
Outputs {
LambdaFunctionName exists
CachePolicyName exists
CloudFrontDistributionId exists
IsCloudFrontDistributionCreatedByDeployment exists
}
}
Loading
Loading