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

RD-1291 Introduced TS to backend #1575

Merged
merged 34 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d447df2
Introduced TS to backend
Sep 1, 2021
00dea5f
Merge branch 'master' into RD-1291-backend-ts
kubama Sep 1, 2021
32264d8
Removed webpack config dependency on backend/consts.ts
Sep 1, 2021
7f17a66
Merge branch 'RD-1291-backend-ts' of github.com:cloudify-cosmo/cloudi…
Sep 1, 2021
955d4f5
Fixed eslint error
Sep 1, 2021
724e8a0
Corrected route implementation
Sep 1, 2021
8205b8e
Updated reference commit for coverage check
Sep 1, 2021
c8db33a
Minor update to ensure non-empty change set for coverage check
Sep 1, 2021
1d64531
Added lodash typings
Sep 1, 2021
b81a37f
Fixed devServer
Sep 1, 2021
08351fd
Extended backend startup timeout
Sep 1, 2021
244cf05
Fixed logger widget backend helper
Sep 2, 2021
ed1713f
Merge branch 'master' into RD-1291-backend-ts
kubama Sep 2, 2021
9267de2
Added test to satisfy coverage check
Sep 2, 2021
3b564ee
Merge branch 'RD-1291-backend-ts' of github.com:cloudify-cosmo/cloudi…
Sep 2, 2021
c6116e4
Merge branch 'master' into RD-1291-backend-ts
kubama Sep 2, 2021
df0e842
Corrected accidental change
Sep 2, 2021
78987c1
Merge branch 'RD-1291-backend-ts' of github.com:cloudify-cosmo/cloudi…
Sep 2, 2021
02e338d
Added -T flag to ts-node invocations
Sep 2, 2021
64d8ffc
Migrated devServer to TS
Sep 3, 2021
ecb665d
Changed devServer extension
Sep 3, 2021
2c8f690
Merge branch 'master' into RD-1291-backend-ts
kubama Sep 3, 2021
8194f60
Fixed devTrace npm script
Sep 3, 2021
e7377cb
Merge branch 'RD-1291-backend-ts' of github.com:cloudify-cosmo/cloudi…
Sep 3, 2021
bbb0b1f
Fixed typo in test name
kubama Sep 3, 2021
cdffc1f
Merge branch 'master' into RD-1291-backend-ts
kubama Sep 3, 2021
44ae37c
Fixed SAML config validation, added test
Sep 3, 2021
05a08d4
Merge branch 'RD-1291-backend-ts' of github.com:cloudify-cosmo/cloudi…
Sep 3, 2021
6f50a30
Aligned project references configuration
Sep 6, 2021
8a4158f
Merge branch 'master' into RD-1291-backend-ts
kubama Sep 6, 2021
5b5a2c8
Added separate check-types scripts for frontend and backend
kubama Sep 6, 2021
6b67ed4
Reused more consts
Sep 6, 2021
aa1dacd
Merge branch 'RD-1291-backend-ts' of github.com:cloudify-cosmo/cloudi…
Sep 6, 2021
6b84796
Merge branch 'master' into RD-1291-backend-ts
kubama Sep 7, 2021
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"overrides": [
{
"files": ["./*.js", "scripts/*.js"],
"files": ["./*.{js,ts}", "scripts/*.js"],
"rules": {
"import/no-extraneous-dependencies": [
"error",
Expand Down
15 changes: 12 additions & 3 deletions backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
qooban marked this conversation as resolved.
Show resolved Hide resolved
"extends": [
"../node_modules/cloudify-ui-common/configs/eslint-common-node.json"
"plugin:node/recommended-module",
"../.eslintrc.temp-overrides.json"
],
"rules": {
"prefer-promise-reject-errors": "off"
}
"prefer-promise-reject-errors": "off",
"node/no-missing-require": ["error", {
"tryExtensions": [".js", ".ts", ".json"]
}],
"node/no-missing-import": ["error", {"tryExtensions": [".js", ".json", ".ts"]}]
},
"overrides": [{
"files": "**/*.js",
"extends": ["../node_modules/cloudify-ui-common/configs/eslint-common-node.json"]
}]
}
13 changes: 13 additions & 0 deletions backend/__mocks__/passport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { RequestHandler } from 'express';
import { noop } from 'lodash';

const middlewareMock: RequestHandler = (req, _res, next) => {
req.user = { username: 'testuser' };
next();
};

export default {
authenticate: () => middlewareMock,
initialize: () => middlewareMock,
use: noop
};
85 changes: 43 additions & 42 deletions backend/app.js → backend/app.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
const fs = require('fs');
const path = require('path');
const expressStaticGzip = require('express-static-gzip');
const express = require('express');
const passport = require('passport');
const cookieParser = require('cookie-parser');
const morgan = require('morgan');

const config = require('./config');
const Consts = require('./consts');
const LoggerHandler = require('./handler/LoggerHandler');
const ServerSettings = require('./serverSettings');
const { getResourcePath } = require('./utils');

const getCookieStrategy = require('./auth/CookieStrategy');
const getTokenStrategy = require('./auth/TokenStrategy');
const getSamlStrategy = require('./auth/SamlStrategy');
const samlSetup = require('./samlSetup');
const Auth = require('./routes/Auth');

const Applications = require('./routes/Applications');
const BlueprintAdditions = require('./routes/BlueprintAdditions');
const BlueprintUserData = require('./routes/BlueprintUserData');
const ClientConfig = require('./routes/ClientConfig');
const External = require('./routes/External');
const File = require('./routes/File');
const GitHub = require('./routes/GitHub');
const Maps = require('./routes/Maps');
const Plugins = require('./routes/Plugins');
const ServerProxy = require('./routes/ServerProxy');
const SourceBrowser = require('./routes/SourceBrowser');
const Style = require('./routes/Style');
const Templates = require('./routes/Templates');
const UserApp = require('./routes/UserApp');
const WidgetBackend = require('./routes/WidgetBackend');
const Widgets = require('./routes/Widgets');
const Filters = require('./routes/Filters');
// @ts-nocheck File not migrated fully to TS
import fs from 'fs';
import path from 'path';
import expressStaticGzip from 'express-static-gzip';
import express from 'express';
import passport from 'passport';
import cookieParser from 'cookie-parser';
import morgan from 'morgan';

import { getConfig, getClientConfig } from './config';
import { CONTEXT_PATH } from './consts';
import LoggerHandler from './handler/LoggerHandler';
import { getMode } from './serverSettings';
import { getResourcePath } from './utils';

import getCookieStrategy from './auth/CookieStrategy';
import getTokenStrategy from './auth/TokenStrategy';
import getSamlStrategy from './auth/SamlStrategy';
import validateSamlConfig from './samlSetup';
import Auth from './routes/Auth';

import Applications from './routes/Applications';
import BlueprintAdditions from './routes/BlueprintAdditions';
import BlueprintUserData from './routes/BlueprintUserData';
import ClientConfig from './routes/ClientConfig';
import External from './routes/External';
import File from './routes/File';
import GitHub from './routes/GitHub';
import Maps from './routes/Maps';
import Plugins from './routes/Plugins';
import ServerProxy from './routes/ServerProxy';
import SourceBrowser from './routes/SourceBrowser';
import Style from './routes/Style';
import Templates from './routes/Templates';
import UserApp from './routes/UserApp';
import WidgetBackend from './routes/WidgetBackend';
import Widgets from './routes/Widgets';
import Filters from './routes/Filters';

const logger = LoggerHandler.getLogger('App');
const contextPath = Consts.CONTEXT_PATH;
const contextPath = CONTEXT_PATH;
const oldContextPath = '/stage';
const app = express();

Expand Down Expand Up @@ -66,9 +67,9 @@ app.use(contextPath, (req, res, next) => {
next();
});

const samlConfig = config.get().app.saml;
const samlConfig = getConfig().app.saml;
if (samlConfig.enabled) {
samlSetup.validate(samlConfig);
validateSamlConfig(samlConfig);
passport.use(getSamlStrategy());
}

Expand Down Expand Up @@ -116,7 +117,7 @@ app.use(`${contextPath}/github`, GitHub);
app.use(`${contextPath}/external`, External);
app.use(`${contextPath}/file`, File);
app.use(`${contextPath}/config`, (req, res) => {
res.send(config.getForClient(ServerSettings.settings.mode));
res.send(getClientConfig(getMode()));
});
app.use(`${contextPath}/wb`, WidgetBackend);
app.use(`${contextPath}/plugins`, Plugins);
Expand Down Expand Up @@ -155,4 +156,4 @@ app.use((err, req, res, next) => {
res.status(err.status || 404).send({ message: message || err });
});

module.exports = app;
export default app;
15 changes: 0 additions & 15 deletions backend/auth/CookieStrategy.js

This file was deleted.

12 changes: 12 additions & 0 deletions backend/auth/CookieStrategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-nocheck File not migrated fully to TS
import { Strategy } from 'passport-cookie';
import { getUser } from '../handler/AuthHandler';
import { TOKEN_COOKIE_NAME } from '../consts';

export default () => {
return new Strategy({ cookieName: TOKEN_COOKIE_NAME }, (token, done) =>
getUser(token)
.then(user => done(null, user))
.catch(err => done(null, false, err + token))
);
};
25 changes: 0 additions & 25 deletions backend/auth/SamlStrategy.js

This file was deleted.

23 changes: 23 additions & 0 deletions backend/auth/SamlStrategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @ts-nocheck File not migrated fully to TS

import { Strategy } from 'passport-saml';
import fs from 'fs';
import { getConfig } from '../config';

export default () => {
let cert;
try {
cert = fs.readFileSync(getConfig().app.saml.certPath, 'utf-8');
} catch (e) {
throw new Error('Could not read SAML certificate [saml.certPath]', e);
}

return new Strategy(
{
path: '/auth/saml/callback',
entryPoint: getConfig().app.saml.ssoUrl,
cert
},
(user, done) => done(null, user)
);
};
19 changes: 8 additions & 11 deletions backend/auth/TokenStrategy.js → backend/auth/TokenStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/**
* Created by edenp on 7/30/17.
*/
// @ts-nocheck File not migrated fully to TS
import { Strategy } from 'passport-unique-token';
import { getUser } from '../handler/AuthHandler';
import { getLogger } from '../handler/LoggerHandler';

const UniqueTokenStrategy = require('passport-unique-token').Strategy;
const AuthHandler = require('../handler/AuthHandler');
const LoggerHandler = require('../handler/LoggerHandler');
const logger = getLogger('Passport');

const logger = LoggerHandler.getLogger('Passport');

module.exports = () => {
return new UniqueTokenStrategy(
export default () => {
return new Strategy(
{
tokenHeader: 'authentication-token'
},
(token, done) => {
AuthHandler.getUser(token)
getUser(token)
.then(user => {
return done(null, user);
})
Expand Down
3 changes: 3 additions & 0 deletions backend/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript']
qooban marked this conversation as resolved.
Show resolved Hide resolved
};
73 changes: 0 additions & 73 deletions backend/config.js

This file was deleted.

Loading