Skip to content

Commit

Permalink
Merge pull request #121 from globaldatanet/linting
Browse files Browse the repository at this point in the history
Linting
  • Loading branch information
daknhh authored Jun 18, 2023
2 parents f29e55a + 689e0a6 commit 5b8cf89
Show file tree
Hide file tree
Showing 14 changed files with 5,564 additions and 18,888 deletions.
62 changes: 29 additions & 33 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,36 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parserOptions": {
"project": true
},
"rules": {
"semi": [2, "always"],
"eqeqeq": 2,
"indent": [2, 2, {"SwitchCase": 1}],
"semi": ["error", "always"],
"indent": ["error", 2, { "SwitchCase": 1 }],
"quotes": ["error", "double"],
"linebreak-style": "off",
"array-bracket-newline": "off",
"array-bracket-spacing": ["error", "never"],
"no-trailing-spaces": "off",
"padded-blocks": "off",
"arrow-body-style": "off",
"init-declarations": "off",
"comma-dangle": "off",
"keyword-spacing": [0, {"before": true, "after": true, "overrides": null}],
"prefer-template": "off",
"id-blacklist": "off",
"no-console": "off",
"no-sync": "off",
"complexity": "off",
"max-statements": "off",
"array-element-newline": "off",
"object-curly-spacing": "off",
"template-curly-spacing": "off",
"camelcase": "off",
"no-use-before-define": "off",
"id-length": "off",
"id-match": "off",
"max-len": "off",
"no-magic-numbers": "off",
"no-underscore-dangle": "off",
"no-process-env": "off",
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/naming-convention": [
"error",
{
"selector": ["variableLike", "method"],
"format": ["strictCamelCase"]
},
{
"selector": ["variable"],
"format": ["UPPER_CASE"],
"modifiers": ["const","global"],
"types": ["array", "boolean", "number", "string"]
},
{
"selector": ["class","interface","enum", "typeParameter", "typeAlias"],
"format": ["StrictPascalCase"]
},
{
"selector": ["enumMember"],
"format": ["UPPER_CASE"]
}
]
}
}
}
28 changes: 28 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Linting

on:
pull_request:
branches:
- "**"
push:
branches:
- master
- linting
workflow_dispatch:

jobs:
nodejs-test:
runs-on: ubuntu-latest
strategy:
matrix:
version: [18, 20]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Change Log

## Released

## 3.2.6
### Add
- Linting Github Action for typescript 18 & 20
### Fixed
- Bump @aws-sdk/client-cloudformation from 3.321.1 to 3.353.0
- Bump @aws-sdk/client-cloudwatch 3.341.0 to 3.353.0
- Bump @aws-sdk/client-fms 3.342.0 to 3.353.0
- Bump @aws-sdk/client-pricing 3.341 .0 to 3.353.0
- Bump @aws-sdk/client-service-quotas 3.342.0 to 3.353.0
- Bump @aws-sdk/client-wafv2 from 3.321.1 to 3.353.0
- Bump @mhlabs/cfn-diagram from 1.1.32 to 1.1.36
- Add more Linting rules see ./eslintrc

