aws-iam-language-server 0.0.11 → 0.0.12
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/package.json
CHANGED
|
@@ -1,7 +1,44 @@
|
|
|
1
|
+
import { partitions } from "../../lib/iam-policy/partitions.js";
|
|
1
2
|
import { ElementValidator } from "./base.js";
|
|
3
|
+
import { createDiagnostic } from "./utils.js";
|
|
4
|
+
const validPartitions = new Set(Object.keys(partitions));
|
|
5
|
+
const validRegions = new Set(Object.values(partitions).flatMap((p) => p.regions.map((r) => r.id)));
|
|
6
|
+
const accountIdPattern = /^\d{12}$/;
|
|
7
|
+
function validateArn(value) {
|
|
8
|
+
const text = value.text;
|
|
9
|
+
const diagnostics = [];
|
|
10
|
+
if (!text.startsWith('arn:'))
|
|
11
|
+
return [];
|
|
12
|
+
const segments = text.split(':');
|
|
13
|
+
if (segments.length > 1) {
|
|
14
|
+
const partition = segments[1];
|
|
15
|
+
if (partition === '') {
|
|
16
|
+
diagnostics.push(createDiagnostic('partition is required', value.range));
|
|
17
|
+
}
|
|
18
|
+
else if (partition !== '*' && !validPartitions.has(partition)) {
|
|
19
|
+
diagnostics.push(createDiagnostic(`partition must be one of: ${[...validPartitions].join(',')}`, value.range));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (segments.length > 3) {
|
|
23
|
+
const region = segments[3];
|
|
24
|
+
if (region !== '*' && region !== '' && !validRegions.has(region)) {
|
|
25
|
+
diagnostics.push(createDiagnostic('invalid region', value.range));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (segments.length > 4) {
|
|
29
|
+
const account = segments[4];
|
|
30
|
+
if (account !== '*' && account !== '' && !accountIdPattern.test(account)) {
|
|
31
|
+
diagnostics.push(createDiagnostic('expected account id to be 12 digits', value.range));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return diagnostics;
|
|
35
|
+
}
|
|
2
36
|
export class ResourceValidator extends ElementValidator {
|
|
3
37
|
validate(entry) {
|
|
4
|
-
|
|
38
|
+
let diagnostics = super.validate(entry);
|
|
39
|
+
for (const value of entry.values) {
|
|
40
|
+
diagnostics = diagnostics.concat(validateArn(value));
|
|
41
|
+
}
|
|
5
42
|
return diagnostics;
|
|
6
43
|
}
|
|
7
44
|
}
|