diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-06 10:34:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:16 +0200 |
commit | a92ddacb38a4a17e117ca9ed41680a03580fb81d (patch) | |
tree | 7b7fc6ef31e86870cee20b915e05c49af1910055 /shared/extra-utils/logs | |
parent | f59545d97a80bf06025bf6343a80d834c7eb237f (diff) | |
download | PeerTube-a92ddacb38a4a17e117ca9ed41680a03580fb81d.tar.gz PeerTube-a92ddacb38a4a17e117ca9ed41680a03580fb81d.tar.zst PeerTube-a92ddacb38a4a17e117ca9ed41680a03580fb81d.zip |
Introduce logs command
Diffstat (limited to 'shared/extra-utils/logs')
-rw-r--r-- | shared/extra-utils/logs/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/logs/logs-command.ts | 41 | ||||
-rw-r--r-- | shared/extra-utils/logs/logs.ts | 32 |
3 files changed, 42 insertions, 32 deletions
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 @@ | |||
1 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
2 | import { LogLevel } from '../../models/server/log-level.type' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class LogsCommand extends AbstractCommand { | ||
6 | |||
7 | getLogs (options: OverrideCommandOptions & { | ||
8 | startDate: Date | ||
9 | endDate?: Date | ||
10 | level?: LogLevel | ||
11 | }) { | ||
12 | const { startDate, endDate, level } = options | ||
13 | const path = '/api/v1/server/logs' | ||
14 | |||
15 | return this.getRequestBody({ | ||
16 | ...options, | ||
17 | |||
18 | path, | ||
19 | query: { startDate, endDate, level }, | ||
20 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | getAuditLogs (options: OverrideCommandOptions & { | ||
25 | startDate: Date | ||
26 | endDate?: Date | ||
27 | }) { | ||
28 | const { startDate, endDate } = options | ||
29 | |||
30 | const path = '/api/v1/server/audit-logs' | ||
31 | |||
32 | return this.getRequestBody({ | ||
33 | ...options, | ||
34 | |||
35 | path, | ||
36 | query: { startDate, endDate }, | ||
37 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | } | ||
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 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | import { LogLevel } from '../../models/server/log-level.type' | ||
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | |||
5 | function getLogs (url: string, accessToken: string, startDate: Date, endDate?: Date, level?: LogLevel) { | ||
6 | const path = '/api/v1/server/logs' | ||
7 | |||
8 | return makeGetRequest({ | ||
9 | url, | ||
10 | path, | ||
11 | token: accessToken, | ||
12 | query: { startDate, endDate, level }, | ||
13 | statusCodeExpected: HttpStatusCode.OK_200 | ||
14 | }) | ||
15 | } | ||
16 | |||
17 | function getAuditLogs (url: string, accessToken: string, startDate: Date, endDate?: Date) { | ||
18 | const path = '/api/v1/server/audit-logs' | ||
19 | |||
20 | return makeGetRequest({ | ||
21 | url, | ||
22 | path, | ||
23 | token: accessToken, | ||
24 | query: { startDate, endDate }, | ||
25 | statusCodeExpected: HttpStatusCode.OK_200 | ||
26 | }) | ||
27 | } | ||
28 | |||
29 | export { | ||
30 | getLogs, | ||
31 | getAuditLogs | ||
32 | } | ||