@cloud-copilot/iam-expand 0.1.9 → 0.1.11
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 +3 -3
- package/dist/cjs/cli.js +2 -2
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/cli_utils.d.ts +1 -1
- package/dist/cjs/cli_utils.d.ts.map +1 -1
- package/dist/cjs/cli_utils.js +1 -1
- package/dist/cjs/cli_utils.js.map +1 -1
- package/dist/cjs/expand_file.d.ts +3 -2
- package/dist/cjs/expand_file.d.ts.map +1 -1
- package/dist/cjs/expand_file.js +14 -15
- package/dist/cjs/expand_file.js.map +1 -1
- package/dist/esm/cli.js +2 -2
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/cli_utils.d.ts +1 -1
- package/dist/esm/cli_utils.d.ts.map +1 -1
- package/dist/esm/cli_utils.js +1 -1
- package/dist/esm/cli_utils.js.map +1 -1
- package/dist/esm/expand_file.d.ts +3 -2
- package/dist/esm/expand_file.d.ts.map +1 -1
- package/dist/esm/expand_file.js +14 -15
- package/dist/esm/expand_file.js.map +1 -1
- package/package.json +5 -2
- package/examples/README.md +0 -3
- package/examples/download-and-expand-authorization-details.sh +0 -8
- package/examples/download-and-expand-policies.sh +0 -22
- package/postbuild.sh +0 -13
- package/src/cli.ts +0 -94
- package/src/cli_utils.test.ts +0 -147
- package/src/cli_utils.ts +0 -84
- package/src/expand.test.ts +0 -489
- package/src/expand.ts +0 -166
- package/src/expand_file.test.ts +0 -184
- package/src/expand_file.ts +0 -39
- package/src/index.ts +0 -1
- package/src/stdin.ts +0 -34
- package/tsconfig.cjs.json +0 -11
- package/tsconfig.esm.json +0 -14
- package/tsconfig.json +0 -22
package/src/expand_file.test.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { beforeEach } from "node:test";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { expandIamActions } from "./expand.js";
|
|
4
|
-
import { expandJsonDocument } from "./expand_file.js";
|
|
5
|
-
|
|
6
|
-
vi.mock('./expand.js')
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
vi.resetAllMocks()
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
describe('expand_file', () => {
|
|
13
|
-
describe('expandJsonDocument', () => {
|
|
14
|
-
it('should return a document without actions as is', async () => {
|
|
15
|
-
// Given a document without actions
|
|
16
|
-
const document = {
|
|
17
|
-
"key": "value",
|
|
18
|
-
"key2": ["value1", "value2"]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// When the document is expanded
|
|
22
|
-
const result = await expandJsonDocument({}, document)
|
|
23
|
-
|
|
24
|
-
// Then the document should be returned as is
|
|
25
|
-
expect(result).toEqual(document)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('should expand a string action', async () => {
|
|
29
|
-
// Given a document with an action
|
|
30
|
-
const document = {
|
|
31
|
-
a: {
|
|
32
|
-
b: {
|
|
33
|
-
"Action": "s3:Get*"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
vi.mocked(expandIamActions).mockResolvedValue(["s3:GetObject", "s3:GetBucket"])
|
|
38
|
-
|
|
39
|
-
// When the document is expanded
|
|
40
|
-
const result = await expandJsonDocument({}, document)
|
|
41
|
-
|
|
42
|
-
// Then the action should be expanded
|
|
43
|
-
const expected = JSON.parse(JSON.stringify(document))
|
|
44
|
-
expected.a.b.Action = ["s3:GetObject", "s3:GetBucket"]
|
|
45
|
-
expect(result).toEqual(expected)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('should expand an array of string actions', async () => {
|
|
49
|
-
// Given a document with an action
|
|
50
|
-
const document = {
|
|
51
|
-
a: {
|
|
52
|
-
b: {
|
|
53
|
-
"Action": ["s3:Get*", "s3:Put*"]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
|
|
58
|
-
return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// When the document is expanded
|
|
62
|
-
const result = await expandJsonDocument({}, document)
|
|
63
|
-
|
|
64
|
-
// Then the action should be expanded
|
|
65
|
-
const expected = JSON.parse(JSON.stringify(document))
|
|
66
|
-
expected.a.b.Action = ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
|
|
67
|
-
expect(result).toEqual(expected)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('should not expand an Action if it is an object', async () => {
|
|
71
|
-
// Given a document with an action
|
|
72
|
-
const document = {
|
|
73
|
-
a: {
|
|
74
|
-
b: {
|
|
75
|
-
"Action": {
|
|
76
|
-
"key": "value"
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// When the document is expanded
|
|
83
|
-
const result = await expandJsonDocument({}, document)
|
|
84
|
-
|
|
85
|
-
// Then the document should be returned as is
|
|
86
|
-
expect(result).toEqual(document)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('should not expand an Action if it is an array of numbers', async () => {
|
|
90
|
-
// Given a document with an action
|
|
91
|
-
const document = {
|
|
92
|
-
a: {
|
|
93
|
-
b: {
|
|
94
|
-
"Action": [1, 2, 3]
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// When the document is expanded
|
|
100
|
-
const result = await expandJsonDocument({}, document)
|
|
101
|
-
|
|
102
|
-
// Then the document should be returned as is
|
|
103
|
-
expect(result).toEqual(document)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('should expand a string NotAction', async () => {
|
|
107
|
-
// Given a document with an action
|
|
108
|
-
const document = {
|
|
109
|
-
a: {
|
|
110
|
-
b: {
|
|
111
|
-
"NotAction": "s3:Get*"
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
vi.mocked(expandIamActions).mockResolvedValue(["s3:GetObject", "s3:GetBucket"])
|
|
116
|
-
|
|
117
|
-
// When the document is expanded
|
|
118
|
-
const result = await expandJsonDocument({}, document)
|
|
119
|
-
|
|
120
|
-
// Then the action should be expanded
|
|
121
|
-
const expected = JSON.parse(JSON.stringify(document))
|
|
122
|
-
expected.a.b.NotAction = ["s3:GetObject", "s3:GetBucket"]
|
|
123
|
-
expect(result).toEqual(expected)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('should expand an array of string NotActions', async () => {
|
|
127
|
-
// Given a document with an action
|
|
128
|
-
const document = {
|
|
129
|
-
a: {
|
|
130
|
-
b: {
|
|
131
|
-
"NotAction": ["s3:Get*", "s3:Put*"]
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
vi.mocked(expandIamActions).mockImplementation(async (actions, options) =>{
|
|
136
|
-
return ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
// When the document is expanded
|
|
140
|
-
const result = await expandJsonDocument({}, document)
|
|
141
|
-
|
|
142
|
-
// Then the action should be expanded
|
|
143
|
-
const expected = JSON.parse(JSON.stringify(document))
|
|
144
|
-
expected.a.b.NotAction = ["s3:GetObject", "s3:GetBucket", "s3:PutObject", "s3:PutBucket"]
|
|
145
|
-
expect(result).toEqual(expected)
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it('should not expand a NotAction if it is an object', async () => {
|
|
149
|
-
// Given a document with an action
|
|
150
|
-
const document = {
|
|
151
|
-
a: {
|
|
152
|
-
b: {
|
|
153
|
-
"NotAction": {
|
|
154
|
-
"key": "value"
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// When the document is expanded
|
|
161
|
-
const result = await expandJsonDocument({}, document)
|
|
162
|
-
|
|
163
|
-
// Then the document should be returned as is
|
|
164
|
-
expect(result).toEqual(document)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('should not expand a NotAction if it is an array of numbers', async () => {
|
|
168
|
-
// Given a document with an action
|
|
169
|
-
const document = {
|
|
170
|
-
a: {
|
|
171
|
-
b: {
|
|
172
|
-
"NotAction": [1, 2, 3]
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// When the document is expanded
|
|
178
|
-
const result = await expandJsonDocument({}, document)
|
|
179
|
-
|
|
180
|
-
// Then the document should be returned as is
|
|
181
|
-
expect(result).toEqual(document)
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
})
|
package/src/expand_file.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { expandIamActions, ExpandIamActionsOptions } from "./expand.js"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Takes any JSON document and expands any Action found in the document
|
|
5
|
-
*
|
|
6
|
-
* @param options the options to use when expanding the actions
|
|
7
|
-
* @param document the JSON document to expand
|
|
8
|
-
* @param key the key of the current node in the document
|
|
9
|
-
* @returns the expanded JSON document
|
|
10
|
-
*/
|
|
11
|
-
export async function expandJsonDocument(options: Partial<ExpandIamActionsOptions>, document: any, key?: string): Promise<any> {
|
|
12
|
-
if(key === 'Action' || key === 'NotAction') {
|
|
13
|
-
if(typeof document === 'string') {
|
|
14
|
-
return await expandIamActions(document, options)
|
|
15
|
-
}
|
|
16
|
-
if(Array.isArray(document) && document.length > 0 && typeof document[0] === 'string') {
|
|
17
|
-
const value = await expandIamActions(document, {...options})
|
|
18
|
-
return value
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if(Array.isArray(document)) {
|
|
23
|
-
return Promise.all(document.map(async (item) => {
|
|
24
|
-
return expandJsonDocument(options, item)
|
|
25
|
-
}))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if(typeof document === 'object') {
|
|
29
|
-
const keys = Object.keys(document)
|
|
30
|
-
const newObject: any = {}
|
|
31
|
-
for(const key of keys) {
|
|
32
|
-
const value = document[key]
|
|
33
|
-
newObject[key] = await expandJsonDocument(options, value, key)
|
|
34
|
-
}
|
|
35
|
-
return newObject
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return document
|
|
39
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './expand.js';
|
package/src/stdin.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { stdin } from 'process';
|
|
2
|
-
/**
|
|
3
|
-
* Read from stdin until the stream ends, timeout, or an error occurs
|
|
4
|
-
*
|
|
5
|
-
* @returns the string input from stdin
|
|
6
|
-
*/
|
|
7
|
-
export async function readStdin(readWait: number | undefined): Promise<string> {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
// If the input is not a TTY, we are most likely receiving data from a pipe.
|
|
10
|
-
const definitelyReceivingData = !process.stdin.isTTY
|
|
11
|
-
if(!readWait || readWait <= 0) {
|
|
12
|
-
readWait = definitelyReceivingData ? 10_000 : 20
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let data = '';
|
|
16
|
-
setTimeout(() => {
|
|
17
|
-
if(data.length === 0) {
|
|
18
|
-
resolve(data)
|
|
19
|
-
}
|
|
20
|
-
}, readWait)
|
|
21
|
-
|
|
22
|
-
stdin.on('data', (chunk) => {
|
|
23
|
-
data += chunk;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
stdin.on('end', () => {
|
|
27
|
-
resolve(data);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
stdin.on('error', (err) => {
|
|
31
|
-
reject(err);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
package/tsconfig.cjs.json
DELETED
package/tsconfig.esm.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"target": "es2022",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"strict": true,
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"declarationMap": true,
|
|
11
|
-
"lib": ["es2023", "DOM"],
|
|
12
|
-
"noUnusedLocals": false,
|
|
13
|
-
"noUnusedParameters": false,
|
|
14
|
-
"noImplicitReturns": true,
|
|
15
|
-
"noFallthroughCasesInSwitch": false,
|
|
16
|
-
"experimentalDecorators": true,
|
|
17
|
-
"emitDecoratorMetadata": true,
|
|
18
|
-
"esModuleInterop": false,
|
|
19
|
-
"forceConsistentCasingInFileNames": true,
|
|
20
|
-
},
|
|
21
|
-
"exclude": ["tests", "test", "dist", "bin", "**/bin", "**/dist", "node_modules", "cdk.out"]
|
|
22
|
-
}
|