@cloud-copilot/iam-expand 0.1.0
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 +674 -0
- package/README.md +269 -0
- package/dist/cjs/cli.d.ts +3 -0
- package/dist/cjs/cli.d.ts.map +1 -0
- package/dist/cjs/cli.js +76 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/cli_utils.d.ts +27 -0
- package/dist/cjs/cli_utils.d.ts.map +1 -0
- package/dist/cjs/cli_utils.js +69 -0
- package/dist/cjs/cli_utils.js.map +1 -0
- package/dist/cjs/expand.d.ts +69 -0
- package/dist/cjs/expand.d.ts.map +1 -0
- package/dist/cjs/expand.js +118 -0
- package/dist/cjs/expand.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/stdin.d.ts +7 -0
- package/dist/cjs/stdin.d.ts.map +1 -0
- package/dist/cjs/stdin.js +34 -0
- package/dist/cjs/stdin.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +67 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli_utils.d.ts +27 -0
- package/dist/cli_utils.d.ts.map +1 -0
- package/dist/cli_utils.js +57 -0
- package/dist/cli_utils.js.map +1 -0
- package/dist/cli_utils.test.d.ts +2 -0
- package/dist/cli_utils.test.d.ts.map +1 -0
- package/dist/cli_utils.test.js +90 -0
- package/dist/cli_utils.test.js.map +1 -0
- package/dist/esm/cli.d.ts +3 -0
- package/dist/esm/cli.d.ts.map +1 -0
- package/dist/esm/cli.js +74 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/esm/cli_utils.d.ts +27 -0
- package/dist/esm/cli_utils.d.ts.map +1 -0
- package/dist/esm/cli_utils.js +63 -0
- package/dist/esm/cli_utils.js.map +1 -0
- package/dist/esm/expand.d.ts +69 -0
- package/dist/esm/expand.d.ts.map +1 -0
- package/dist/esm/expand.js +114 -0
- package/dist/esm/expand.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/stdin.d.ts +7 -0
- package/dist/esm/stdin.d.ts.map +1 -0
- package/dist/esm/stdin.js +31 -0
- package/dist/esm/stdin.js.map +1 -0
- package/dist/expand.d.ts +55 -0
- package/dist/expand.d.ts.map +1 -0
- package/dist/expand.js +94 -0
- package/dist/expand.js.map +1 -0
- package/dist/expand.test.d.ts +2 -0
- package/dist/expand.test.d.ts.map +1 -0
- package/dist/expand.test.js +382 -0
- package/dist/expand.test.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/stdin.d.ts +7 -0
- package/dist/stdin.d.ts.map +1 -0
- package/dist/stdin.js +35 -0
- package/dist/stdin.js.map +1 -0
- package/package.json +33 -0
- package/postbuild.sh +13 -0
- package/src/cli.ts +82 -0
- package/src/cli_utils.test.ts +131 -0
- package/src/cli_utils.ts +78 -0
- package/src/expand.test.ts +523 -0
- package/src/expand.ts +185 -0
- package/src/index.ts +1 -0
- package/src/stdin.ts +34 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.esm.json +14 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const expand_1 = require("./expand");
|
|
4
|
+
const iam_data_1 = require("@cloud-copilot/iam-data");
|
|
5
|
+
jest.mock('@cloud-copilot/iam-data');
|
|
6
|
+
const mockGetActionsForService = iam_data_1.getActionsForService;
|
|
7
|
+
const mockServiceExists = iam_data_1.serviceExists;
|
|
8
|
+
const mockAllServiceKeys = iam_data_1.allServiceKeys;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.resetAllMocks();
|
|
11
|
+
});
|
|
12
|
+
describe("expand", () => {
|
|
13
|
+
it("should return an empty array when actionString is null", () => {
|
|
14
|
+
//Given actionString is null
|
|
15
|
+
const actionString = null;
|
|
16
|
+
//When expand is called with actionString
|
|
17
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
18
|
+
//Then result should be an empty array
|
|
19
|
+
expect(result).toEqual([]);
|
|
20
|
+
});
|
|
21
|
+
it("should return '*' when actionString is '*' and expandAsterik is false", () => {
|
|
22
|
+
//Given actionString is '*'
|
|
23
|
+
const actionString = '*';
|
|
24
|
+
//When expand is called with actionString
|
|
25
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
26
|
+
//Then result should be '*'
|
|
27
|
+
expect(result).toEqual(['*']);
|
|
28
|
+
});
|
|
29
|
+
it("should expand all actions for all services when actionString is '*' and expandAsterik is true", () => {
|
|
30
|
+
//Given actionString is '*'
|
|
31
|
+
const actionString = '*';
|
|
32
|
+
//And expandAsterik is true
|
|
33
|
+
const options = { expandAsterik: true };
|
|
34
|
+
//And there are services
|
|
35
|
+
mockAllServiceKeys.mockReturnValue(['s3', 'ec2']);
|
|
36
|
+
//And there are actions for the services
|
|
37
|
+
mockGetActionsForService.mockImplementation(service => {
|
|
38
|
+
if (service === 's3') {
|
|
39
|
+
return ['action1', 'action2'];
|
|
40
|
+
}
|
|
41
|
+
if (service === 'ec2') {
|
|
42
|
+
return ['action3', 'action4'];
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
});
|
|
46
|
+
//When expand is called with actionString and options
|
|
47
|
+
const result = (0, expand_1.expandIamActions)(actionString, options);
|
|
48
|
+
//Then result should be an array of all actions for all services
|
|
49
|
+
expect(result.sort()).toEqual([
|
|
50
|
+
'ec2:action3',
|
|
51
|
+
'ec2:action4',
|
|
52
|
+
's3:action1',
|
|
53
|
+
's3:action2'
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
it("should do a case insensitive match for the service in the action string", () => {
|
|
57
|
+
//Given actionString is 'S3:GetObject'
|
|
58
|
+
const actionString = 'S3:get*';
|
|
59
|
+
//And s3 service exists
|
|
60
|
+
mockServiceExists.mockImplementation((s) => s === 's3');
|
|
61
|
+
//And there are matching actions
|
|
62
|
+
mockGetActionsForService.mockReturnValue(['GetObject']);
|
|
63
|
+
//When expand is called with actionString
|
|
64
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
65
|
+
//Then result should be an array with the actionString
|
|
66
|
+
expect(result).toEqual(['s3:GetObject']);
|
|
67
|
+
});
|
|
68
|
+
it("should return the action string as is when it does not contain wildcards", () => {
|
|
69
|
+
//Given actionString contains no wildcards
|
|
70
|
+
const actionString = 's3:GetObject';
|
|
71
|
+
//And the service and action exist
|
|
72
|
+
mockServiceExists.mockReturnValue(true);
|
|
73
|
+
mockGetActionsForService.mockReturnValue(['GetObject']);
|
|
74
|
+
//When expand is called with actionString
|
|
75
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
76
|
+
//Then result should be an array with the actionString
|
|
77
|
+
expect(result).toEqual([actionString]);
|
|
78
|
+
});
|
|
79
|
+
describe("when the actions string is in the wrong format", () => {
|
|
80
|
+
it("should return an empty array when there are too many parts and errorOnInvalidFormat is false", () => {
|
|
81
|
+
//Given actionString is in the wrong format
|
|
82
|
+
const actionString = 's3:GetObject:Extra*';
|
|
83
|
+
//And errorOnInvalidFormat is false
|
|
84
|
+
const options = { errorOnInvalidFormat: false };
|
|
85
|
+
//When expand is called with actionString
|
|
86
|
+
const result = (0, expand_1.expandIamActions)(actionString, options);
|
|
87
|
+
//Then result should be an empty array
|
|
88
|
+
expect(result).toEqual([]);
|
|
89
|
+
});
|
|
90
|
+
it("should return an empty array when there are too few parts and errorOnInvalidFormat is false", () => {
|
|
91
|
+
//Given actionString has no :
|
|
92
|
+
const actionString = 's3GetObject*';
|
|
93
|
+
//And errorOnInvalidFormat is false
|
|
94
|
+
const options = { errorOnInvalidFormat: false };
|
|
95
|
+
//When expand is called with actionString
|
|
96
|
+
const result = (0, expand_1.expandIamActions)(actionString, options);
|
|
97
|
+
//Then result should be an empty array
|
|
98
|
+
expect(result).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
it("should throw an error when there are too many parts and errorOnInvalidFormat is true", () => {
|
|
101
|
+
//Given actionString is in the wrong format
|
|
102
|
+
const actionString = 's3:GetObject:Extra*';
|
|
103
|
+
//And errorOnInvalidFormat is true
|
|
104
|
+
const options = { errorOnInvalidFormat: true };
|
|
105
|
+
//When expand is called with actionString
|
|
106
|
+
//Then an error should be thrown
|
|
107
|
+
expect(() => (0, expand_1.expandIamActions)(actionString, options)).toThrowError('Invalid action format');
|
|
108
|
+
});
|
|
109
|
+
it("should throw an error when there are too few parts and errorOnInvalidFormat is true", () => {
|
|
110
|
+
//Given actionString has no :
|
|
111
|
+
const actionString = 's3GetObject*';
|
|
112
|
+
//And errorOnInvalidFormat is true
|
|
113
|
+
const options = { errorOnInvalidFormat: true };
|
|
114
|
+
//When expand is called with actionString
|
|
115
|
+
//Then an error should be thrown
|
|
116
|
+
expect(() => (0, expand_1.expandIamActions)(actionString, options)).toThrowError('Invalid action format');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe("when the service in the action string does not exist", () => {
|
|
120
|
+
it("should return an empty array when errorOnMissingService is false", () => {
|
|
121
|
+
//Given actionString contains a service that does not exist
|
|
122
|
+
const actionString = 'fake:GetObject*';
|
|
123
|
+
//And errorOnMissingService is false
|
|
124
|
+
const options = { errorOnMissingService: false };
|
|
125
|
+
//When expand is called with actionString
|
|
126
|
+
const result = (0, expand_1.expandIamActions)(actionString, options);
|
|
127
|
+
//Then result should be an empty array
|
|
128
|
+
expect(result).toEqual([]);
|
|
129
|
+
});
|
|
130
|
+
it("should throw an error when errorOnMissingService is true", () => {
|
|
131
|
+
//Given actionString contains a service that does not exist
|
|
132
|
+
const actionString = 'fake:GetObject*';
|
|
133
|
+
//And errorOnMissingService is true
|
|
134
|
+
const options = { errorOnMissingService: true };
|
|
135
|
+
//When expand is called with actionString
|
|
136
|
+
//Then an error should be thrown
|
|
137
|
+
expect(() => (0, expand_1.expandIamActions)(actionString, options)).toThrowError('Service not found');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe("when the action string contains a wildcard for a service", () => {
|
|
141
|
+
it("should expand not expand the wildcard when expandServiceAsterik is false", () => {
|
|
142
|
+
//Given actionString is 's3:*'
|
|
143
|
+
const actionString = 's3:*';
|
|
144
|
+
//And expandServiceAsterik is false
|
|
145
|
+
const options = { expandServiceAsterik: false };
|
|
146
|
+
//And s3 service exists
|
|
147
|
+
mockServiceExists.mockReturnValue(true);
|
|
148
|
+
//And there are matching actions
|
|
149
|
+
mockGetActionsForService.mockReturnValue(['GetObject', 'PutObject']);
|
|
150
|
+
//When expand is called with actionString
|
|
151
|
+
const result = (0, expand_1.expandIamActions)(actionString, options);
|
|
152
|
+
//Then result should be an array with the original string
|
|
153
|
+
expect(result).toEqual([actionString]);
|
|
154
|
+
});
|
|
155
|
+
it("should expand the wildcard when expandServiceAsterik is true", () => {
|
|
156
|
+
//Given actionString is 's3:*'
|
|
157
|
+
const actionString = 's3:*';
|
|
158
|
+
//And expandServiceAsterik is true
|
|
159
|
+
const options = { expandServiceAsterik: true };
|
|
160
|
+
//And s3 service exists
|
|
161
|
+
mockServiceExists.mockReturnValue(true);
|
|
162
|
+
//And there are matching actions
|
|
163
|
+
mockGetActionsForService.mockReturnValue(['GetObject', 'PutObject']);
|
|
164
|
+
//When expand is called with actionString
|
|
165
|
+
const result = (0, expand_1.expandIamActions)(actionString, options);
|
|
166
|
+
//Then result should be an array of actions
|
|
167
|
+
expect(result).toEqual([
|
|
168
|
+
's3:GetObject',
|
|
169
|
+
's3:PutObject'
|
|
170
|
+
]);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe("when the action string contains wildcards", () => {
|
|
174
|
+
it('should expand the wildcard actions at the end', () => {
|
|
175
|
+
//Given actionString is 's3:Get*'
|
|
176
|
+
const actionString = 's3:Get*';
|
|
177
|
+
//And s3 service exists
|
|
178
|
+
mockServiceExists.mockReturnValue(true);
|
|
179
|
+
//And there are matching actions
|
|
180
|
+
mockGetActionsForService.mockReturnValue([
|
|
181
|
+
'GetObject',
|
|
182
|
+
'GetObjectAcl',
|
|
183
|
+
'GetObjectTagging',
|
|
184
|
+
'GetObjectTorrent',
|
|
185
|
+
'PutObject',
|
|
186
|
+
'PutObjectAcl',
|
|
187
|
+
'SomethingGetSomething'
|
|
188
|
+
]);
|
|
189
|
+
//When expand is called with actionString
|
|
190
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
191
|
+
//Then result should be an array of actions
|
|
192
|
+
expect(result).toEqual([
|
|
193
|
+
's3:GetObject',
|
|
194
|
+
's3:GetObjectAcl',
|
|
195
|
+
's3:GetObjectTagging',
|
|
196
|
+
's3:GetObjectTorrent'
|
|
197
|
+
]);
|
|
198
|
+
});
|
|
199
|
+
it('should expand the wildcard actions at the beginning', () => {
|
|
200
|
+
//Given actionString is 's3:*Object'
|
|
201
|
+
const actionString = 's3:*Object';
|
|
202
|
+
//And s3 service exists
|
|
203
|
+
mockServiceExists.mockReturnValue(true);
|
|
204
|
+
//And there are matching actions
|
|
205
|
+
mockGetActionsForService.mockReturnValue([
|
|
206
|
+
'GetObject',
|
|
207
|
+
'GetObjectAcl',
|
|
208
|
+
'GetObjectTagging',
|
|
209
|
+
'GetObjectTorrent',
|
|
210
|
+
'PutObject',
|
|
211
|
+
'PutObjectAcl',
|
|
212
|
+
'SomethingGetSomething'
|
|
213
|
+
]);
|
|
214
|
+
//When expand is called with actionString
|
|
215
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
216
|
+
//Then result should be an array of actions
|
|
217
|
+
expect(result).toEqual([
|
|
218
|
+
's3:GetObject',
|
|
219
|
+
's3:PutObject'
|
|
220
|
+
]);
|
|
221
|
+
});
|
|
222
|
+
it('should expand the wildcard actions in the middle', () => {
|
|
223
|
+
//Given actionString is 's3:Get*Tagging'
|
|
224
|
+
const actionString = 's3:Get*Tagging';
|
|
225
|
+
//And s3 service exists
|
|
226
|
+
mockServiceExists.mockReturnValue(true);
|
|
227
|
+
//And there are matching actions
|
|
228
|
+
mockGetActionsForService.mockReturnValue([
|
|
229
|
+
'GetObject',
|
|
230
|
+
'GetObjectAcl',
|
|
231
|
+
'GetObjectTagging',
|
|
232
|
+
'GetBanskyTagging',
|
|
233
|
+
'GetObjectTorrent',
|
|
234
|
+
'PutObject',
|
|
235
|
+
'PutObjectAcl',
|
|
236
|
+
'SomethingGetSomething'
|
|
237
|
+
]);
|
|
238
|
+
//When expand is called with actionString
|
|
239
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
240
|
+
//Then result should be an array of actions
|
|
241
|
+
expect(result).toEqual([
|
|
242
|
+
's3:GetObjectTagging',
|
|
243
|
+
's3:GetBanskyTagging'
|
|
244
|
+
]);
|
|
245
|
+
});
|
|
246
|
+
it('should expand multiple wildcards', () => {
|
|
247
|
+
//Given actionString is 's3:Get*Tagging*'
|
|
248
|
+
const actionString = 's3:Get*Tagging*';
|
|
249
|
+
//And s3 service exists
|
|
250
|
+
mockServiceExists.mockReturnValue(true);
|
|
251
|
+
//And there are matching actions
|
|
252
|
+
mockGetActionsForService.mockReturnValue([
|
|
253
|
+
'GetObject',
|
|
254
|
+
'GetObjectAcl',
|
|
255
|
+
'GetObjectTagging',
|
|
256
|
+
'GetBanskyTagging',
|
|
257
|
+
'GetTagging',
|
|
258
|
+
'GetObjectTorrent',
|
|
259
|
+
'GetSomethingTaggingSomething',
|
|
260
|
+
'PutObject',
|
|
261
|
+
'PutObjectAcl',
|
|
262
|
+
'SomethingGetSomething'
|
|
263
|
+
]);
|
|
264
|
+
//When expand is called with actionString
|
|
265
|
+
const result = (0, expand_1.expandIamActions)(actionString);
|
|
266
|
+
//Then result should be an array of actions
|
|
267
|
+
expect(result).toEqual([
|
|
268
|
+
's3:GetObjectTagging',
|
|
269
|
+
's3:GetBanskyTagging',
|
|
270
|
+
's3:GetTagging',
|
|
271
|
+
's3:GetSomethingTaggingSomething'
|
|
272
|
+
]);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
describe("when actionStrings is an array", () => {
|
|
276
|
+
it("should return an empty array when actionStrings is an empty array", () => {
|
|
277
|
+
//Given actionStrings is an empty array
|
|
278
|
+
const actionStrings = [];
|
|
279
|
+
//When expand is called with actionStrings
|
|
280
|
+
const result = (0, expand_1.expandIamActions)(actionStrings);
|
|
281
|
+
//Then result should be an empty array
|
|
282
|
+
expect(result).toEqual([]);
|
|
283
|
+
});
|
|
284
|
+
it("should return an array of expanded actions when actionStrings is an array of action strings", () => {
|
|
285
|
+
//Given actionStrings is an array of action strings
|
|
286
|
+
const actionStrings = [
|
|
287
|
+
's3:Get*',
|
|
288
|
+
'ec2:*Instances'
|
|
289
|
+
];
|
|
290
|
+
//And s3 and ec2 services exist
|
|
291
|
+
mockServiceExists.mockReturnValue(true);
|
|
292
|
+
//And there are actions for the services
|
|
293
|
+
mockGetActionsForService.mockImplementation(service => {
|
|
294
|
+
if (service === 's3') {
|
|
295
|
+
return ['GetObject', 'GetObjectTagging', 'PutObject', 'PutObjectTagging'];
|
|
296
|
+
}
|
|
297
|
+
if (service === 'ec2') {
|
|
298
|
+
return ['RunInstances', 'TerminateInstances'];
|
|
299
|
+
}
|
|
300
|
+
return [];
|
|
301
|
+
});
|
|
302
|
+
//When expand is called with actionStrings
|
|
303
|
+
const result = (0, expand_1.expandIamActions)(actionStrings);
|
|
304
|
+
//Then result should be an array of expanded actions
|
|
305
|
+
expect(result.sort()).toEqual([
|
|
306
|
+
'ec2:RunInstances',
|
|
307
|
+
'ec2:TerminateInstances',
|
|
308
|
+
's3:GetObject',
|
|
309
|
+
's3:GetObjectTagging',
|
|
310
|
+
]);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
describe("distinct option", () => {
|
|
314
|
+
it('should return all values when distinct is false', () => {
|
|
315
|
+
//Given two action strings
|
|
316
|
+
const actionString = ['s3:Get*', 's3:*Object'];
|
|
317
|
+
//And s3 service exists
|
|
318
|
+
mockServiceExists.mockReturnValue(true);
|
|
319
|
+
//And there are matching actions
|
|
320
|
+
mockGetActionsForService.mockReturnValue(['GetObject', 'PutObject', 'GetOtherObject']);
|
|
321
|
+
//When expand is called with actionString and distinct is false
|
|
322
|
+
const result = (0, expand_1.expandIamActions)(actionString, { distinct: false });
|
|
323
|
+
//Then result should be an array of actions, even if they are duplicates
|
|
324
|
+
expect(result).toEqual(['s3:GetObject', 's3:GetOtherObject', 's3:GetObject', 's3:PutObject', 's3:GetOtherObject']);
|
|
325
|
+
});
|
|
326
|
+
it('should return only unique values when distinct is true, and maintain order', () => {
|
|
327
|
+
//Given two action strings
|
|
328
|
+
const actionString = ['s3:Get*', 's3:*Object'];
|
|
329
|
+
//And s3 service exists
|
|
330
|
+
mockServiceExists.mockReturnValue(true);
|
|
331
|
+
//And there are matching actions
|
|
332
|
+
mockGetActionsForService.mockReturnValue(['GetObject', 'PutObject', 'GetOtherObject']);
|
|
333
|
+
//When expand is called with actionStrings and distinct is true
|
|
334
|
+
const result = (0, expand_1.expandIamActions)(actionString, { distinct: true });
|
|
335
|
+
//Then result should be an array of unique actions
|
|
336
|
+
expect(result).toEqual(['s3:GetObject', 's3:GetOtherObject', 's3:PutObject']);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
describe("sort option", () => {
|
|
340
|
+
it('should return values in the order they were expanded when sort is false', () => {
|
|
341
|
+
//Given two action strings
|
|
342
|
+
const actionString = ['s3:Get*', 'ec2:Describe*'];
|
|
343
|
+
//And s3 service exists
|
|
344
|
+
mockServiceExists.mockReturnValue(true);
|
|
345
|
+
//And there are matching actions
|
|
346
|
+
mockGetActionsForService.mockImplementation(service => {
|
|
347
|
+
if (service === 's3') {
|
|
348
|
+
return ['GetObject', 'GetBucket'];
|
|
349
|
+
}
|
|
350
|
+
if (service === 'ec2') {
|
|
351
|
+
return ['DescribeInstances', 'DescribeVolumes'];
|
|
352
|
+
}
|
|
353
|
+
return [];
|
|
354
|
+
});
|
|
355
|
+
//When expand is called with actionStrings and sort is false
|
|
356
|
+
const result = (0, expand_1.expandIamActions)(actionString, { sort: false });
|
|
357
|
+
//Then result should be an array of actions in the order they were expanded
|
|
358
|
+
expect(result).toEqual(['s3:GetObject', 's3:GetBucket', 'ec2:DescribeInstances', 'ec2:DescribeVolumes']);
|
|
359
|
+
});
|
|
360
|
+
it('should return values sorted when sort is true', () => {
|
|
361
|
+
//Given two action strings
|
|
362
|
+
const actionString = ['s3:Get*', 'ec2:Describe*'];
|
|
363
|
+
//And s3 service exists
|
|
364
|
+
mockServiceExists.mockReturnValue(true);
|
|
365
|
+
//And there are matching actions
|
|
366
|
+
mockGetActionsForService.mockImplementation(service => {
|
|
367
|
+
if (service === 's3') {
|
|
368
|
+
return ['GetObject', 'GetBucket'];
|
|
369
|
+
}
|
|
370
|
+
if (service === 'ec2') {
|
|
371
|
+
return ['DescribeInstances', 'DescribeVolumes'];
|
|
372
|
+
}
|
|
373
|
+
return [];
|
|
374
|
+
});
|
|
375
|
+
//When expand is called with actionStrings and sort is false
|
|
376
|
+
const result = (0, expand_1.expandIamActions)(actionString, { sort: true });
|
|
377
|
+
//Then result should be an array of actions in the order they were expanded
|
|
378
|
+
expect(result).toEqual(['ec2:DescribeInstances', 'ec2:DescribeVolumes', 's3:GetBucket', 's3:GetObject']);
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
//# sourceMappingURL=expand.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.test.js","sourceRoot":"","sources":["../src/expand.test.ts"],"names":[],"mappings":";;AAAA,qCAA2C;AAE3C,sDAA6F;AAC7F,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CA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Ac,EAAE,cAAc,CAAC,CAAC,CAAA;QAC1G,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AAGJ,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./expand"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
|
package/dist/stdin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin.d.ts","sourceRoot":"","sources":["../src/stdin.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CA4B7E"}
|
package/dist/stdin.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readStdin = readStdin;
|
|
4
|
+
const process_1 = require("process");
|
|
5
|
+
/**
|
|
6
|
+
* Read from stdin until the stream ends, timeout, or an error occurs
|
|
7
|
+
*
|
|
8
|
+
* @returns the string input from stdin
|
|
9
|
+
*/
|
|
10
|
+
async function readStdin(readWait) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
// If the input is not a TTY, we are most likely receiving data from a pipe.
|
|
13
|
+
const definitelyReceivingData = !process.stdin.isTTY;
|
|
14
|
+
if (!readWait || readWait <= 0) {
|
|
15
|
+
readWait = definitelyReceivingData ? 10_000 : 20;
|
|
16
|
+
}
|
|
17
|
+
let data = '';
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
if (data.length === 0) {
|
|
20
|
+
resolve(data);
|
|
21
|
+
}
|
|
22
|
+
}, readWait);
|
|
23
|
+
process_1.stdin.on('data', (chunk) => {
|
|
24
|
+
data += chunk;
|
|
25
|
+
});
|
|
26
|
+
process_1.stdin.on('end', () => {
|
|
27
|
+
console.log('end');
|
|
28
|
+
resolve(data);
|
|
29
|
+
});
|
|
30
|
+
process_1.stdin.on('error', (err) => {
|
|
31
|
+
reject(err);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=stdin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin.js","sourceRoot":"","sources":["../src/stdin.ts"],"names":[],"mappings":";;AAMA,8BA4BC;AAlCD,qCAAgC;AAChC;;;;GAIG;AACI,KAAK,UAAU,SAAS,CAAC,QAA4B;IAC1D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,4EAA4E;QAC5E,MAAM,uBAAuB,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAA;QACpD,IAAG,CAAC,QAAQ,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;YAC9B,QAAQ,GAAG,uBAAuB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;QAClD,CAAC;QAED,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,UAAU,CAAC,GAAG,EAAE;YACd,IAAG,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACrB,OAAO,CAAC,IAAI,CAAC,CAAA;YACf,CAAC;QACH,CAAC,EAAE,QAAQ,CAAC,CAAA;QAEZ,eAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YACzB,IAAI,IAAI,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,eAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACnB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;YAClB,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,eAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloud-copilot/iam-expand",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Expand AWS IAM Actions with Wildcards",
|
|
5
|
+
"repository": "github:cloud-copilot/iam-expand",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/esm/index.js",
|
|
9
|
+
"require": "./dist/cjs/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"iam-expand": "./dist/cjs/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "npx tsc -p tsconfig.cjs.json && npx tsc -p tsconfig.esm.json && ./postbuild.sh",
|
|
17
|
+
"test": "npx vitest --run"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"AWS",
|
|
21
|
+
"IAM"
|
|
22
|
+
],
|
|
23
|
+
"author": "David Kerber <dave@cloudcopilot.io>",
|
|
24
|
+
"license": "GPL-3.0-or-later",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.5.0",
|
|
27
|
+
"typescript": "^5.5.4",
|
|
28
|
+
"vitest": "^2.0.5"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@cloud-copilot/iam-data": ">=0.2.0 <1.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/postbuild.sh
ADDED
package/src/cli.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { iamDataVersion } from "@cloud-copilot/iam-data";
|
|
4
|
+
import { convertOptions, parseStdInActions } from "./cli_utils.js";
|
|
5
|
+
import { expandIamActions, ExpandIamActionsOptions } from "./expand.js";
|
|
6
|
+
|
|
7
|
+
const commandName = 'iam-expand'
|
|
8
|
+
|
|
9
|
+
function expandAndPrint(actionStrings: string[], options: Partial<ExpandIamActionsOptions>) {
|
|
10
|
+
try {
|
|
11
|
+
const result = expandIamActions(actionStrings, options)
|
|
12
|
+
for (const action of result) {
|
|
13
|
+
console.log(action)
|
|
14
|
+
}
|
|
15
|
+
} catch (e: any) {
|
|
16
|
+
console.error(e.message)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function printUsage() {
|
|
22
|
+
console.log('No arguments provided or input from stdin.')
|
|
23
|
+
console.log('Usage:')
|
|
24
|
+
console.log(` ${commandName} [options] [action1] [action2] ...`)
|
|
25
|
+
console.log(` <input from stdout> | ${commandName} [options]`)
|
|
26
|
+
console.log('Action Expanding Options:')
|
|
27
|
+
console.log(' --distinct: Remove duplicate actions')
|
|
28
|
+
console.log(' --sort: Sort the actions')
|
|
29
|
+
console.log(' --expand-asterik: Expand the * action to all actions')
|
|
30
|
+
console.log(' --expand-service-asterik: Expand service:* to all actions for that service')
|
|
31
|
+
console.log(' --error-on-missing-service: Throw an error if a service is not found')
|
|
32
|
+
console.log(' --error-on-invalid-format: Throw an error if the action string is not in the correct format')
|
|
33
|
+
console.log(' --invalid-action-behavior: What to do when an invalid action is encountered:')
|
|
34
|
+
console.log(' --invalid-action-behavior=remove: Remove the invalid action')
|
|
35
|
+
console.log(' --invalid-action-behavior=include: Include the invalid action')
|
|
36
|
+
console.log(' --invalid-action-behavior=error: Throw an error if an invalid action is encountered')
|
|
37
|
+
console.log('CLI Behavior Options:')
|
|
38
|
+
console.log(' --show-data-version: Print the version of the iam-data package being used and exit')
|
|
39
|
+
console.log(' --read-wait-time: Millisenconds to wait for input from stdin before timing out.')
|
|
40
|
+
console.log(' Example: --read-wait-time=10_000')
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const args = process.argv.slice(2); // Ignore the first two elements
|
|
45
|
+
const actionStrings: string[] = []
|
|
46
|
+
const optionStrings: string[] = []
|
|
47
|
+
|
|
48
|
+
for (const arg of args) {
|
|
49
|
+
if(arg.startsWith('--')) {
|
|
50
|
+
optionStrings.push(arg)
|
|
51
|
+
} else {
|
|
52
|
+
actionStrings.push(arg)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function run() {
|
|
57
|
+
const options = convertOptions(optionStrings)
|
|
58
|
+
if(options.showDataVersion) {
|
|
59
|
+
console.log(`@cloud-copilot/iam-data version: ${iamDataVersion()}`)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if(actionStrings.length === 0) {
|
|
64
|
+
const otherActions = await parseStdInActions(options)
|
|
65
|
+
if(otherActions.length > 0 && options.expandAsterik) {
|
|
66
|
+
console.warn('Notice: --expand-asterik is not supported when reading from stdin, ignoring.')
|
|
67
|
+
}
|
|
68
|
+
actionStrings.push(...otherActions)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if(actionStrings.length > 0) {
|
|
72
|
+
expandAndPrint(actionStrings, options)
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
printUsage()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
run().catch((e) => {
|
|
80
|
+
console.error(e)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}).then(() => process.exit(0)).finally(() => {})
|