@actsecurity/iam-utils 0.1.82
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/LICENSE.txt +661 -0
- package/README.md +5 -0
- package/dist/cjs/actions.d.ts +9 -0
- package/dist/cjs/actions.d.ts.map +1 -0
- package/dist/cjs/actions.js +65 -0
- package/dist/cjs/actions.js.map +1 -0
- package/dist/cjs/arn.d.ts +48 -0
- package/dist/cjs/arn.d.ts.map +1 -0
- package/dist/cjs/arn.js +67 -0
- package/dist/cjs/arn.js.map +1 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/principals.d.ts +58 -0
- package/dist/cjs/principals.d.ts.map +1 -0
- package/dist/cjs/principals.js +93 -0
- package/dist/cjs/principals.js.map +1 -0
- package/dist/cjs/resourceInfoContextKeys.d.ts +19 -0
- package/dist/cjs/resourceInfoContextKeys.d.ts.map +1 -0
- package/dist/cjs/resourceInfoContextKeys.js +54 -0
- package/dist/cjs/resourceInfoContextKeys.js.map +1 -0
- package/dist/cjs/resourcePatterns.d.ts +9 -0
- package/dist/cjs/resourcePatterns.d.ts.map +1 -0
- package/dist/cjs/resourcePatterns.js +19 -0
- package/dist/cjs/resourcePatterns.js.map +1 -0
- package/dist/cjs/resourceTypes.d.ts +30 -0
- package/dist/cjs/resourceTypes.d.ts.map +1 -0
- package/dist/cjs/resourceTypes.js +267 -0
- package/dist/cjs/resourceTypes.js.map +1 -0
- package/dist/cjs/resources.d.ts +8 -0
- package/dist/cjs/resources.d.ts.map +1 -0
- package/dist/cjs/resources.js +14 -0
- package/dist/cjs/resources.js.map +1 -0
- package/dist/cjs/s3.d.ts +15 -0
- package/dist/cjs/s3.d.ts.map +1 -0
- package/dist/cjs/s3.js +35 -0
- package/dist/cjs/s3.js.map +1 -0
- package/dist/esm/actions.d.ts +9 -0
- package/dist/esm/actions.d.ts.map +1 -0
- package/dist/esm/actions.js +62 -0
- package/dist/esm/actions.js.map +1 -0
- package/dist/esm/arn.d.ts +48 -0
- package/dist/esm/arn.d.ts.map +1 -0
- package/dist/esm/arn.js +63 -0
- package/dist/esm/arn.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/principals.d.ts +58 -0
- package/dist/esm/principals.d.ts.map +1 -0
- package/dist/esm/principals.js +83 -0
- package/dist/esm/principals.js.map +1 -0
- package/dist/esm/resourceInfoContextKeys.d.ts +19 -0
- package/dist/esm/resourceInfoContextKeys.d.ts.map +1 -0
- package/dist/esm/resourceInfoContextKeys.js +50 -0
- package/dist/esm/resourceInfoContextKeys.js.map +1 -0
- package/dist/esm/resourcePatterns.d.ts +9 -0
- package/dist/esm/resourcePatterns.d.ts.map +1 -0
- package/dist/esm/resourcePatterns.js +16 -0
- package/dist/esm/resourcePatterns.js.map +1 -0
- package/dist/esm/resourceTypes.d.ts +30 -0
- package/dist/esm/resourceTypes.d.ts.map +1 -0
- package/dist/esm/resourceTypes.js +263 -0
- package/dist/esm/resourceTypes.js.map +1 -0
- package/dist/esm/resources.d.ts +8 -0
- package/dist/esm/resources.d.ts.map +1 -0
- package/dist/esm/resources.js +11 -0
- package/dist/esm/resources.js.map +1 -0
- package/dist/esm/s3.d.ts +15 -0
- package/dist/esm/s3.d.ts.map +1 -0
- package/dist/esm/s3.js +31 -0
- package/dist/esm/s3.js.map +1 -0
- package/package.json +115 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resourceStringMatchesResourceTypePattern = resourceStringMatchesResourceTypePattern;
|
|
4
|
+
exports.mostSpecificMatchingResourceTypePatterns = mostSpecificMatchingResourceTypePatterns;
|
|
5
|
+
const arn_js_1 = require("./arn.js");
|
|
6
|
+
/**
|
|
7
|
+
* Checks whether a concrete resource ARN (possibly with wildcards) matches
|
|
8
|
+
* a resource-type ARN pattern from the Service Authorization Reference.
|
|
9
|
+
*
|
|
10
|
+
* A wildcard resource string (`"*"`) always matches.
|
|
11
|
+
*
|
|
12
|
+
* This is a compatibility check: it returns true when there is at least one
|
|
13
|
+
* concrete ARN that could satisfy both the resource string and the resource
|
|
14
|
+
* type pattern. Resource type variables may span resource-component separators
|
|
15
|
+
* such as `:` and `/`.
|
|
16
|
+
*
|
|
17
|
+
* @param resourceString - A concrete resource ARN or wildcard (`"*"`)
|
|
18
|
+
* @param resourcePattern - An ARN pattern from iam-data (e.g. `arn:${Partition}:s3:::${BucketName}/${ObjectName}`)
|
|
19
|
+
* @returns Whether the resource string matches the pattern
|
|
20
|
+
*/
|
|
21
|
+
function resourceStringMatchesResourceTypePattern(resourceString, resourcePattern) {
|
|
22
|
+
if (resourceString === '*') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const resourceParts = (0, arn_js_1.splitArnParts)(resourceString);
|
|
26
|
+
const patternParts = (0, arn_js_1.splitArnParts)(resourcePattern);
|
|
27
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.partition, patternParts.partition)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.service, patternParts.service)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.region, patternParts.region)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.accountId, patternParts.accountId)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return resourceComponentMatchesResourceTypeComponent(resourceParts.resource, patternParts.resource);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Reduce resource type patterns to the most specific patterns that match a resource string.
|
|
43
|
+
*
|
|
44
|
+
* This helper does not know about iam-data or service-specific resource type ordering. It uses
|
|
45
|
+
* the provided pattern set as context and removes matching parent patterns when a matching child
|
|
46
|
+
* pattern has all of the parent's literal structure plus additional literal structure. Wildcard
|
|
47
|
+
* resource strings preserve all matches because the wildcard may refer to parent and child resources.
|
|
48
|
+
*
|
|
49
|
+
* @param resourceString - A concrete resource ARN or wildcard (`"*"`)
|
|
50
|
+
* @param resourcePatterns - Candidate resource type ARN patterns
|
|
51
|
+
* @returns Matching resource type patterns with less-specific parent patterns removed, in input order
|
|
52
|
+
*/
|
|
53
|
+
function mostSpecificMatchingResourceTypePatterns(resourceString, resourcePatterns) {
|
|
54
|
+
const matchingPatterns = resourcePatterns.filter((pattern) => resourceStringMatchesResourceTypePattern(resourceString, pattern));
|
|
55
|
+
if (resourceString.includes('*') || resourceString.includes('?')) {
|
|
56
|
+
return matchingPatterns;
|
|
57
|
+
}
|
|
58
|
+
return matchingPatterns.filter((candidatePattern, candidateIndex) => {
|
|
59
|
+
return !matchingPatterns.some((otherPattern, otherIndex) => {
|
|
60
|
+
return (otherIndex !== candidateIndex &&
|
|
61
|
+
resourceTypePatternIsMoreSpecific(otherPattern, candidatePattern));
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check whether one resource type pattern is more specific than another.
|
|
67
|
+
*
|
|
68
|
+
* @param possibleChildPattern - The pattern that may be more specific
|
|
69
|
+
* @param possibleParentPattern - The pattern that may be less specific
|
|
70
|
+
* @returns Whether the possible child has all parent literal structure plus more literal structure
|
|
71
|
+
*/
|
|
72
|
+
function resourceTypePatternIsMoreSpecific(possibleChildPattern, possibleParentPattern) {
|
|
73
|
+
const childLiteralText = literalTextFromResourceTypePattern(possibleChildPattern);
|
|
74
|
+
const parentLiteralText = literalTextFromResourceTypePattern(possibleParentPattern);
|
|
75
|
+
return (childLiteralText.length > parentLiteralText.length &&
|
|
76
|
+
childLiteralText.startsWith(parentLiteralText));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extract the literal text from a resource type pattern by removing variable placeholders.
|
|
80
|
+
*
|
|
81
|
+
* @param pattern - The resource type pattern to inspect
|
|
82
|
+
* @returns Literal pattern text without `${Variable}` placeholders
|
|
83
|
+
*/
|
|
84
|
+
function literalTextFromResourceTypePattern(pattern) {
|
|
85
|
+
return tokenizeResourceTypePattern(pattern)
|
|
86
|
+
.filter((token) => token.type === 'literal')
|
|
87
|
+
.map((token) => token.value)
|
|
88
|
+
.join('');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check whether a resource string component is compatible with a resource type pattern component.
|
|
92
|
+
*
|
|
93
|
+
* @param resourceComponent - The component value from the concrete or wildcard ARN
|
|
94
|
+
* @param resourceTypeComponent - The component value from the resource type pattern ARN
|
|
95
|
+
* @returns Whether at least one concrete component can satisfy both component patterns
|
|
96
|
+
*/
|
|
97
|
+
function resourceComponentMatchesResourceTypeComponent(resourceComponent, resourceTypeComponent) {
|
|
98
|
+
if (resourceTypeComponent === '*') {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (resourceComponent === undefined || resourceTypeComponent === undefined) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (resourceComponent === '' || resourceTypeComponent === '') {
|
|
105
|
+
return (resourceComponent.localeCompare(resourceTypeComponent, undefined, {
|
|
106
|
+
sensitivity: 'accent'
|
|
107
|
+
}) === 0);
|
|
108
|
+
}
|
|
109
|
+
return patternsHaveIntersection(createResourceStringAutomaton(resourceComponent), createResourceTypePatternAutomaton(resourceTypeComponent));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check whether two resource pattern automata accept at least one common string.
|
|
113
|
+
*
|
|
114
|
+
* @param first - The first pattern automaton to compare
|
|
115
|
+
* @param second - The second pattern automaton to compare
|
|
116
|
+
* @returns Whether the pattern languages have a non-empty intersection
|
|
117
|
+
*/
|
|
118
|
+
function patternsHaveIntersection(first, second) {
|
|
119
|
+
const visited = new Set();
|
|
120
|
+
const queue = [[0, 0]];
|
|
121
|
+
while (queue.length > 0) {
|
|
122
|
+
const [firstState, secondState] = queue.shift();
|
|
123
|
+
const key = `${firstState}:${secondState}`;
|
|
124
|
+
if (visited.has(key)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
visited.add(key);
|
|
128
|
+
if (firstState === first.acceptingState && secondState === second.acceptingState) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
const firstTransitions = first.transitions(firstState);
|
|
132
|
+
const secondTransitions = second.transitions(secondState);
|
|
133
|
+
for (const transition of firstTransitions) {
|
|
134
|
+
if (!transition.consumes) {
|
|
135
|
+
queue.push([transition.nextState, secondState]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const transition of secondTransitions) {
|
|
139
|
+
if (!transition.consumes) {
|
|
140
|
+
queue.push([firstState, transition.nextState]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
for (const firstTransition of firstTransitions) {
|
|
144
|
+
if (!firstTransition.consumes) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
for (const secondTransition of secondTransitions) {
|
|
148
|
+
if (!secondTransition.consumes) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (characterMatchersIntersect(firstTransition.consumes, secondTransition.consumes)) {
|
|
152
|
+
queue.push([firstTransition.nextState, secondTransition.nextState]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create an automaton for a resource string that may contain IAM wildcards.
|
|
161
|
+
*
|
|
162
|
+
* @param resourceString - The resource string component to convert
|
|
163
|
+
* @returns An automaton accepting concrete strings matched by the resource string
|
|
164
|
+
*/
|
|
165
|
+
function createResourceStringAutomaton(resourceString) {
|
|
166
|
+
const chars = [...resourceString];
|
|
167
|
+
return {
|
|
168
|
+
acceptingState: chars.length,
|
|
169
|
+
transitions(state) {
|
|
170
|
+
if (state >= chars.length) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
const char = chars[state];
|
|
174
|
+
if (char === '*') {
|
|
175
|
+
return [{ nextState: state + 1 }, { nextState: state, consumes: 'any' }];
|
|
176
|
+
}
|
|
177
|
+
if (char === '?') {
|
|
178
|
+
return [{ nextState: state + 1, consumes: 'any' }];
|
|
179
|
+
}
|
|
180
|
+
return [{ nextState: state + 1, consumes: { char } }];
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Create an automaton for a Service Authorization Reference resource type component.
|
|
186
|
+
*
|
|
187
|
+
* @param resourceTypePattern - The resource type component to convert
|
|
188
|
+
* @returns An automaton accepting concrete strings matched by the resource type component
|
|
189
|
+
*/
|
|
190
|
+
function createResourceTypePatternAutomaton(resourceTypePattern) {
|
|
191
|
+
const tokens = tokenizeResourceTypePattern(resourceTypePattern);
|
|
192
|
+
return {
|
|
193
|
+
acceptingState: tokens.length,
|
|
194
|
+
transitions(state) {
|
|
195
|
+
if (state >= tokens.length) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
const token = tokens[state];
|
|
199
|
+
if (token.type === 'variable') {
|
|
200
|
+
return [
|
|
201
|
+
{ nextState: state, consumes: token.characterMatcher },
|
|
202
|
+
{ nextState: state + 1, consumes: token.characterMatcher }
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
return [{ nextState: state + 1, consumes: { char: token.value } }];
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Tokenize a Service Authorization Reference resource type pattern.
|
|
211
|
+
*
|
|
212
|
+
* @param pattern - The resource type pattern component to tokenize
|
|
213
|
+
* @returns Tokens representing literals and `${Variable}` placeholders
|
|
214
|
+
*/
|
|
215
|
+
function tokenizeResourceTypePattern(pattern) {
|
|
216
|
+
const tokens = [];
|
|
217
|
+
const variableMatches = [...pattern.matchAll(/\$\{[0-9a-zA-Z]+\}/g)];
|
|
218
|
+
const patternIsSingleVariable = variableMatches.length === 1 && variableMatches[0][0] === pattern;
|
|
219
|
+
for (let i = 0; i < pattern.length;) {
|
|
220
|
+
if (pattern[i] === '$' && pattern[i + 1] === '{') {
|
|
221
|
+
const endIndex = pattern.indexOf('}', i + 2);
|
|
222
|
+
if (endIndex !== -1) {
|
|
223
|
+
tokens.push({
|
|
224
|
+
type: 'variable',
|
|
225
|
+
characterMatcher: patternIsSingleVariable ? 'nonSeparator' : 'any'
|
|
226
|
+
});
|
|
227
|
+
i = endIndex + 1;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
tokens.push({ type: 'literal', value: pattern[i] });
|
|
232
|
+
i++;
|
|
233
|
+
}
|
|
234
|
+
return tokens;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Check whether two character matchers can consume the same character.
|
|
238
|
+
*
|
|
239
|
+
* @param first - The first character matcher
|
|
240
|
+
* @param second - The second character matcher
|
|
241
|
+
* @returns Whether the matchers have a non-empty intersection
|
|
242
|
+
*/
|
|
243
|
+
function characterMatchersIntersect(first, second) {
|
|
244
|
+
if (first === 'any' || second === 'any') {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
if (first === 'nonSeparator' && second === 'nonSeparator') {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
if (first === 'nonSeparator') {
|
|
251
|
+
return typeof second === 'object' && !isResourceComponentSeparator(second.char);
|
|
252
|
+
}
|
|
253
|
+
if (second === 'nonSeparator') {
|
|
254
|
+
return typeof first === 'object' && !isResourceComponentSeparator(first.char);
|
|
255
|
+
}
|
|
256
|
+
return first.char.localeCompare(second.char, undefined, { sensitivity: 'accent' }) === 0;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Check whether a character is a resource component separator.
|
|
260
|
+
*
|
|
261
|
+
* @param char - The character to check
|
|
262
|
+
* @returns Whether the character separates resource component segments
|
|
263
|
+
*/
|
|
264
|
+
function isResourceComponentSeparator(char) {
|
|
265
|
+
return char === ':' || char === '/';
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=resourceTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceTypes.js","sourceRoot":"","sources":["../../src/resourceTypes.ts"],"names":[],"mappings":";;AAqDA,4FAmCC;AAcD,4FAoBC;AA1HD,qCAAwC;AAsCxC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,wCAAwC,CACtD,cAAsB,EACtB,eAAuB;IAEvB,IAAI,cAAc,KAAK,GAAG,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,aAAa,GAAG,IAAA,sBAAa,EAAC,cAAc,CAAC,CAAA;IACnD,MAAM,YAAY,GAAG,IAAA,sBAAa,EAAC,eAAe,CAAC,CAAA;IAEnD,IACE,CAAC,6CAA6C,CAAC,aAAa,CAAC,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,EAC/F,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,CAAC,6CAA6C,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QAChG,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,CAAC,6CAA6C,CAAC,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9F,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IACE,CAAC,6CAA6C,CAAC,aAAa,CAAC,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,EAC/F,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,6CAA6C,CAClD,aAAa,CAAC,QAAQ,EACtB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,CAAC,EAAE,CAAA;IACL,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,0BAA0B,CAAC,KAAuB,EAAE,MAAwB;IACnF,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACxC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,KAAK,KAAK,cAAc,IAAI,MAAM,KAAK,cAAc,EAAE,CAAC;QAC1D,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,KAAK,KAAK,cAAc,EAAE,CAAC;QAC7B,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,4BAA4B,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACjF,CAAC;IAED,IAAI,MAAM,KAAK,cAAc,EAAE,CAAC;QAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,4BAA4B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC/E,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAA;AAC1F,CAAC;AAED;;;;;GAKG;AACH,SAAS,4BAA4B,CAAC,IAAY;IAChD,OAAO,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
3
|
+
*
|
|
4
|
+
* @param pattern The ARN pattern string with wildcards
|
|
5
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
6
|
+
*/
|
|
7
|
+
export declare function resourceArnWithWildcardsToRegex(pattern: string): RegExp;
|
|
8
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGvE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resourceArnWithWildcardsToRegex = resourceArnWithWildcardsToRegex;
|
|
4
|
+
/**
|
|
5
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
6
|
+
*
|
|
7
|
+
* @param pattern The ARN pattern string with wildcards
|
|
8
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
9
|
+
*/
|
|
10
|
+
function resourceArnWithWildcardsToRegex(pattern) {
|
|
11
|
+
const parts = pattern.split('*').map((s) => s.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&'));
|
|
12
|
+
return new RegExp('^' + parts.join('.*?') + '$');
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":";;AAMA,0EAGC;AATD;;;;;GAKG;AACH,SAAgB,+BAA+B,CAAC,OAAe;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC,CAAA;IACtF,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAA;AAClD,CAAC"}
|
package/dist/cjs/s3.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks to see if an ARN is an S3 bucket or object ARN
|
|
3
|
+
*
|
|
4
|
+
* @param arn the ARN to check
|
|
5
|
+
* @returns whether the ARN is an S3 bucket or object ARN
|
|
6
|
+
*/
|
|
7
|
+
export declare function isS3BucketOrObjectArn(arn: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Get the bucket ARN from an S3 bucket or object ARN. Does not validate the input ARN.
|
|
10
|
+
*
|
|
11
|
+
* @param bucketOrObjectArn the ARN of the S3 bucket or object
|
|
12
|
+
* @returns the ARN of the S3 bucket
|
|
13
|
+
*/
|
|
14
|
+
export declare function bucketArn(bucketOrObjectArn: string): string;
|
|
15
|
+
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../src/s3.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAa1D;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAE3D"}
|
package/dist/cjs/s3.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isS3BucketOrObjectArn = isS3BucketOrObjectArn;
|
|
4
|
+
exports.bucketArn = bucketArn;
|
|
5
|
+
const arn_js_1 = require("./arn.js");
|
|
6
|
+
/**
|
|
7
|
+
* Checks to see if an ARN is an S3 bucket or object ARN
|
|
8
|
+
*
|
|
9
|
+
* @param arn the ARN to check
|
|
10
|
+
* @returns whether the ARN is an S3 bucket or object ARN
|
|
11
|
+
*/
|
|
12
|
+
function isS3BucketOrObjectArn(arn) {
|
|
13
|
+
const arnParts = (0, arn_js_1.splitArnParts)(arn);
|
|
14
|
+
if (arnParts.service !== 's3') {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (!arnParts.resource) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// S3 bucket or object ARNs have no account ID or region
|
|
21
|
+
if (arnParts.accountId || arnParts.region) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the bucket ARN from an S3 bucket or object ARN. Does not validate the input ARN.
|
|
28
|
+
*
|
|
29
|
+
* @param bucketOrObjectArn the ARN of the S3 bucket or object
|
|
30
|
+
* @returns the ARN of the S3 bucket
|
|
31
|
+
*/
|
|
32
|
+
function bucketArn(bucketOrObjectArn) {
|
|
33
|
+
return bucketOrObjectArn.split('/').at(0);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=s3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.js","sourceRoot":"","sources":["../../src/s3.ts"],"names":[],"mappings":";;AAQA,sDAaC;AAQD,8BAEC;AA/BD,qCAAwC;AAExC;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,GAAW;IAC/C,MAAM,QAAQ,GAAG,IAAA,sBAAa,EAAC,GAAG,CAAC,CAAA;IACnC,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACvB,OAAO,KAAK,CAAA;IACd,CAAC;IACD,wDAAwD;IACxD,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,iBAAyB;IACjD,OAAO,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks to see if the action matches the provided IAM action pattern.
|
|
3
|
+
*
|
|
4
|
+
* @param action the action to check, should not contain wildcards
|
|
5
|
+
* @param pattern the pattern to match against, may contain wildcards
|
|
6
|
+
* @returns true if the action matches the pattern, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export declare function actionMatchesPattern(action: string, pattern: string): boolean;
|
|
9
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAuC7E"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks to see if the action matches the provided IAM action pattern.
|
|
3
|
+
*
|
|
4
|
+
* @param action the action to check, should not contain wildcards
|
|
5
|
+
* @param pattern the pattern to match against, may contain wildcards
|
|
6
|
+
* @returns true if the action matches the pattern, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export function actionMatchesPattern(action, pattern) {
|
|
9
|
+
const unescapedAction = unescapeUnicodeCharacters(action);
|
|
10
|
+
const unescapedPattern = unescapeUnicodeCharacters(pattern);
|
|
11
|
+
// Full wildcard matches everything
|
|
12
|
+
if (unescapedPattern === '*') {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
// Split into service and action parts
|
|
16
|
+
const patternColonIndex = unescapedPattern.indexOf(':');
|
|
17
|
+
const actionColonIndex = unescapedAction.indexOf(':');
|
|
18
|
+
// If pattern has no colon, it must match the entire action exactly (case-insensitive)
|
|
19
|
+
if (patternColonIndex === -1) {
|
|
20
|
+
if (actionColonIndex === -1) {
|
|
21
|
+
return unescapedAction.toLowerCase() === unescapedPattern.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
// If action has no colon but pattern does, no match
|
|
26
|
+
if (actionColonIndex === -1) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const patternService = unescapedPattern.substring(0, patternColonIndex);
|
|
30
|
+
const patternAction = unescapedPattern.substring(patternColonIndex + 1);
|
|
31
|
+
const actionService = unescapedAction.substring(0, actionColonIndex);
|
|
32
|
+
const actionAction = unescapedAction.substring(actionColonIndex + 1);
|
|
33
|
+
// Service must match exactly (case-insensitive), no wildcards allowed
|
|
34
|
+
if (patternService.toLowerCase() !== actionService.toLowerCase()) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
// Match the action part with wildcards
|
|
38
|
+
const regex = convertStringToPattern(patternAction);
|
|
39
|
+
return regex.test(actionAction);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts an action string pattern to a regular expression for matching.
|
|
43
|
+
*
|
|
44
|
+
* @param actionString the IAM action pattern string to convert
|
|
45
|
+
* @returns RegExp that matches the pattern (case-insensitive)
|
|
46
|
+
*/
|
|
47
|
+
function convertStringToPattern(actionString) {
|
|
48
|
+
const pattern = '^' + actionString.replace(/\?/g, '.').replace(/\*/g, '.*?') + '$';
|
|
49
|
+
return new RegExp(pattern, 'i');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Unescapes unicode characters in a string.
|
|
53
|
+
*
|
|
54
|
+
* @param str The string to unescape
|
|
55
|
+
* @returns The string with any escaped unicode characters replaced with their actual characters
|
|
56
|
+
*/
|
|
57
|
+
function unescapeUnicodeCharacters(str) {
|
|
58
|
+
return str.replace(/\\u([\dA-Fa-f]{4})/gi, (match, code) => {
|
|
59
|
+
return String.fromCharCode(parseInt(code, 16));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":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C;IAED,uCAAuC;IACvC,MAAM,KAAK,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAA;IACnD,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,sBAAsB,CAAC,YAAoB;IAClD,MAAM,OAAO,GAAG,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,GAAG,CAAA;IAClF,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,GAAW;IAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACzD,OAAO,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface ArnParts {
|
|
2
|
+
/**
|
|
3
|
+
* The partition of the ARN such as aws, aws-cn, aws-us-gov
|
|
4
|
+
*/
|
|
5
|
+
partition: string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The service of the ARN such as s3, ec2, iam
|
|
8
|
+
*/
|
|
9
|
+
service: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The region of the ARN such as us-east-1, us-west-2
|
|
12
|
+
*/
|
|
13
|
+
region: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The account ID of the ARN
|
|
16
|
+
*/
|
|
17
|
+
accountId: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The resource portion of the ARN, includes the resource type, path and name
|
|
20
|
+
*/
|
|
21
|
+
resource: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The resource type of the ARN, such as instance, user, topic, may be undefined for
|
|
24
|
+
* some S3 buckets.
|
|
25
|
+
*/
|
|
26
|
+
resourceType: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The resource path and name of the ARN, such as Development/user1, or MyTopic or my-bucket/my-object.txt
|
|
29
|
+
*/
|
|
30
|
+
resourcePath: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Split an ARN into its parts
|
|
34
|
+
*
|
|
35
|
+
* @param arn the arn to split
|
|
36
|
+
* @returns the parts of the ARN
|
|
37
|
+
*/
|
|
38
|
+
export declare function splitArnParts(arn: string): ArnParts;
|
|
39
|
+
/**
|
|
40
|
+
* Get the product/id segments of the resource portion of an ARN.
|
|
41
|
+
* The first segment is the product segment and the second segment is the resource id segment.
|
|
42
|
+
* This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
|
|
43
|
+
*
|
|
44
|
+
* @param resource The resource to get the resource segments. Must be an ARN resource.
|
|
45
|
+
* @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getResourceSegments(service: string, accountId: string, region: string, resourceString: string): [string, string];
|
|
48
|
+
//# sourceMappingURL=arn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.d.ts","sourceRoot":"","sources":["../../src/arn.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAE7B;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAE3B;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAE1B;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAE7B;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAE5B;;;OAGG;IACH,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAEhC;;OAEG;IACH,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAkBnD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,CAAC,MAAM,EAAE,MAAM,CAAC,CA+BlB"}
|
package/dist/esm/arn.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split an ARN into its parts
|
|
3
|
+
*
|
|
4
|
+
* @param arn the arn to split
|
|
5
|
+
* @returns the parts of the ARN
|
|
6
|
+
*/
|
|
7
|
+
export function splitArnParts(arn) {
|
|
8
|
+
const parts = arn.split(':');
|
|
9
|
+
const partition = parts.at(1);
|
|
10
|
+
const service = parts.at(2);
|
|
11
|
+
const region = parts.at(3);
|
|
12
|
+
const accountId = parts.at(4);
|
|
13
|
+
const resource = parts.slice(5).join(':');
|
|
14
|
+
const [resourceType, resourcePath] = getResourceSegments(service, accountId, region, resource);
|
|
15
|
+
return {
|
|
16
|
+
partition,
|
|
17
|
+
service,
|
|
18
|
+
region,
|
|
19
|
+
accountId,
|
|
20
|
+
resource,
|
|
21
|
+
resourceType,
|
|
22
|
+
resourcePath
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the product/id segments of the resource portion of an ARN.
|
|
27
|
+
* The first segment is the product segment and the second segment is the resource id segment.
|
|
28
|
+
* This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
|
|
29
|
+
*
|
|
30
|
+
* @param resource The resource to get the resource segments. Must be an ARN resource.
|
|
31
|
+
* @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
|
|
32
|
+
*/
|
|
33
|
+
export function getResourceSegments(service, accountId, region, resourceString) {
|
|
34
|
+
// This is terrible, and I hate it
|
|
35
|
+
if ((service === 's3' && accountId === '' && region === '') ||
|
|
36
|
+
service === 'sns' ||
|
|
37
|
+
service === 'sqs') {
|
|
38
|
+
return ['', resourceString];
|
|
39
|
+
}
|
|
40
|
+
if (resourceString.startsWith('/')) {
|
|
41
|
+
resourceString = resourceString.slice(1);
|
|
42
|
+
}
|
|
43
|
+
const slashIndex = resourceString.indexOf('/');
|
|
44
|
+
const colonIndex = resourceString.indexOf(':');
|
|
45
|
+
let splitIndex = slashIndex;
|
|
46
|
+
if (slashIndex != -1 && colonIndex != -1) {
|
|
47
|
+
splitIndex = Math.min(slashIndex, colonIndex) + 1;
|
|
48
|
+
}
|
|
49
|
+
else if (slashIndex == -1 && colonIndex == -1) {
|
|
50
|
+
splitIndex = resourceString.length + 1;
|
|
51
|
+
}
|
|
52
|
+
else if (colonIndex == -1) {
|
|
53
|
+
splitIndex = slashIndex + 1;
|
|
54
|
+
}
|
|
55
|
+
else if (slashIndex == -1) {
|
|
56
|
+
splitIndex = colonIndex + 1;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error(`Unable to split resource ${resourceString}`);
|
|
60
|
+
}
|
|
61
|
+
return [resourceString.slice(0, splitIndex - 1), resourceString.slice(splitIndex)];
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=arn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.js","sourceRoot":"","sources":["../../src/arn.ts"],"names":[],"mappings":"AAsCA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CAAA;IAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAE,CA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AAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAChD,UAAU,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAA;IACxC,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;AACpF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { actionMatchesPattern } from './actions.js';
|
|
2
|
+
export { getResourceSegments, splitArnParts, type ArnParts } from './arn.js';
|
|
3
|
+
export { convertAssumedRoleArnToRoleArn, convertRoleArnToAssumedRoleArn, isArnPrincipal, isAssumedRoleArn, isFederatedUserArn, isIamRoleArn, isIamUserArn, isServicePrincipal } from './principals.js';
|
|
4
|
+
export { convertResourcePatternToRegex } from './resourcePatterns.js';
|
|
5
|
+
export { resourceArnWithWildcardsToRegex } from './resources.js';
|
|
6
|
+
export { mostSpecificMatchingResourceTypePatterns, resourceStringMatchesResourceTypePattern } from './resourceTypes.js';
|
|
7
|
+
export { actionSupportsAwsResourceInfoContextKeys, isAwsResourceInfoExcludedAction } from './resourceInfoContextKeys.js';
|
|
8
|
+
export { bucketArn, isS3BucketOrObjectArn } from './s3.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EACL,wCAAwC,EACxC,wCAAwC,EACzC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,wCAAwC,EACxC,+BAA+B,EAChC,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { actionMatchesPattern } from './actions.js';
|
|
2
|
+
export { getResourceSegments, splitArnParts } from './arn.js';
|
|
3
|
+
export { convertAssumedRoleArnToRoleArn, convertRoleArnToAssumedRoleArn, isArnPrincipal, isAssumedRoleArn, isFederatedUserArn, isIamRoleArn, isIamUserArn, isServicePrincipal } from './principals.js';
|
|
4
|
+
export { convertResourcePatternToRegex } from './resourcePatterns.js';
|
|
5
|
+
export { resourceArnWithWildcardsToRegex } from './resources.js';
|
|
6
|
+
export { mostSpecificMatchingResourceTypePatterns, resourceStringMatchesResourceTypePattern } from './resourceTypes.js';
|
|
7
|
+
export { actionSupportsAwsResourceInfoContextKeys, isAwsResourceInfoExcludedAction } from './resourceInfoContextKeys.js';
|
|
8
|
+
export { bucketArn, isS3BucketOrObjectArn } from './s3.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAiB,MAAM,UAAU,CAAA;AAC5E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EACL,wCAAwC,EACxC,wCAAwC,EACzC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,wCAAwC,EACxC,+BAA+B,EAChC,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|