This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.ts
62 lines (56 loc) · 1.79 KB
/
config.ts
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
import {
IntegrationExecutionContext,
IntegrationValidationError,
IntegrationInstanceConfigFieldMap,
IntegrationInstanceConfig,
} from '@jupiterone/integration-sdk-core';
import { createAPIClient } from './client';
/**
* A type describing the configuration fields required to execute the
* integration for a specific account in the data provider.
*
* When executing the integration in a development environment, these values may
* be provided in a `.env` file with environment variables. For example:
*
* - `CLIENT_ID=123` becomes `instance.config.clientId = '123'`
* - `CLIENT_SECRET=abc` becomes `instance.config.clientSecret = 'abc'`
*
* Environment variables are NOT used when the integration is executing in a
* managed environment. For example, in JupiterOne, users configure
* `instance.config` in a UI.
*/
export const instanceConfigFields: IntegrationInstanceConfigFieldMap = {
clientId: {
type: 'string',
},
clientSecret: {
type: 'string',
mask: true,
},
};
/**
* Properties provided by the `IntegrationInstance.config`. This reflects the
* same properties defined by `instanceConfigFields`.
*/
export interface IntegrationConfig extends IntegrationInstanceConfig {
/**
* The provider API client ID used to authenticate requests.
*/
clientId: string;
/**
* The provider API client secret used to authenticate requests.
*/
clientSecret: string;
}
export async function validateInvocation(
context: IntegrationExecutionContext<IntegrationConfig>,
) {
const { config } = context.instance;
if (!config.clientId || !config.clientSecret) {
throw new IntegrationValidationError(
'Config requires all of {clientId, clientSecret}',
);
}
const apiClient = createAPIClient(config, context.logger);
await apiClient.verifyAuthentication();
}