@jupiterone/integration-sdk-cli 17.3.0 → 17.4.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/dist/src/commands/generate-ingestion-sources-config.d.ts +4 -2
- package/dist/src/commands/generate-ingestion-sources-config.js +36 -0
- package/dist/src/commands/generate-ingestion-sources-config.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/commands/generate-ingestion-sources-config.test.ts +67 -0
- package/src/commands/generate-ingestion-sources-config.ts +46 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupiterone/integration-sdk-cli",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.4.0",
|
|
4
4
|
"description": "The SDK for developing JupiterOne integrations",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"plop": "plop --plopfile dist/src/generator/newIntegration.js"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@jupiterone/integration-sdk-core": "^17.
|
|
29
|
-
"@jupiterone/integration-sdk-runtime": "^17.
|
|
28
|
+
"@jupiterone/integration-sdk-core": "^17.4.0",
|
|
29
|
+
"@jupiterone/integration-sdk-runtime": "^17.4.0",
|
|
30
30
|
"chalk": "^4",
|
|
31
31
|
"commander": "^9.4.0",
|
|
32
32
|
"ejs": "^3.1.9",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jupiterone/data-model": "^0.62.0",
|
|
47
|
-
"@jupiterone/integration-sdk-private-test-utils": "^17.
|
|
47
|
+
"@jupiterone/integration-sdk-private-test-utils": "^17.4.0",
|
|
48
48
|
"@pollyjs/adapter-node-http": "^6.0.5",
|
|
49
49
|
"@pollyjs/core": "^6.0.5",
|
|
50
50
|
"@pollyjs/persister-fs": "^6.0.5",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@jupiterone/data-model": ">= 0.62.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "db92eb90fa36ad806f6d7fae77791380985a1568"
|
|
64
64
|
}
|
|
@@ -190,4 +190,71 @@ describe('#generateIngestionSourcesConfig', () => {
|
|
|
190
190
|
ingestionSourcesConfig[INGESTION_SOURCE_IDS.TEST_SOURCE],
|
|
191
191
|
).toBeUndefined();
|
|
192
192
|
});
|
|
193
|
+
|
|
194
|
+
it('should aggregate authorization from all steps into a top-level field', () => {
|
|
195
|
+
const integrationSteps: IntegrationStep<IntegrationInstanceConfig>[] = [
|
|
196
|
+
{
|
|
197
|
+
id: 'fetch-account',
|
|
198
|
+
name: 'Fetch Account',
|
|
199
|
+
entities: [],
|
|
200
|
+
relationships: [],
|
|
201
|
+
dependsOn: [],
|
|
202
|
+
executionHandler: jest.fn(),
|
|
203
|
+
authorization: {
|
|
204
|
+
permissions: ['account:read'],
|
|
205
|
+
apis: ['accounts.googleapis.com'],
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
id: 'fetch-repos',
|
|
210
|
+
name: 'Fetch Repos',
|
|
211
|
+
entities: [],
|
|
212
|
+
relationships: [],
|
|
213
|
+
dependsOn: ['fetch-account'],
|
|
214
|
+
ingestionSourceId: INGESTION_SOURCE_IDS.FETCH_REPOS,
|
|
215
|
+
executionHandler: jest.fn(),
|
|
216
|
+
authorization: {
|
|
217
|
+
permissions: ['repo:read', 'account:read'],
|
|
218
|
+
apis: ['repos.googleapis.com'],
|
|
219
|
+
oauthScopes: ['repo:read'],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: 'fetch-teams',
|
|
224
|
+
name: 'Fetch Teams',
|
|
225
|
+
entities: [],
|
|
226
|
+
relationships: [],
|
|
227
|
+
dependsOn: ['fetch-account'],
|
|
228
|
+
executionHandler: jest.fn(),
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
const ingestionSourcesConfig = generateIngestionSourcesConfig(
|
|
232
|
+
ingestionConfig,
|
|
233
|
+
integrationSteps,
|
|
234
|
+
);
|
|
235
|
+
expect(ingestionSourcesConfig.authorization).toEqual({
|
|
236
|
+
permissions: ['account:read', 'repo:read'],
|
|
237
|
+
apis: ['accounts.googleapis.com', 'repos.googleapis.com'],
|
|
238
|
+
oauthScopes: ['repo:read'],
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('should not include authorization when no steps have it', () => {
|
|
243
|
+
const integrationSteps: IntegrationStep<IntegrationInstanceConfig>[] = [
|
|
244
|
+
{
|
|
245
|
+
id: 'fetch-repos',
|
|
246
|
+
name: 'Fetch Repos',
|
|
247
|
+
entities: [],
|
|
248
|
+
relationships: [],
|
|
249
|
+
dependsOn: [],
|
|
250
|
+
ingestionSourceId: INGESTION_SOURCE_IDS.FETCH_REPOS,
|
|
251
|
+
executionHandler: jest.fn(),
|
|
252
|
+
},
|
|
253
|
+
];
|
|
254
|
+
const ingestionSourcesConfig = generateIngestionSourcesConfig(
|
|
255
|
+
ingestionConfig,
|
|
256
|
+
integrationSteps,
|
|
257
|
+
);
|
|
258
|
+
expect(ingestionSourcesConfig.authorization).toBeUndefined();
|
|
259
|
+
});
|
|
193
260
|
});
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
IntegrationIngestionConfigFieldMap,
|
|
4
4
|
IntegrationSourceId,
|
|
5
5
|
Step,
|
|
6
|
+
StepAuthorization,
|
|
6
7
|
StepExecutionContext,
|
|
7
8
|
StepMetadata,
|
|
8
9
|
} from '@jupiterone/integration-sdk-core';
|
|
@@ -70,7 +71,9 @@ export function generateIngestionSourcesConfigCommand() {
|
|
|
70
71
|
export type EnhancedIntegrationIngestionConfigFieldMap = Record<
|
|
71
72
|
IntegrationSourceId,
|
|
72
73
|
IntegrationIngestionConfigField & { childIngestionSources?: StepMetadata[] }
|
|
73
|
-
|
|
74
|
+
> & {
|
|
75
|
+
authorization?: StepAuthorization;
|
|
76
|
+
};
|
|
74
77
|
|
|
75
78
|
/**
|
|
76
79
|
* Generates an ingestionConfig with childIngestionSources taking into account
|
|
@@ -119,5 +122,47 @@ export function generateIngestionSourcesConfig<
|
|
|
119
122
|
log.warn(`The key ${key} does not exist in the ingestionConfig`);
|
|
120
123
|
}
|
|
121
124
|
});
|
|
125
|
+
|
|
126
|
+
const aggregatedAuth = aggregateAuthorization(integrationSteps);
|
|
127
|
+
if (aggregatedAuth) {
|
|
128
|
+
newIngestionConfig.authorization = aggregatedAuth;
|
|
129
|
+
}
|
|
130
|
+
|
|
122
131
|
return newIngestionConfig;
|
|
123
132
|
}
|
|
133
|
+
|
|
134
|
+
function aggregateAuthorization<
|
|
135
|
+
TStepExecutionContext extends StepExecutionContext,
|
|
136
|
+
>(steps: Step<TStepExecutionContext>[]): StepAuthorization | undefined {
|
|
137
|
+
const collected: Record<keyof StepAuthorization, Set<string>> = {
|
|
138
|
+
permissions: new Set(),
|
|
139
|
+
roles: new Set(),
|
|
140
|
+
oauthScopes: new Set(),
|
|
141
|
+
apis: new Set(),
|
|
142
|
+
endpoints: new Set(),
|
|
143
|
+
licenses: new Set(),
|
|
144
|
+
documentationLinks: new Set(),
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
for (const step of steps) {
|
|
148
|
+
if (!step.authorization) continue;
|
|
149
|
+
for (const [key, values] of Object.entries(step.authorization)) {
|
|
150
|
+
if (Array.isArray(values)) {
|
|
151
|
+
for (const v of values) {
|
|
152
|
+
if (v) collected[key as keyof StepAuthorization].add(v);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const auth: StepAuthorization = {};
|
|
159
|
+
let hasAny = false;
|
|
160
|
+
for (const [key, set] of Object.entries(collected)) {
|
|
161
|
+
if (set.size > 0) {
|
|
162
|
+
auth[key as keyof StepAuthorization] = [...set].sort();
|
|
163
|
+
hasAny = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return hasAny ? auth : undefined;
|
|
168
|
+
}
|