-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1be064d
commit 6970687
Showing
5 changed files
with
81 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Request, Response } from "express"; | ||
import { GetEndpointsService } from "../../services/get-endpoints"; | ||
import { GetEndpointParams } from "../../types"; | ||
|
||
export const getEndpointsHandler = async (req: Request, res: Response) => { | ||
const getEndpointParams: GetEndpointParams = req.query; | ||
try { | ||
const endpoints = await GetEndpointsService.getEndpoints(getEndpointParams); | ||
res.send(200).send(endpoints) | ||
} catch { | ||
res.sendStatus(500) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import { Request, Response } from "express"; | ||
import { LogRequestService } from "../../services/log-request"; | ||
import { TraceParams } from "types"; | ||
import { TraceParams } from "../../types"; | ||
|
||
export const logRequestSingleHandler = async (req: Request, res: Response) => { | ||
const traceParams: TraceParams = req.body; | ||
await LogRequestService.logRequest(traceParams); | ||
res.sendStatus(200); | ||
try { | ||
await LogRequestService.logRequest(traceParams); | ||
res.sendStatus(200) | ||
} catch { | ||
res.sendStatus(500) | ||
} | ||
} | ||
|
||
export const logRequestBatchHandler = async (req: Request, res: Response) => { | ||
const traceParamsBatch: TraceParams[] = req.body; | ||
await LogRequestService.logRequestBatch(traceParamsBatch); | ||
res.sendStatus(200); | ||
try { | ||
await LogRequestService.logRequestBatch(traceParamsBatch); | ||
res.sendStatus(200); | ||
} catch { | ||
res.sendStatus(500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { FindManyOptions, FindOptionsWhere } from "typeorm"; | ||
import { GetEndpointParams } from "../../types"; | ||
import { AppDataSource } from "../../data-source" | ||
import { ApiEndpoint } from "../../../models"; | ||
|
||
export class GetEndpointsService { | ||
static async getEndpoints(getEndpointParams: GetEndpointParams): Promise<ApiEndpoint[]> { | ||
try { | ||
const apiEndpointRepository = AppDataSource.getRepository(ApiEndpoint); | ||
let whereConditions: FindOptionsWhere<ApiEndpoint> = {} | ||
let paginationParams: FindManyOptions<ApiEndpoint> = {} | ||
if (getEndpointParams?.environment) { | ||
whereConditions = { | ||
...whereConditions, | ||
environment: getEndpointParams.environment | ||
} | ||
} | ||
if (getEndpointParams?.host) { | ||
whereConditions = { | ||
...whereConditions, | ||
host: getEndpointParams.host | ||
} | ||
} | ||
if (getEndpointParams?.offset) { | ||
paginationParams = { | ||
...paginationParams, | ||
skip: getEndpointParams.offset | ||
} | ||
} | ||
if (getEndpointParams?.limit) { | ||
paginationParams = { | ||
...paginationParams, | ||
take: getEndpointParams.limit | ||
} | ||
} | ||
|
||
const endpoints = await apiEndpointRepository.find({ where: whereConditions, ...paginationParams }) | ||
|
||
// TODO: Calculate risk score for endpoints and if risk score param present, only return those that meet | ||
|
||
return endpoints | ||
} catch (err) { | ||
console.error(`Error in Get Endpoints service: ${err}`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters