-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathinstance.ts
More file actions
64 lines (56 loc) · 2.22 KB
/
Copy pathinstance.ts
File metadata and controls
64 lines (56 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {
IntegrationInstance,
IntegrationInvocationConfig,
} from '@jupiterone/integration-sdk-core';
import { loadConfigFromEnvironmentVariables } from './config';
export const LOCAL_INTEGRATION_INSTANCE: IntegrationInstance = {
id: 'local-integration-instance',
accountId: 'Your account',
name: 'Local Integration',
integrationDefinitionId: 'local-integration-definition',
description: 'A generated integration instance for local execution',
config: {},
} as const;
/**
* Parses the DISABLED_INGESTION_SOURCES environment variable.
* Expects a comma-separated list of ingestion source IDs, e.g. "permissions,vulnerabilities"
*/
function parseDisabledIngestionSourcesFromEnv():
| { ingestionSourceId: string }[]
| undefined {
const raw = process.env.DISABLED_INGESTION_SOURCES;
if (!raw) return undefined;
const sourceIds = raw
.split(',')
.map((id) => id.trim())
.filter((id) => id.length > 0);
if (sourceIds.length === 0) return undefined;
return sourceIds.map((ingestionSourceId) => ({ ingestionSourceId }));
}
export function createIntegrationInstanceForLocalExecution(
config: IntegrationInvocationConfig,
): IntegrationInstance {
return {
id: process.env.INTEGRATION_INSTANCE_ID || LOCAL_INTEGRATION_INSTANCE.id,
name:
process.env.INTEGRATION_INSTANCE_NAME || LOCAL_INTEGRATION_INSTANCE.name,
integrationDefinitionId:
process.env.INTEGRATION_INSTANCE_INTEGRATION_DEFINITION_ID ||
LOCAL_INTEGRATION_INSTANCE.integrationDefinitionId,
description:
process.env.INTEGRATION_INSTANCE_DESCRIPTION ||
LOCAL_INTEGRATION_INSTANCE.description,
accountId:
process.env.INTEGRATION_INSTANCE_ACCOUNT_ID ||
process.env.JUPITERONE_LOCAL_INTEGRATION_INSTANCE_ACCOUNT_ID ||
LOCAL_INTEGRATION_INSTANCE.accountId,
// Always call `loadConfigFromEnvironmentVariables` so that the implicit
// agent-configuration fields (caCertificate / disableTlsVerification) are
// picked up from the environment even when an integration does not declare
// any `instanceConfigFields` of its own.
config: loadConfigFromEnvironmentVariables(
config.instanceConfigFields ?? {},
),
disabledSources: parseDisabledIngestionSourcesFromEnv(),
};
}