@cloud-copilot/iam-expand 0.1.6 → 0.1.8
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 +254 -203
- package/dist/cjs/cli.js +8 -7
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/expand.d.ts +1 -13
- package/dist/cjs/expand.d.ts.map +1 -1
- package/dist/cjs/expand.js +5 -21
- package/dist/cjs/expand.js.map +1 -1
- package/dist/cjs/expand_file.js +1 -1
- package/dist/cjs/expand_file.js.map +1 -1
- package/dist/esm/cli.js +8 -7
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/expand.d.ts +1 -13
- package/dist/esm/expand.d.ts.map +1 -1
- package/dist/esm/expand.js +5 -21
- package/dist/esm/expand.js.map +1 -1
- package/dist/esm/expand_file.js +1 -1
- package/dist/esm/expand_file.js.map +1 -1
- package/examples/README.md +3 -0
- package/examples/download-and-expand-authorization-details.sh +8 -0
- package/examples/download-and-expand-policies.sh +22 -0
- package/package.json +1 -1
- package/src/cli.ts +9 -7
- package/src/expand.test.ts +39 -79
- package/src/expand.ts +7 -38
- package/src/expand_file.test.ts +0 -2
- package/src/expand_file.ts +1 -1
package/src/expand.ts
CHANGED
|
@@ -37,15 +37,7 @@ export interface ExpandIamActionsOptions {
|
|
|
37
37
|
* If false, an empty array will be returned
|
|
38
38
|
* Default: false
|
|
39
39
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* If true, only unique values will be returned, while maintaining order
|
|
44
|
-
* If false, all values will be returned, even if they are duplicates
|
|
45
|
-
* Default: false
|
|
46
|
-
*/
|
|
47
|
-
distinct: boolean
|
|
48
|
-
|
|
40
|
+
errorOnInvalidService: boolean
|
|
49
41
|
|
|
50
42
|
/**
|
|
51
43
|
* The behavior to use when an invalid action is encountered without wildcards
|
|
@@ -56,23 +48,14 @@ export interface ExpandIamActionsOptions {
|
|
|
56
48
|
* Default: InvalidActionBehavior.Remove
|
|
57
49
|
*/
|
|
58
50
|
invalidActionBehavior: InvalidActionBehavior
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* If true, the returned array will be sorted
|
|
62
|
-
* If false, the returned array will be in the order they were expanded
|
|
63
|
-
* Default: false
|
|
64
|
-
*/
|
|
65
|
-
sort: boolean
|
|
66
51
|
}
|
|
67
52
|
|
|
68
53
|
const defaultOptions: ExpandIamActionsOptions = {
|
|
69
54
|
expandAsterisk: false,
|
|
70
55
|
expandServiceAsterisk: false,
|
|
71
56
|
errorOnInvalidFormat: false,
|
|
72
|
-
|
|
57
|
+
errorOnInvalidService: false,
|
|
73
58
|
invalidActionBehavior: InvalidActionBehavior.Remove,
|
|
74
|
-
distinct: false,
|
|
75
|
-
sort: false
|
|
76
59
|
}
|
|
77
60
|
|
|
78
61
|
const allAsterisksPattern = /^\*+$/i
|
|
@@ -101,21 +84,9 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
|
|
|
101
84
|
return expandIamActions(actionString, options);
|
|
102
85
|
}))
|
|
103
86
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const aSet = new Set<string>()
|
|
108
|
-
allMatches = allMatches.filter((value) => {
|
|
109
|
-
if(aSet.has(value)) {
|
|
110
|
-
return false
|
|
111
|
-
}
|
|
112
|
-
aSet.add(value)
|
|
113
|
-
return true
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
if(options.sort) {
|
|
117
|
-
allMatches.sort()
|
|
118
|
-
}
|
|
87
|
+
const allMatches = Array.from(new Set(actionLists.flat()))
|
|
88
|
+
allMatches.sort()
|
|
89
|
+
|
|
119
90
|
return allMatches
|
|
120
91
|
}
|
|
121
92
|
|
|
@@ -152,7 +123,7 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
|
|
|
152
123
|
|
|
153
124
|
const [service, wildcardActions] = parts.map(part => part.toLowerCase())
|
|
154
125
|
if(!await iamServiceExists(service)) {
|
|
155
|
-
if(options.
|
|
126
|
+
if(options.errorOnInvalidService) {
|
|
156
127
|
throw new Error(`Service not found: ${service}`)
|
|
157
128
|
}
|
|
158
129
|
return []
|
|
@@ -189,9 +160,7 @@ export async function expandIamActions(actionStringOrStrings: string | string[],
|
|
|
189
160
|
const pattern = "^" + wildcardActions.replace(/\*/g, '.*?') + "$"
|
|
190
161
|
const regex = new RegExp(pattern, 'i')
|
|
191
162
|
const matchingActions = allActions.filter(action => regex.test(action)).map(action => `${service}:${action}`)
|
|
192
|
-
|
|
193
|
-
matchingActions.sort()
|
|
194
|
-
}
|
|
163
|
+
matchingActions.sort()
|
|
195
164
|
|
|
196
165
|
return matchingActions
|
|
197
166
|
}
|
package/src/expand_file.test.ts
CHANGED
|
@@ -55,7 +55,6 @@ describe('expand_file', () => {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
|
|
58
|
-
expect(options?.distinct).toBe(true)
|
|
59
58
|
return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
|
|
60
59
|
})
|
|
61
60
|
|
|
@@ -134,7 +133,6 @@ describe('expand_file', () => {
|
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
|
|
137
|
-
expect(options?.distinct).toBe(true)
|
|
138
136
|
return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
|
|
139
137
|
})
|
|
140
138
|
|
package/src/expand_file.ts
CHANGED
|
@@ -14,7 +14,7 @@ export async function expandJsonDocument(options: Partial<ExpandIamActionsOption
|
|
|
14
14
|
return await expandIamActions(document, options)
|
|
15
15
|
}
|
|
16
16
|
if(Array.isArray(document) && document.length > 0 && typeof document[0] === 'string') {
|
|
17
|
-
const value = await expandIamActions(document, {...options
|
|
17
|
+
const value = await expandIamActions(document, {...options})
|
|
18
18
|
return value
|
|
19
19
|
}
|
|
20
20
|
}
|