Skip to content

Commit

Permalink
[#174416949] Apply eslint to app.ts after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnedMarshal committed Jan 8, 2021
1 parent 66d1d63 commit 644b605
Showing 1 changed file with 82 additions and 75 deletions.
157 changes: 82 additions & 75 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,6 @@
* Main entry point for the Digital Citizenship proxy.
*/

import {
API_CLIENT,
appConfig,
BONUS_API_CLIENT,
BONUS_REQUEST_LIMIT_DATE,
CACHE_MAX_AGE_SECONDS,
ENABLE_NOTICE_EMAIL_CACHE,
ENV,
FF_BONUS_ENABLED,
getClientProfileRedirectionUrl,
IDP_METADATA_REFRESH_INTERVAL_SECONDS,
NOTIFICATION_DEFAULT_SUBJECT,
NOTIFICATION_DEFAULT_TITLE,
NOTIFICATIONS_QUEUE_NAME,
NOTIFICATIONS_STORAGE_CONNECTION_STRING,
PAGOPA_CLIENT,
samlConfig,
serviceProviderConfig,
SPID_LOG_QUEUE_NAME,
SPID_LOG_STORAGE_CONNECTION_STRING,
TEST_LOGIN_FISCAL_CODES,
TEST_LOGIN_PASSWORD,
tokenDurationSecs,
URL_TOKEN_STRATEGY,
USERS_LOGIN_QUEUE_NAME,
USERS_LOGIN_STORAGE_CONNECTION_STRING
} from "./config";

import * as apicache from "apicache";
import * as bodyParser from "body-parser";
import * as express from "express";
Expand All @@ -44,8 +16,16 @@ import {
NodeEnvironmentEnum
} from "italia-ts-commons/lib/environment";
import { CIDR } from "italia-ts-commons/lib/strings";
import { QueueClient } from "@azure/storage-queue";
import { withSpid } from "@pagopa/io-spid-commons";
import { getSpidStrategyOption } from "@pagopa/io-spid-commons/dist/utils/middleware";
import * as appInsights from "applicationinsights";
import { tryCatch2v } from "fp-ts/lib/Either";
import { isEmpty, StrMap } from "fp-ts/lib/StrMap";
import { fromLeft, taskEither, tryCatch } from "fp-ts/lib/TaskEither";
import { ServerInfo } from "../generated/public/ServerInfo";

import { VersionPerPlatform } from "../generated/public/VersionPerPlatform";
import AuthenticationController from "./controllers/authenticationController";
import MessagesController from "./controllers/messagesController";
import NotificationController from "./controllers/notificationController";
Expand All @@ -59,14 +39,33 @@ import UserMetadataController from "./controllers/userMetadataController";
import { log } from "./utils/logger";
import checkIP from "./utils/middleware/checkIP";

import { QueueClient } from "@azure/storage-queue";
import { withSpid } from "@pagopa/io-spid-commons";
import { getSpidStrategyOption } from "@pagopa/io-spid-commons/dist/utils/middleware";
import * as appInsights from "applicationinsights";
import { tryCatch2v } from "fp-ts/lib/Either";
import { isEmpty, StrMap } from "fp-ts/lib/StrMap";
import { fromLeft, taskEither, tryCatch } from "fp-ts/lib/TaskEither";
import { VersionPerPlatform } from "../generated/public/VersionPerPlatform";
import {
API_CLIENT,
appConfig,
BONUS_API_CLIENT,
BONUS_REQUEST_LIMIT_DATE,
CACHE_MAX_AGE_SECONDS,
ENABLE_NOTICE_EMAIL_CACHE,
ENV,
FF_BONUS_ENABLED,
getClientProfileRedirectionUrl,
IDP_METADATA_REFRESH_INTERVAL_SECONDS,
NOTIFICATION_DEFAULT_SUBJECT,
NOTIFICATION_DEFAULT_TITLE,
NOTIFICATIONS_QUEUE_NAME,
NOTIFICATIONS_STORAGE_CONNECTION_STRING,
PAGOPA_CLIENT,
samlConfig,
serviceProviderConfig,
SPID_LOG_QUEUE_NAME,
SPID_LOG_STORAGE_CONNECTION_STRING,
TEST_LOGIN_FISCAL_CODES,
TEST_LOGIN_PASSWORD,
tokenDurationSecs,
URL_TOKEN_STRATEGY,
USERS_LOGIN_QUEUE_NAME,
USERS_LOGIN_STORAGE_CONNECTION_STRING
} from "./config";
import BonusController from "./controllers/bonusController";
import SessionLockController from "./controllers/sessionLockController";
import { getUserForBPD, getUserForMyPortal } from "./controllers/ssoController";
Expand Down Expand Up @@ -104,6 +103,7 @@ import {
import { makeSpidLogCallback } from "./utils/spid";

const defaultModule = {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
newApp
};

Expand All @@ -120,22 +120,22 @@ const cachingMiddleware = apicache.options({
}).middleware;

export interface IAppFactoryParameters {
env: NodeEnvironment;
appInsightsClient?: appInsights.TelemetryClient;
allowNotifyIPSourceRange: readonly CIDR[];
allowPagoPAIPSourceRange: readonly CIDR[];
allowMyPortalIPSourceRange: readonly CIDR[];
allowBPDIPSourceRange: readonly CIDR[];
allowSessionHandleIPSourceRange: readonly CIDR[];
authenticationBasePath: string;
APIBasePath: string;
BonusAPIBasePath: string;
PagoPABasePath: string;
MyPortalBasePath: string;
BPDBasePath: string;
readonly env: NodeEnvironment;
readonly appInsightsClient?: appInsights.TelemetryClient;
readonly allowNotifyIPSourceRange: ReadonlyArray<CIDR>;
readonly allowPagoPAIPSourceRange: ReadonlyArray<CIDR>;
readonly allowMyPortalIPSourceRange: ReadonlyArray<CIDR>;
readonly allowBPDIPSourceRange: ReadonlyArray<CIDR>;
readonly allowSessionHandleIPSourceRange: ReadonlyArray<CIDR>;
readonly authenticationBasePath: string;
readonly APIBasePath: string;
readonly BonusAPIBasePath: string;
readonly PagoPABasePath: string;
readonly MyPortalBasePath: string;
readonly BPDBasePath: string;
}

// tslint:disable-next-line: no-big-function
// eslint-disable-next-line max-lines-per-function
export function newApp({
env,
allowNotifyIPSourceRange,
Expand Down Expand Up @@ -294,12 +294,11 @@ export function newApp({

// Create the Notification Service
const ERROR_OR_NOTIFICATION_SERVICE = tryCatch2v(
() => {
return new NotificationService(
() =>
new NotificationService(
NOTIFICATIONS_STORAGE_CONNECTION_STRING,
NOTIFICATIONS_QUEUE_NAME
);
},
),
err => {
throw new Error(`Error initializing Notification Service: [${err}]`);
}
Expand All @@ -309,12 +308,11 @@ export function newApp({

// Create the UsersLoginLogService
const ERROR_OR_USERS_LOGIN_LOG_SERVICE = tryCatch2v(
() => {
return new UsersLoginLogService(
() =>
new UsersLoginLogService(
USERS_LOGIN_STORAGE_CONNECTION_STRING,
USERS_LOGIN_QUEUE_NAME
);
},
),
err => {
throw new Error(`Error initializing UsersLoginLogService: [${err}]`);
}
Expand All @@ -332,8 +330,10 @@ export function newApp({
TEST_LOGIN_FISCAL_CODES
);

// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerPublicRoutes(app);

// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerAuthenticationRoutes(
app,
authenticationBasePath,
Expand All @@ -346,6 +346,7 @@ export function newApp({
const PAGOPA_PROXY_SERVICE = new PagoPAProxyService(PAGOPA_CLIENT);
// Register the user metadata storage service.
const USER_METADATA_STORAGE = new RedisUserMetadataStorage(REDIS_CLIENT);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerAPIRoutes(
app,
APIBasePath,
Expand All @@ -361,6 +362,7 @@ export function newApp({
TOKEN_SERVICE,
authMiddlewares.bearerSession
);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerSessionAPIRoutes(
app,
APIBasePath,
Expand All @@ -370,6 +372,7 @@ export function newApp({
USER_METADATA_STORAGE
);
if (FF_BONUS_ENABLED) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerBonusAPIRoutes(
app,
BonusAPIBasePath,
Expand All @@ -378,6 +381,7 @@ export function newApp({
BONUS_REQUEST_LIMIT_DATE
);
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerPagoPARoutes(
app,
PagoPABasePath,
Expand All @@ -387,19 +391,21 @@ export function newApp({
ENABLE_NOTICE_EMAIL_CACHE,
authMiddlewares.bearerWallet
);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerMyPortalRoutes(
app,
MyPortalBasePath,
allowMyPortalIPSourceRange,
authMiddlewares.bearerMyPortal
);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerBPDRoutes(
app,
BPDBasePath,
allowBPDIPSourceRange,
authMiddlewares.bearerBPD
);
return { app, acsController };
return { acsController, app };
},
err => new Error(`Error on app routes setup: [${err}]`)
)
Expand Down Expand Up @@ -480,14 +486,15 @@ export function newApp({
.run();
}

// eslint-disable-next-line max-params
function registerPagoPARoutes(
app: Express,
basePath: string,
allowPagoPAIPSourceRange: readonly CIDR[],
allowPagoPAIPSourceRange: ReadonlyArray<CIDR>,
profileService: ProfileService,
sessionStorage: RedisSessionStorage,
enableNoticeEmailCache: boolean,
// tslint:disable-next-line: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerWalletTokenAuth: any
): void {
const pagopaController: PagoPAController = new PagoPAController(
Expand All @@ -507,8 +514,8 @@ function registerPagoPARoutes(
function registerMyPortalRoutes(
app: Express,
basePath: string,
allowMyPortalIPSourceRange: readonly CIDR[],
// tslint:disable-next-line: no-any
allowMyPortalIPSourceRange: ReadonlyArray<CIDR>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerMyPortalTokenAuth: any
): void {
app.get(
Expand All @@ -522,8 +529,8 @@ function registerMyPortalRoutes(
function registerBPDRoutes(
app: Express,
basePath: string,
allowBPDIPSourceRange: readonly CIDR[],
// tslint:disable-next-line: no-any
allowBPDIPSourceRange: ReadonlyArray<CIDR>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerBPDTokenAuth: any
): void {
app.get(
Expand All @@ -534,12 +541,12 @@ function registerBPDRoutes(
);
}

// tslint:disable-next-line: parameters-max-number
// eslint-disable-next-line max-params, max-lines-per-function
function registerAPIRoutes(
app: Express,
basePath: string,
allowNotifyIPSourceRange: readonly CIDR[],
// tslint:disable-next-line: no-any
allowNotifyIPSourceRange: ReadonlyArray<CIDR>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
urlTokenAuth: any,
profileService: ProfileService,
messagesService: MessagesService,
Expand All @@ -549,7 +556,7 @@ function registerAPIRoutes(
userMetadataStorage: RedisUserMetadataStorage,
userDataProcessingService: UserDataProcessingService,
tokenService: TokenService,
// tslint:disable-next-line: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerSessionTokenAuth: any
): void {
const profileController: ProfileController = new ProfileController(
Expand Down Expand Up @@ -752,12 +759,12 @@ function registerAPIRoutes(
);
}

// tslint:disable-next-line: parameters-max-number
// eslint-disable-next-line max-params
function registerSessionAPIRoutes(
app: Express,
basePath: string,
allowSessionHandleIPSourceRange: readonly CIDR[],
// tslint:disable-next-line: no-any
allowSessionHandleIPSourceRange: ReadonlyArray<CIDR>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
urlTokenAuth: any,
sessionStorage: RedisSessionStorage,
userMetadataStorage: RedisUserMetadataStorage
Expand Down Expand Up @@ -792,7 +799,7 @@ function registerBonusAPIRoutes(
app: Express,
basePath: string,
bonusService: BonusService,
// tslint:disable-next-line: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerSessionTokenAuth: any,
requestLimitDate: Date
): void {
Expand Down Expand Up @@ -844,9 +851,9 @@ function registerAuthenticationRoutes(
app: Express,
authBasePath: string,
acsController: AuthenticationController,
// tslint:disable-next-line: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerSessionTokenAuth: any,
// tslint:disable-next-line: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
localAuth: any
): void {
TEST_LOGIN_PASSWORD.map(testLoginPassword => {
Expand Down

0 comments on commit 644b605

Please sign in to comment.