Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from JupiterOne/fix-account-set-data
Browse files Browse the repository at this point in the history
Fix account set data
  • Loading branch information
ndowmon authored Aug 27, 2021
2 parents 9a3ec4b + f1629da commit 0118d2f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ and this project adheres to

## [Unreleased]

## [2.0.1] - 221-08-27

### Fixed

- Fixed bug where `accountEntity` and `protectionServiceEntity` singletons were
not added to `jobState.setData()`

## [2.0.0] - 2021-08-26

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupiterone/graph-crowdstrike",
"version": "2.0.0",
"version": "2.0.1",
"description": "A template for JupiterOne graph converters.",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down
35 changes: 20 additions & 15 deletions src/steps/getAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import {
JobState,
RelationshipClass,
Step,
} from "@jupiterone/integration-sdk-core";
import { Entities, Relationships, SetDataKeys, StepIds } from "../constants";
} from '@jupiterone/integration-sdk-core';
import { Entities, Relationships, SetDataKeys, StepIds } from '../constants';
import {
createAccountEntity,
createProtectionServiceEntity,
} from "../jupiterone/converters";
import { CrowdStrikeIntegrationInstanceConfig } from "../types";
} from '../jupiterone/converters';
import { CrowdStrikeIntegrationInstanceConfig } from '../types';

export async function getAccountEntityFromJobState(
jobState: JobState,
): Promise<Entity> {
const accountEntity = await jobState.findEntity(SetDataKeys.ACCOUNT_ENTITY);
const accountEntity = await jobState.getData<Entity>(
SetDataKeys.ACCOUNT_ENTITY,
);

if (!accountEntity) {
throw new IntegrationError({
code: "MISSING_ACCOUNT_ENTITY",
code: 'MISSING_ACCOUNT_ENTITY',
message: `The ${Entities.ACCOUNT._type} entity could not be found in the job state.`,
});
}
Expand All @@ -31,30 +33,33 @@ export async function getAccountEntityFromJobState(
export async function getProtectionServiceEntityFromJobState(
jobState: JobState,
): Promise<Entity> {
const protectionServiceEntity = await jobState.findEntity(
const protectionServiceEntity = await jobState.getData<Entity>(
SetDataKeys.PROTECTION_SERVICE_ENTITY,
);

if (!protectionServiceEntity) {
throw new IntegrationError({
code: "MISSING_PROTECTION_SERVICE_ENTITY",
code: 'MISSING_PROTECTION_SERVICE_ENTITY',
message: `The ${Entities.PROTECTION_SERVICE._type} entity could not be found in the job state.`,
});
}
return protectionServiceEntity;
}

export async function getAccount(
context: IntegrationStepExecutionContext<
CrowdStrikeIntegrationInstanceConfig
>,
context: IntegrationStepExecutionContext<CrowdStrikeIntegrationInstanceConfig>,
): Promise<void> {
const { instance, jobState } = context;
const accountEntity = await jobState.addEntity(createAccountEntity(instance));
await jobState.setData(SetDataKeys.ACCOUNT_ENTITY, accountEntity);

const protectionServiceEntity = await jobState.addEntity(
createProtectionServiceEntity(instance),
);
await jobState.setData(
SetDataKeys.PROTECTION_SERVICE_ENTITY,
protectionServiceEntity,
);

await jobState.addRelationship(
createDirectRelationship({
Expand All @@ -65,11 +70,11 @@ export async function getAccount(
);
}

export const getAccountStep: Step<IntegrationStepExecutionContext<
CrowdStrikeIntegrationInstanceConfig
>> = {
export const getAccountStep: Step<
IntegrationStepExecutionContext<CrowdStrikeIntegrationInstanceConfig>
> = {
id: StepIds.ACCOUNT,
name: "Get Account",
name: 'Get Account',
entities: [Entities.ACCOUNT, Entities.PROTECTION_SERVICE],
relationships: [Relationships.ACCOUNT_HAS_PROTECTION_SERVICE],
executionHandler: getAccount,
Expand Down

0 comments on commit 0118d2f

Please sign in to comment.