diff --git a/.gitignore b/.gitignore index 5ec5d3f89..73d79aa01 100644 --- a/.gitignore +++ b/.gitignore @@ -53,7 +53,4 @@ yarn-error.log # Certs .srl -script/rootCA.* -script/server.crt -script/server.csr -script/server.key +certificate/ diff --git a/package.json b/package.json index 3823ae2f9..3b577b7c0 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "packages/zapp/**" ], "scripts": { + "clean": "yarn workspace @flyteconsole/client-app clean", "start": "yarn workspace @flyteconsole/client-app start", "start:prod": "yarn workspace @flyteconsole/client-app start:prod", "build:prod": "yarn workspace @flyteconsole/client-app build:prod", diff --git a/packages/zapp/console/env.js b/packages/zapp/console/env.js index 4cc3d8b22..a8a9224db 100644 --- a/packages/zapp/console/env.js +++ b/packages/zapp/console/env.js @@ -20,6 +20,12 @@ const BASE_URL = process.env.BASE_URL || ''; */ const ASSETS_PATH = `${BASE_URL}/assets/`; +/** + * Certificate path required for local development, should not include trailing '/'. + * Located at top level of the repository in script folder + */ +const CERTIFICATE_PATH = '../../../script/certificate'; + // Defines a file to be required which will provide implementations for // any user-definable code. const PLUGINS_MODULE = process.env.PLUGINS_MODULE; @@ -43,6 +49,7 @@ module.exports = { ENABLE_GA, GA_TRACKING_ID, ASSETS_PATH, + CERTIFICATE_PATH, LOCAL_DEV_HOST, processEnv: { ADMIN_API_URL, diff --git a/packages/zapp/console/index.js b/packages/zapp/console/index.js index b38b1cb08..e25b3fc02 100644 --- a/packages/zapp/console/index.js +++ b/packages/zapp/console/index.js @@ -42,8 +42,8 @@ const port = process.env.PORT || 3000; if (env.ADMIN_API_USE_SSL === 'https') { const fs = require('fs'); const https = require('https'); - var privateKey = fs.readFileSync('../../../script/server.key'); - var certificate = fs.readFileSync('../../../script/server.crt'); + var privateKey = fs.readFileSync(`${env.CERTIFICATE_PATH}/server.key`); + var certificate = fs.readFileSync(`${env.CERTIFICATE_PATH}/server.crt`); server = https .createServer( diff --git a/packages/zapp/console/package.json b/packages/zapp/console/package.json index 5757cfa3a..fa1706344 100644 --- a/packages/zapp/console/package.json +++ b/packages/zapp/console/package.json @@ -9,7 +9,6 @@ "main": "index.js", "scripts": { "clean": "rm -rf dist", - "prebuild": "yarn run clean", "build": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' webpack --config webpack.dev.config.ts --mode=development", "build:prod": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' NODE_ENV=production webpack --config webpack.prod.config.ts --mode=production --progress", "start": "webpack serve --open --config webpack.dev.config.ts --hot", diff --git a/packages/zapp/console/src/common/utils.ts b/packages/zapp/console/src/common/utils.ts index 4bfbb2c23..0f5973571 100644 --- a/packages/zapp/console/src/common/utils.ts +++ b/packages/zapp/console/src/common/utils.ts @@ -1,4 +1,3 @@ -import { env } from 'common/env'; import { Protobuf } from 'flyteidl'; import * as Long from 'long'; diff --git a/packages/zapp/console/src/components/Executions/ExecutionDetails/types.ts b/packages/zapp/console/src/components/Executions/ExecutionDetails/types.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/zapp/console/src/components/Launch/LaunchForm/BlobInput.tsx b/packages/zapp/console/src/components/Launch/LaunchForm/BlobInput.tsx index 4f18dcb26..900167338 100644 --- a/packages/zapp/console/src/components/Launch/LaunchForm/BlobInput.tsx +++ b/packages/zapp/console/src/components/Launch/LaunchForm/BlobInput.tsx @@ -10,7 +10,7 @@ import { import { makeStyles, Theme } from '@material-ui/core/styles'; import { BlobDimensionality } from 'models/Common/types'; import * as React from 'react'; -import { blobFormatHelperText, blobUriHelperText, defaultBlobValue } from './constants'; +import { blobFormatHelperText, blobUriHelperText } from './constants'; import { InputProps } from './types'; import { getLaunchInputId, isBlobValue } from './utils'; diff --git a/packages/zapp/console/src/components/common/DelayedMount.tsx b/packages/zapp/console/src/components/common/DelayedMount.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/zapp/console/src/components/common/FilterableNamedEntityList.tsx b/packages/zapp/console/src/components/common/FilterableNamedEntityList.tsx index 3c3be4fed..74afadbb9 100644 --- a/packages/zapp/console/src/components/common/FilterableNamedEntityList.tsx +++ b/packages/zapp/console/src/components/common/FilterableNamedEntityList.tsx @@ -1,4 +1,4 @@ -import { Checkbox, debounce, FormControlLabel, FormGroup, Typography } from '@material-ui/core'; +import { Checkbox, debounce, FormControlLabel, FormGroup } from '@material-ui/core'; import { makeStyles, Theme } from '@material-ui/core/styles'; import { NamedEntity } from 'models/Common/types'; import * as React from 'react'; diff --git a/packages/zapp/console/src/components/common/SearchableList.tsx b/packages/zapp/console/src/components/common/SearchableList.tsx index acf02cdf1..6a6798df9 100644 --- a/packages/zapp/console/src/components/common/SearchableList.tsx +++ b/packages/zapp/console/src/components/common/SearchableList.tsx @@ -130,4 +130,4 @@ export const SearchableList = (props: SearchableListProps) => { ); }; -export { SearchResult, PropertyGetter }; +export type { SearchResult, PropertyGetter }; diff --git a/packages/zapp/console/src/components/common/SearchableNamedEntityList.tsx b/packages/zapp/console/src/components/common/SearchableNamedEntityList.tsx index 6a855080a..68b0d7dd9 100644 --- a/packages/zapp/console/src/components/common/SearchableNamedEntityList.tsx +++ b/packages/zapp/console/src/components/common/SearchableNamedEntityList.tsx @@ -1,4 +1,3 @@ -import { Typography } from '@material-ui/core'; import { makeStyles, Theme } from '@material-ui/core/styles'; import { listhoverColor, separatorColor } from 'components/Theme/constants'; import { NamedEntity } from 'models/Common/types'; diff --git a/packages/zapp/console/src/components/common/scopedContext.ts b/packages/zapp/console/src/components/common/scopedContext.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/zapp/console/tsconfig.json b/packages/zapp/console/tsconfig.json index 597473928..0e27291d2 100644 --- a/packages/zapp/console/tsconfig.json +++ b/packages/zapp/console/tsconfig.json @@ -1,54 +1,16 @@ { + "extends": "../../../tsconfig.base.json", "compilerOptions": { - "allowSyntheticDefaultImports": true, - "allowJs": true, - "baseUrl": "src", - "checkJs": false, - "downlevelIteration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "importHelpers": true, - "jsx": "react", - "lib": ["es6", "es2021", "dom", "dom.iterable"], - "module": "commonjs", - "moduleResolution": "node", - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "noImplicitAny": false, - "noUnusedLocals": false, - "noUnusedParameters": false, + "baseUrl": "./src", "outDir": "./dist", - "removeComments": false, - "resolveJsonModule": true, - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "target": "es6", - "types": ["node", "webpack-env", "jest", "@testing-library/jest-dom"], - "composite": true, - "paths": { - "@flyteconsole/*": ["../../plugins/*/src"] - } + // TODO: this items should be removed when violations are fixed: + "noUnusedLocals": false, + "noUnusedParameters": false, + "noImplicitAny": false, + "exactOptionalPropertyTypes": false, + "noImplicitOverride": false }, "references": [{ "path": "../../plugins/components" }], - // "extends": "../../../tsconfig.base.json", - // "compilerOptions": { - // "rootDir": "./src", - // "outDir": "./dist" - // }, - // "references": [{ "path": "../../plugins/components" }], - "include": ["src/**/*"], - "exclude": [ - "**/__mocks__", - "**/test", - "**/mocks", - // baseline - "**/node_modules", - "**/dist", - "**/lib", - "**/src/**/*.spec.*", - "**/src/**/*.test.*", - "**/src/**/*.stories.*" - ] + "include": ["src/**/*"] } diff --git a/packages/zapp/console/webpack.dev.config.ts b/packages/zapp/console/webpack.dev.config.ts index 0b8a9eee3..b9d6ae2ef 100644 --- a/packages/zapp/console/webpack.dev.config.ts +++ b/packages/zapp/console/webpack.dev.config.ts @@ -1,7 +1,8 @@ import * as webpack from 'webpack'; import * as HTMLWebpackPlugin from 'html-webpack-plugin'; import * as path from 'path'; -import { processEnv as env, LOCAL_DEV_HOST } from './env'; +import chalk from 'chalk'; +import { LOCAL_DEV_HOST, CERTIFICATE_PATH } from './env'; const { merge } = require('webpack-merge'); const fs = require('fs'); @@ -9,6 +10,22 @@ const common = require('./webpack.common.config'); const devtool = 'eval-cheap-module-source-map'; +// Check if certificate provided and if not - exit early +if ( + !fs.existsSync(`${CERTIFICATE_PATH}/server.key`) || + !fs.existsSync(`${CERTIFICATE_PATH}/server.crt`) +) { + console.log( + chalk.red(`ERROR: Can not locate server.key and server.crt in ${CERTIFICATE_PATH} location`), + ); + console.log( + chalk.red('Please re-genereate your site certificates by running'), + 'make generate_ssl', + chalk.red('than re-run the command'), + ); + process.exit(0); +} + /** * Client configuration * @@ -27,8 +44,8 @@ export const clientConfig: webpack.Configuration = merge(common.default.clientCo server: { type: 'https', options: { - key: fs.readFileSync('../../../script/server.key'), - cert: fs.readFileSync('../../../script/server.crt'), + key: fs.readFileSync(`${CERTIFICATE_PATH}/server.key`), + cert: fs.readFileSync(`${CERTIFICATE_PATH}/server.crt`), }, }, client: { diff --git a/script/generate_ssl.sh b/script/generate_ssl.sh index e216d32c5..3673c3362 100755 --- a/script/generate_ssl.sh +++ b/script/generate_ssl.sh @@ -2,10 +2,13 @@ script="$0" basename="$(dirname $script)" - -echo "Script name $script resides in $basename directory." +output="$basename/certificate" -openssl genrsa -des3 -out "$basename/rootCA.key" 2048 -openssl req -x509 -new -nodes -key "$basename/rootCA.key" -sha256 -days 1024 -out "$basename/rootCA.pem" -openssl req -new -sha256 -nodes -out "$basename/server.csr" -newkey rsa:2048 -keyout "$basename/server.key" -config <( cat "$basename/server.csr.cnf" ) -openssl x509 -req -in "$basename/server.csr" -CA "$basename/rootCA.pem" -CAkey "$basename/rootCA.key" -CAcreateserial -out "$basename/server.crt" -days 500 -sha256 -extfile "$basename/v3.ext" +echo "Script name $script resides in $basename directory. Output would be written to: $output" + +mkdir -p $output + +openssl genrsa -des3 -out "$output/rootCA.key" 2048 +openssl req -x509 -new -nodes -key "$output/rootCA.key" -sha256 -days 1024 -out "$output/rootCA.pem" +openssl req -new -sha256 -nodes -out "$output/server.csr" -newkey rsa:2048 -keyout "$output/server.key" -config <( cat "$basename/server.csr.cnf" ) +openssl x509 -req -in "$output/server.csr" -CA "$output/rootCA.pem" -CAkey "$output/rootCA.key" -CAcreateserial -out "$output/server.crt" -days 500 -sha256 -extfile "$basename/v3.ext" diff --git a/tsconfig.base.json b/tsconfig.base.json index 1eff79958..48e257019 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,64 +1,47 @@ { "compilerOptions": { - "allowSyntheticDefaultImports": true, - "allowJs": true, + "strict": true, "checkJs": false, - "downlevelIteration": true, + "allowJs": true, + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, + "resolveJsonModule": true, + "removeComments": false, "importHelpers": true, + "jsx": "react", "lib": ["es6", "es2021", "dom", "dom.iterable"], + // TODO: switch target to "esnext" when babel would be removed. + "target": "es6", "module": "commonjs", "moduleResolution": "node", - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "noImplicitAny": false, - "noUnusedLocals": false, - "noUnusedParameters": false, - "outDir": "./dist", - "removeComments": false, - "resolveJsonModule": true, - "skipLibCheck": true, - "strict": true, - "target": "es6", - "types": ["node", "webpack-env", "jest"], - - // "lib": ["dom", "dom.iterable", "es2018"], - // "jsx": "react", - // "target": "esnext", - // "module": "commonjs", - // "moduleResolution": "node", + "types": ["node", "webpack-env", "jest", "@testing-library/jest-dom"], - // "allowJs": false, - // "allowUnreachableCode": false, - // "esModuleInterop": true, - // "strict": true, - // "isolatedModules": true, - // "declaration": true, - // "noUnusedLocals": true, - // "noUnusedParameters": true, - // "noImplicitReturns": true, - // "noImplicitThis": true, - // "noImplicitAny": true, - // "importHelpers": true, - // "declarationMap": true, - // "useDefineForClassFields": true, - // "useUnknownInCatchVariables": false, - // "resolveJsonModule": true, - // "experimentalDecorators": true, - // "skipLibCheck": true, + "isolatedModules": true, + "declaration": true, + "declarationMap": true, + "downlevelIteration": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noImplicitAny": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "useDefineForClassFields": true, + "useUnknownInCatchVariables": false, - // // More strict - // "exactOptionalPropertyTypes": false, // true, - // "noUncheckedIndexedAccess": false, - // "noFallthroughCasesInSwitch": true, - // "noPropertyAccessFromIndexSignature": false, - // "noImplicitOverride": true, + // More strict rules + "exactOptionalPropertyTypes": true, + "noUncheckedIndexedAccess": false, + "noPropertyAccessFromIndexSignature": false, + "noImplicitOverride": true, + "noFallthroughCasesInSwitch": true, "sourceMap": true, "composite": true, "baseUrl": ".", + "outDir": "./dist", "paths": { "@flyteconsole/*": ["./packages/plugins/*/src", "./packages/zapp/*/src"] } @@ -69,6 +52,10 @@ "**/lib", "**/src/**/*.spec.*", "**/src/**/*.test.*", - "**/src/**/*.stories.*" + "**/src/**/*.stories.*", + // old code patterns + "**/__mocks__", + "**/test", + "**/mocks" ] }