## 3.2.5
### Fixed
- Pricing Calculation - Check for Shield Advanced State
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<a href="https://github.com/globaldatanet/aws-firewall-factory/actions/workflows/linting.yml"><img alt="github-badge" src="https://github.com/globaldatanet/aws-firewall-factory/actions/workflows/linting.yml/badge.svg"></a>
[![Mentioned in Awesome CDK](https://awesome.re/mentioned-badge.svg)](https://github.com/kolomied/awesome-cdk)
[![License: Apache2](https://img.shields.io/badge/license-Apache%202-lightgrey.svg)](http://www.apache.org/licenses/) [![cdk](https://img.shields.io/badge/aws_cdk-v2-orange.svg)](https://docs.aws.amazon.com/cdk/v2/guide/home.html)
[![latest](https://img.shields.io/badge/latest-release-yellow.svg)](https://github.com/globaldatanet/aws-firewall-factory/releases)
[![gdn](https://img.shields.io/badge/opensource-@globaldatanet-%2300ecbd)](https://globaldatanet.com/opensource) [![dakn](https://img.shields.io/badge/by-dakn-%23ae0009.svg)](https://github.com/daknhh)
[![language](https://img.shields.io/badge/typescript-3.9.7-purple.svg)](https://docs.aws.amazon.com/cdk/v2/guide/home.html)
[![TypeScript](https://badges.frapsoft.com/typescript/love/typescript.png?v=101)](https://github.com/ellerbrock/typescript-badges/)
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=AWS%20FIREWALL%20FACTORY%20-%20Deploy%2C%20update%2C%20and%20stage%20your%20WAFs%20while%20managing%20them%20centrally%20via%20FMS&url=https://github.com/globaldatanet/aws-firewall-factory&hashtags=aws,security,waf)
[![roadmap](https://img.shields.io/badge/public-roadmap-yellow.svg)](https://github.com/orgs/globaldatanet/projects/1)

Expand Down
25 changes: 14 additions & 11 deletions bin/aws-firewall-factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/restrict-plus-operands */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { FirewallStack } from "../lib/firewall-stack";
import { PrerequisitesStack } from "../lib/prerequisites-stack";
import * as cdk from "aws-cdk-lib";
import { realpathSync, existsSync } from "fs";
import { validatewaf, validateprerequisites } from "../lib/tools/config-validator";
import { Config, Prerequisites, PriceRegions, RegionString } from "../lib/types/config";
import { isPolicyQuotaReached, isWcuQuotaReached, setOutputsFromStack, initRuntimeProperties } from "../lib/tools/helpers";
import {isPriceCalculated, GetCurrentPrices} from "../lib/tools/price-calculator";
import {isPriceCalculated, getCurrentPrices} from "../lib/tools/price-calculator";
import * as packageJsonObject from "../package.json";


Expand All @@ -18,21 +20,22 @@ const FIREWALL_FACTORY_VERSION = packageJsonObject.version;
/**
* relative path to config file imported from the env PROCESS_PARAMETERS
*/
const configFile = process.env.PROCESS_PARAMETERS;
const CONFIGFILE = process.env.PROCESS_PARAMETERS;

/**
* the region into which the stack is deployed
*/
let deploymentRegion = "";

if (configFile && existsSync(configFile)) {
if (CONFIGFILE && existsSync(CONFIGFILE)) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const config: Config = require(realpathSync(configFile));
const config: Config = require(realpathSync(CONFIGFILE));
// eslint-disable-next-line @typescript-eslint/no-var-requires
const prerequisites: Prerequisites = require(realpathSync(configFile));
const prerequisites: Prerequisites = require(realpathSync(CONFIGFILE));
if(process.env.PREREQUISITE === "true"){
if(validateprerequisites(prerequisites)){
(async () => {
// eslint-disable-next-line @typescript-eslint/require-await
void (async () => {
console.log(`
█████╗ ██╗ ██╗███████╗ ███████╗██╗██████╗ ███████╗██╗ ██╗ █████╗ ██╗ ██╗ ███████╗ █████╗ ██████╗████████╗ ██████╗ ██████╗ ██╗ ██╗
██╔══██╗██║ ██║██╔════╝ ██╔════╝██║██╔══██╗██╔════╝██║ ██║██╔══██╗██║ ██║ ██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗╚██╗ ██╔╝
Expand Down Expand Up @@ -66,7 +69,7 @@ if (configFile && existsSync(configFile)) {
╚═╝ ╚═╝ ╚══╝╚══╝ ╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
`);
console.log("\n🏷 Version: ","\x1b[4m",FIREWALL_FACTORY_VERSION,"\x1b[0m");
console.log("\n 🧪 Validation of your ConfigFile: \n 📂 " + configFile + "\n\n");
console.log("\n 🧪 Validation of your ConfigFile: \n 📂 " + CONFIGFILE + "\n\n");
console.error("\u001B[31m","🚨 Invalid Configuration File 🚨 \n\n","\x1b[0m" + JSON.stringify(validateprerequisites.errors, null, 2)+ "\n\n");
process.exit(1);
}
Expand All @@ -91,7 +94,7 @@ if (configFile && existsSync(configFile)) {
console.log("\n🏷 Version: ","\x1b[4m",FIREWALL_FACTORY_VERSION,"\x1b[0m");
console.log("👤 AWS Account used: ","\x1b[33m","\n " + process.env.CDK_DEFAULT_ACCOUNT,"\x1b[0m");
console.log("🌎 CDK deployment region:","\x1b[33m","\n "+deploymentRegion,"\x1b[0m \n");
(async () => {
void (async () => {
const isNewStack = (config.General.DeployHash === "");
const runtimeProperties = initRuntimeProperties();
if(isNewStack){
Expand Down Expand Up @@ -127,7 +130,7 @@ if (configFile && existsSync(configFile)) {
account: process.env.CDK_DEFAULT_ACCOUNT,
},
});
await GetCurrentPrices(PriceRegions[deploymentRegion as RegionString], runtimeProperties, config,deploymentRegion);
await getCurrentPrices(PriceRegions[deploymentRegion as RegionString], runtimeProperties, config,deploymentRegion);
await isPriceCalculated(runtimeProperties);
})();
} else {
Expand All @@ -140,13 +143,13 @@ if (configFile && existsSync(configFile)) {
╚═╝ ╚═╝ ╚══╝╚══╝ ╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
`);
console.log("\n🏷 Version: ","\x1b[4m",FIREWALL_FACTORY_VERSION,"\x1b[0m");
console.log("\n 🧪 Validation of your ConfigFile: \n 📂 " + configFile + "\n\n");
console.log("\n 🧪 Validation of your ConfigFile: \n 📂 " + CONFIGFILE + "\n\n");
console.error("\u001B[31m","🚨 Invalid Configuration File 🚨 \n\n","\x1b[0m" + JSON.stringify(validatewaf.errors, null, 2)+ "\n\n");
process.exit(1);
}
}
}
else {
console.log("File", configFile, "not found. - NO CDK ERROR");
console.log("File", CONFIGFILE, "not found. - NO CDK ERROR");
}

Loading

0 comments on commit 5b8cf89

Please sign in to comment.