@digitraffic/common 2025.5.5-1 → 2025.6.16-1
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.
- package/README.md +4 -0
- package/dist/__test__/infra/acl-builder.test.js +7 -2
- package/dist/aws/infra/acl-builder.d.ts +19 -12
- package/dist/aws/infra/acl-builder.js +34 -2
- package/dist/types/openapi-schema.d.ts +128 -128
- package/dist/utils/logging.d.ts +1 -2
- package/dist/utils/logging.js +1 -2
- package/package.json +34 -34
package/README.md
CHANGED
@@ -21,8 +21,13 @@ describe("acl-builder tests", () => {
|
|
21
21
|
]).build();
|
22
22
|
expect(acl.rules).toHaveLength(2);
|
23
23
|
});
|
24
|
-
test("ip
|
25
|
-
const acl = createBuilder().
|
24
|
+
test("ip blacklist", () => {
|
25
|
+
const acl = createBuilder().withIpBlacklistRule(["1.2.3.4", "1.2.6.6"])
|
26
|
+
.build();
|
27
|
+
expect(acl.rules).toHaveLength(1);
|
28
|
+
});
|
29
|
+
test("ip whitelist", () => {
|
30
|
+
const acl = createBuilder().withIpWhitelistRule(["1.2.3.4", "1.2.6.6"])
|
26
31
|
.build();
|
27
32
|
expect(acl.rules).toHaveLength(1);
|
28
33
|
});
|
@@ -12,7 +12,7 @@ export type CfnWebAclRuleProperty = {
|
|
12
12
|
*
|
13
13
|
* Currently supports:
|
14
14
|
* * Some AWS managed WAF rules
|
15
|
-
* * IP blacklisting
|
15
|
+
* * IP blacklisting/whitelisting
|
16
16
|
*/
|
17
17
|
export declare class AclBuilder {
|
18
18
|
readonly _construct: Construct;
|
@@ -23,18 +23,25 @@ export declare class AclBuilder {
|
|
23
23
|
_customResponseBodies: Record<string, CfnWebACL.CustomResponseBodyProperty>;
|
24
24
|
constructor(construct: Construct, name?: string);
|
25
25
|
isRuleDefined(rules: AWSManagedWafRule[] | "all", rule: AWSManagedWafRule): boolean;
|
26
|
-
withAWSManagedRules(rules?: AWSManagedWafRule[] | "all", excludedRules?: ExcludedAWSRules):
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
withAWSManagedRules(rules?: AWSManagedWafRule[] | "all", excludedRules?: ExcludedAWSRules): this;
|
27
|
+
/**
|
28
|
+
* Block access from given addresses
|
29
|
+
*/
|
30
|
+
withIpBlacklistRule(addresses: string[]): this;
|
31
|
+
/**
|
32
|
+
* Allow access only from the given addresses
|
33
|
+
*/
|
34
|
+
withIpWhitelistRule(addresses: string[]): this;
|
35
|
+
withThrottleRule(name: string, limit: number, isHeaderRequired: boolean, isBasedOnIpAndUriPath: boolean, customResponseBodyKey?: string): this;
|
36
|
+
withCustomResponseBody(key: string, customResponseBody: CfnWebACL.CustomResponseBodyProperty): this;
|
37
|
+
withThrottleDigitrafficUserIp(limit: number | undefined): this;
|
38
|
+
withThrottleDigitrafficUserIpAndUriPath(limit: number | undefined): this;
|
32
39
|
withThrottleAnonymousUserIp(limit: number | undefined): AclBuilder;
|
33
|
-
withThrottleAnonymousUserIpAndUriPath(limit: number | undefined):
|
34
|
-
withCountDigitrafficUserIp(limit: number | undefined):
|
35
|
-
withCountDigitrafficUserIpAndUriPath(limit: number | undefined):
|
36
|
-
withCountAnonymousUserIp(limit: number | undefined):
|
37
|
-
withCountAnonymousUserIpAndUriPath(limit: number | undefined):
|
40
|
+
withThrottleAnonymousUserIpAndUriPath(limit: number | undefined): this;
|
41
|
+
withCountDigitrafficUserIp(limit: number | undefined): this;
|
42
|
+
withCountDigitrafficUserIpAndUriPath(limit: number | undefined): this;
|
43
|
+
withCountAnonymousUserIp(limit: number | undefined): this;
|
44
|
+
withCountAnonymousUserIpAndUriPath(limit: number | undefined): this;
|
38
45
|
_isCustomResponseBodyKeySet(key: string): boolean;
|
39
46
|
_addThrottleResponseBody(customResponseBodyKey: string, limit: number): void;
|
40
47
|
build(): CfnWebACL;
|
@@ -6,7 +6,7 @@ import { concat, range, zipWith } from "lodash-es";
|
|
6
6
|
*
|
7
7
|
* Currently supports:
|
8
8
|
* * Some AWS managed WAF rules
|
9
|
-
* * IP blacklisting
|
9
|
+
* * IP blacklisting/whitelisting
|
10
10
|
*/
|
11
11
|
export class AclBuilder {
|
12
12
|
_construct;
|
@@ -37,7 +37,10 @@ export class AclBuilder {
|
|
37
37
|
}
|
38
38
|
return this;
|
39
39
|
}
|
40
|
-
|
40
|
+
/**
|
41
|
+
* Block access from given addresses
|
42
|
+
*/
|
43
|
+
withIpBlacklistRule(addresses) {
|
41
44
|
const blocklistIpSet = new CfnIPSet(this._construct, "BlocklistIpSet", {
|
42
45
|
ipAddressVersion: "IPV4",
|
43
46
|
scope: this._scope,
|
@@ -59,6 +62,35 @@ export class AclBuilder {
|
|
59
62
|
});
|
60
63
|
return this;
|
61
64
|
}
|
65
|
+
/**
|
66
|
+
* Allow access only from the given addresses
|
67
|
+
*/
|
68
|
+
withIpWhitelistRule(addresses) {
|
69
|
+
const blocklistIpSet = new CfnIPSet(this._construct, "AllowlistIpSet", {
|
70
|
+
ipAddressVersion: "IPV4",
|
71
|
+
scope: this._scope,
|
72
|
+
addresses,
|
73
|
+
});
|
74
|
+
this._blockRules.push({
|
75
|
+
name: "IpAllowlist",
|
76
|
+
action: { block: {} },
|
77
|
+
statement: {
|
78
|
+
notStatement: {
|
79
|
+
statement: {
|
80
|
+
ipSetReferenceStatement: {
|
81
|
+
arn: blocklistIpSet.attrArn,
|
82
|
+
},
|
83
|
+
},
|
84
|
+
},
|
85
|
+
},
|
86
|
+
visibilityConfig: {
|
87
|
+
sampledRequestsEnabled: false,
|
88
|
+
cloudWatchMetricsEnabled: true,
|
89
|
+
metricName: "IpAllowlist",
|
90
|
+
},
|
91
|
+
});
|
92
|
+
return this;
|
93
|
+
}
|
62
94
|
withThrottleRule(name, limit, isHeaderRequired, isBasedOnIpAndUriPath, customResponseBodyKey) {
|
63
95
|
const isBlockRule = !!customResponseBodyKey;
|
64
96
|
const rules = isBlockRule ? this._blockRules : this._countRules;
|