From a92ddacb38a4a17e117ca9ed41680a03580fb81d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:34:29 +0200 Subject: Introduce logs command --- shared/extra-utils/logs/index.ts | 1 + shared/extra-utils/logs/logs-command.ts | 41 +++++++++++++++++++++++++++++++++ shared/extra-utils/logs/logs.ts | 32 ------------------------- 3 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 shared/extra-utils/logs/index.ts create mode 100644 shared/extra-utils/logs/logs-command.ts delete mode 100644 shared/extra-utils/logs/logs.ts (limited to 'shared/extra-utils/logs') diff --git a/shared/extra-utils/logs/index.ts b/shared/extra-utils/logs/index.ts new file mode 100644 index 000000000..69452d7f0 --- /dev/null +++ b/shared/extra-utils/logs/index.ts @@ -0,0 +1 @@ +export * from './logs-command' diff --git a/shared/extra-utils/logs/logs-command.ts b/shared/extra-utils/logs/logs-command.ts new file mode 100644 index 000000000..f7594734d --- /dev/null +++ b/shared/extra-utils/logs/logs-command.ts @@ -0,0 +1,41 @@ +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { LogLevel } from '../../models/server/log-level.type' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class LogsCommand extends AbstractCommand { + + getLogs (options: OverrideCommandOptions & { + startDate: Date + endDate?: Date + level?: LogLevel + }) { + const { startDate, endDate, level } = options + const path = '/api/v1/server/logs' + + return this.getRequestBody({ + ...options, + + path, + query: { startDate, endDate, level }, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getAuditLogs (options: OverrideCommandOptions & { + startDate: Date + endDate?: Date + }) { + const { startDate, endDate } = options + + const path = '/api/v1/server/audit-logs' + + return this.getRequestBody({ + ...options, + + path, + query: { startDate, endDate }, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + +} diff --git a/shared/extra-utils/logs/logs.ts b/shared/extra-utils/logs/logs.ts deleted file mode 100644 index 8d741276c..000000000 --- a/shared/extra-utils/logs/logs.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { makeGetRequest } from '../requests/requests' -import { LogLevel } from '../../models/server/log-level.type' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function getLogs (url: string, accessToken: string, startDate: Date, endDate?: Date, level?: LogLevel) { - const path = '/api/v1/server/logs' - - return makeGetRequest({ - url, - path, - token: accessToken, - query: { startDate, endDate, level }, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getAuditLogs (url: string, accessToken: string, startDate: Date, endDate?: Date) { - const path = '/api/v1/server/audit-logs' - - return makeGetRequest({ - url, - path, - token: accessToken, - query: { startDate, endDate }, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -export { - getLogs, - getAuditLogs -} -- cgit v1.2.3 From a1637fa1e25b60a88f7cfe50aac8953f50d55761 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:55:16 +0200 Subject: Specify if we want to fallback to the server token --- shared/extra-utils/logs/logs-command.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'shared/extra-utils/logs') diff --git a/shared/extra-utils/logs/logs-command.ts b/shared/extra-utils/logs/logs-command.ts index f7594734d..f34c58c47 100644 --- a/shared/extra-utils/logs/logs-command.ts +++ b/shared/extra-utils/logs/logs-command.ts @@ -17,6 +17,7 @@ export class LogsCommand extends AbstractCommand { path, query: { startDate, endDate, level }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -34,6 +35,7 @@ export class LogsCommand extends AbstractCommand { path, query: { startDate, endDate }, + implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 }) } -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- shared/extra-utils/logs/logs-command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared/extra-utils/logs') diff --git a/shared/extra-utils/logs/logs-command.ts b/shared/extra-utils/logs/logs-command.ts index f34c58c47..5912e814f 100644 --- a/shared/extra-utils/logs/logs-command.ts +++ b/shared/extra-utils/logs/logs-command.ts @@ -1,4 +1,4 @@ -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { LogLevel } from '../../models/server/log-level.type' import { AbstractCommand, OverrideCommandOptions } from '../shared' -- cgit v1.2.3