attlaz-client 1.18.2 → 1.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
1
  import { Endpoint } from './Endpoint.js';
2
+ import { CollectionResult } from '../Model/Result/CollectionResult.js';
3
+ import { CursorPagination } from '../Model/Pagination/CursorPagination.js';
2
4
  export type BlockedIp = {
3
5
  ip: string;
4
6
  from: Date;
@@ -15,13 +17,10 @@ export type IpRule = {
15
17
  action: string;
16
18
  description: string;
17
19
  };
18
- export type FirewallInfo = {
19
- blockedIps: BlockedIp[];
20
- flaggedIps: FlaggedIp[];
21
- ipRules: IpRule[];
22
- };
23
20
  export declare class FirewallEndpoint extends Endpoint {
24
- getInformation(): Promise<FirewallInfo | null>;
21
+ getBlockedIps(pagination: CursorPagination): Promise<CollectionResult<BlockedIp>>;
22
+ getFlaggedIps(pagination: CursorPagination): Promise<CollectionResult<FlaggedIp>>;
23
+ getIpRules(pagination: CursorPagination): Promise<CollectionResult<IpRule>>;
25
24
  createIpRule(ip: string, action: string, description?: string): Promise<boolean>;
26
25
  unblockIP(ip: string): Promise<boolean>;
27
26
  }
@@ -1,44 +1,54 @@
1
1
  import { Endpoint } from './Endpoint.js';
2
2
  import { Utils } from '../Utils.js';
3
+ import { QueryString } from '../Http/Data/QueryString.js';
3
4
  export class FirewallEndpoint extends Endpoint {
4
- async getInformation() {
5
- const cmd = '/system/firewall/';
6
- try {
7
- const parser = (raw) => {
8
- const info = {
9
- blockedIps: [],
10
- flaggedIps: [],
11
- ipRules: [],
12
- };
13
- for (const blockedIp of raw.blocked_ips) {
14
- blockedIp.from = Utils.parseRawDate(blockedIp.from);
15
- blockedIp.to = Utils.parseRawDate(blockedIp.to);
16
- info.blockedIps.push(blockedIp);
17
- }
18
- for (const flaggedIp of raw.flagged_ips) {
19
- flaggedIp.date = Utils.parseRawDate(flaggedIp.date);
20
- info.flaggedIps.push(flaggedIp);
21
- }
22
- for (const ipRule of raw.ip_rules) {
23
- info.ipRules.push(ipRule);
24
- }
25
- return info;
5
+ async getBlockedIps(pagination) {
6
+ const parser = (raw) => {
7
+ return {
8
+ ip: raw.ip,
9
+ from: Utils.parseRawDate(raw.from),
10
+ to: Utils.parseRawDate(raw.to),
11
+ reason: raw.reason,
26
12
  };
27
- const result = await this.requestObject(cmd, null, parser, 'GET');
28
- return result.getData();
29
- }
30
- catch (ex) {
31
- if (this.httpClient.isDebugEnabled()) {
32
- console.error('Failed to get firewall information', ex);
33
- }
34
- throw ex;
35
- }
13
+ };
14
+ const queryString = new QueryString('/system/firewall/blocked');
15
+ queryString.addPagination(pagination);
16
+ const result = await this.requestCollection(queryString, parser);
17
+ return result;
18
+ }
19
+ async getFlaggedIps(pagination) {
20
+ const parser = (raw) => {
21
+ return {
22
+ ip: raw.ip,
23
+ date: Utils.parseRawDate(raw.date),
24
+ reason: raw.reason,
25
+ };
26
+ };
27
+ const queryString = new QueryString('/system/firewall/flagged');
28
+ queryString.addPagination(pagination);
29
+ const result = await this.requestCollection(queryString, parser);
30
+ return result;
31
+ }
32
+ async getIpRules(pagination) {
33
+ const parser = (raw) => {
34
+ return {
35
+ ip: raw.ip,
36
+ action: raw.action,
37
+ description: raw.description,
38
+ };
39
+ };
40
+ const queryString = new QueryString('/system/firewall/rules');
41
+ queryString.addPagination(pagination);
42
+ const result = await this.requestCollection(queryString, parser);
43
+ return result;
36
44
  }
37
45
  async createIpRule(ip, action, description = '') {
38
46
  const cmd = '/system/firewall/ip_rules';
39
47
  try {
40
48
  const parser = (raw) => raw.success;
41
- const result = await this.requestObject(cmd, { ip, action, description }, parser, 'PUT');
49
+ const result = await this.requestObject(cmd, {
50
+ ip, action, description,
51
+ }, parser, 'PUT');
42
52
  const re = result.getData();
43
53
  if (re === null) {
44
54
  console.log('createIPRule wrong result', { result, parsed: re });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.18.2",
3
+ "version": "1.18.3",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",