/
account.ts
121 lines (107 loc) · 3.07 KB
/
account.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
createDirectRelationship,
createIntegrationEntity,
IntegrationInfoEventName,
IntegrationStep,
IntegrationStepExecutionContext,
RelationshipClass,
} from '@jupiterone/integration-sdk-core';
import { OrgOktaSupportSettingsObj } from '@okta/okta-sdk-nodejs';
import { createAPIClient } from '../client';
import { IntegrationConfig } from '../config';
import { createAccountEntity } from '../converters/account';
import {
createMFAServiceEntity,
createSSOServiceEntity,
} from '../converters/service';
import { accountFlagged } from '../okta/createOktaClient';
import getOktaAccountInfo from '../util/getOktaAccountInfo';
import { StepAnnouncer } from '../util/runningTimer';
import {
DATA_ACCOUNT_ENTITY,
Entities,
Relationships,
Steps,
} from './constants';
export async function fetchAccountDetails({
jobState,
instance,
logger,
}: IntegrationStepExecutionContext<IntegrationConfig>) {
let stepAnnouncer;
if (accountFlagged) {
stepAnnouncer = new StepAnnouncer(Steps.ACCOUNT, logger);
}
const apiClient = createAPIClient(instance.config, logger);
const oktaAccountInfo = getOktaAccountInfo({
name: instance.name,
config: instance.config,
});
let oktaSupportInfo: OrgOktaSupportSettingsObj | undefined = undefined;
try {
oktaSupportInfo = await apiClient.getSupportInfo();
} catch (err) {
logger.info(`Unable to query Okta Support Info due to ERROR: `, err);
logger.publishInfoEvent({
name: IntegrationInfoEventName.Info,
description: `INFO: Unable to query Okta Support Information. The okta_account.supportEnabled value cannot be set.`,
});
}
const accountProperties = createAccountEntity(
instance.config,
oktaAccountInfo,
oktaSupportInfo,
);
const accountEntity = await jobState.addEntity(
createIntegrationEntity({
entityData: {
source: oktaAccountInfo,
assign: accountProperties,
},
}),
);
await jobState.setData(DATA_ACCOUNT_ENTITY, accountEntity);
const ssoServiceEntity = await jobState.addEntity(
createIntegrationEntity({
entityData: {
source: {},
assign: createSSOServiceEntity(accountProperties),
},
}),
);
await jobState.addRelationship(
createDirectRelationship({
_class: RelationshipClass.HAS,
from: accountEntity,
to: ssoServiceEntity,
}),
);
const mfaServiceEntity = await jobState.addEntity(
createIntegrationEntity({
entityData: {
source: {},
assign: createMFAServiceEntity(accountProperties),
},
}),
);
await jobState.addRelationship(
createDirectRelationship({
_class: RelationshipClass.HAS,
from: accountEntity,
to: mfaServiceEntity,
}),
);
if (accountFlagged) {
stepAnnouncer.finish();
}
}
export const accountSteps: IntegrationStep<IntegrationConfig>[] = [
{
id: Steps.ACCOUNT,
name: 'Fetch Account Details',
entities: [Entities.ACCOUNT, Entities.SERVICE],
relationships: [Relationships.ACCOUNT_HAS_SERVICE],
dependsOn: [],
executionHandler: fetchAccountDetails,
},
];