Skip to content

Commit

Permalink
Merge pull request #39 from JupiterOne/APP-15547
Browse files Browse the repository at this point in the history
[APP-15547] update to use new createIntegrationHelpers
  • Loading branch information
ryan-willis authored Jul 24, 2024
2 parents 4b8b5ef + 44bf279 commit bae172a
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 289 deletions.
90 changes: 0 additions & 90 deletions .github/workflows/peril.yml

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@
"@microsoft/microsoft-graph-types": "^2.24.0",
"node-fetch": "2"
},
"peerDependencies": {
"@jupiterone/integration-sdk-core": "^12.2.5"
},
"devDependencies": {
"@jupiterone/integration-sdk-core": "^12.2.5",
"@jupiterone/integration-sdk-dev-tools": "^12.2.5",
"@jupiterone/integration-sdk-testing": "^12.2.5",
"@jupiterone/integration-sdk-core": "^13.2.0",
"@jupiterone/integration-sdk-dev-tools": "^13.2.0",
"@jupiterone/integration-sdk-testing": "^13.2.0",
"@types/node": "^20.11.30",
"auto": "^10.36.5",
"@types/node-fetch": "^2.6.2"
Expand Down
44 changes: 14 additions & 30 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import {
StepMappedRelationshipMetadata,
StepRelationshipMetadata,
} from '@jupiterone/integration-sdk-core';
import {
ACCOUNT_ENTITY,
ENDPOINT_ENTITY,
LOGON_USER_ENTITY,
MACHINE_ENTITY,
USER_ENTITY,
VULNERABILITY_ENTITY,
} from './entities';

export const Steps: Record<
| 'FETCH_ACCOUNT'
Expand Down Expand Up @@ -38,36 +46,12 @@ export const Entities: Record<
'ACCOUNT' | 'MACHINE' | 'LOGON_USER' | 'USER' | 'VULNERABILITY' | 'ENDPOINT',
StepEntityMetadata
> = {
ACCOUNT: {
resourceName: 'Account',
_type: 'microsoft_defender_account',
_class: ['Account'],
},
MACHINE: {
resourceName: 'Machine',
_type: 'microsoft_defender_machine',
_class: ['HostAgent'],
},
LOGON_USER: {
resourceName: 'Logon User',
_type: 'microsoft_defender_logon_user',
_class: ['User'],
},
USER: {
resourceName: 'User',
_type: 'microsoft_defender_user',
_class: ['User'],
},
VULNERABILITY: {
resourceName: 'Vulnerability',
_type: 'microsoft_defender_vulnerability',
_class: ['Finding'],
},
ENDPOINT: {
resourceName: 'Device/Machine/Host',
_type: 'user_endpoint',
_class: ['Device'],
},
ACCOUNT: ACCOUNT_ENTITY,
MACHINE: MACHINE_ENTITY,
LOGON_USER: LOGON_USER_ENTITY,
USER: USER_ENTITY,
VULNERABILITY: VULNERABILITY_ENTITY,
ENDPOINT: ENDPOINT_ENTITY,
};

export const Relationships: Record<
Expand Down
125 changes: 125 additions & 0 deletions src/entities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { SchemaType } from '@jupiterone/integration-sdk-core';
import { createEntityType, createEntityMetadata } from './helpers';

const StringNullUndefined = SchemaType.Optional(
SchemaType.Union([SchemaType.String(), SchemaType.Null()]),
);

export const [ACCOUNT_ENTITY, assignAccount] = createEntityMetadata({
resourceName: 'Account',
_class: ['Account'],
_type: createEntityType('account'),
description: 'A Microsoft Defender Endpoint account',
schema: SchemaType.Object({
organizationName: StringNullUndefined,
defaultDomain: SchemaType.Optional(SchemaType.String()),
verifiedDomains: SchemaType.Optional(SchemaType.Array(SchemaType.String())),
}),
});

export const [MACHINE_ENTITY, assignMachine] = createEntityMetadata({
resourceName: 'Machine',
_class: ['HostAgent'],
_type: createEntityType('machine'),
description: 'A Microsoft Defender Endpoint machine',
schema: SchemaType.Object({
firstSeenOn: SchemaType.Optional(SchemaType.Number()),
agentVersion: SchemaType.String(),
defenderAvStatus: SchemaType.String(),
riskScore: SchemaType.String(),
computerDnsName: SchemaType.String(),
rbacGroupId: SchemaType.Number(),
rbacGroupName: SchemaType.Union([SchemaType.String(), SchemaType.Null()]),
machineTags: SchemaType.Array(SchemaType.String()),
onboardingStatus: SchemaType.String(),
managedBy: SchemaType.String(),
managedByStatus: SchemaType.String(),
ipAddress: SchemaType.Array(SchemaType.String()),
macAddress: SchemaType.Array(SchemaType.String()),
aadDeviceId: SchemaType.Union([SchemaType.String(), SchemaType.Null()]),
}),
});

export const [LOGON_USER_ENTITY, assignLogonUser] = createEntityMetadata({
resourceName: 'Logon User',
_class: ['User'],
_type: createEntityType('logon_user'),
description: 'A Microsoft Defender Endpoint Logon User',
schema: SchemaType.Object({
domain: StringNullUndefined,
firstSeenOn: SchemaType.Optional(SchemaType.Number()),
lastSeenOn: SchemaType.Optional(SchemaType.Number()),
logonTypes: SchemaType.String(),
}),
});

export const [USER_ENTITY, assignUser] = createEntityMetadata({
resourceName: 'User',
_class: ['User'],
_type: createEntityType('user'),
description: 'A Microsoft Defender Endpoint user',
schema: SchemaType.Object({
businessPhones: SchemaType.Optional(SchemaType.Array(SchemaType.String())),
givenName: StringNullUndefined,
jobTitle: StringNullUndefined,
mail: StringNullUndefined,
mobilePhone: StringNullUndefined,
officeLocation: StringNullUndefined,
preferredLanguage: StringNullUndefined,
surname: StringNullUndefined,
userPrincipalName: StringNullUndefined,
}),
});

export const [VULNERABILITY_ENTITY, assignVulnerability] = createEntityMetadata(
{
resourceName: 'Vulnerability',
_class: ['Finding'],
_type: createEntityType('vulnerability'),
description: 'A Microsoft Defender Endpoint vulnerability',
schema: SchemaType.Object({
id: SchemaType.String(),
publishedOn: SchemaType.Optional(SchemaType.Number()),
exposedMachines: SchemaType.Number(),
blocking: SchemaType.Boolean(),
}),
},
);

export const [ENDPOINT_ENTITY, assignEndpoint] = createEntityMetadata({
resourceName: 'Device/Machine/Host',
_class: ['Device'],
_type: 'user_endpoint',
description: 'A Microsoft Defender Endpoint entity',
schema: SchemaType.Object({
computerDnsName: SchemaType.String(),
firstSeenOn: SchemaType.Optional(SchemaType.Number()),
osPlatform: SchemaType.String(),
osProcessor: SchemaType.Optional(SchemaType.String()),
lastIpAddress: SchemaType.String(),
lastExternalIpAddress: SchemaType.String(),
agentVersion: SchemaType.String(),
osBuild: SchemaType.Union([SchemaType.Number(), SchemaType.Null()]),
healthStatus: SchemaType.String(),
deviceValue: SchemaType.String(),
rbacGroupId: SchemaType.Number(),
rbacGroupName: SchemaType.Union([SchemaType.String(), SchemaType.Null()]),
riskScore: SchemaType.String(),
exposureLevel: SchemaType.String(),
isAadJoined: SchemaType.Union([SchemaType.Boolean(), SchemaType.Null()]),
aadDeviceId: SchemaType.Union([SchemaType.String(), SchemaType.Null()]),
machineTags: SchemaType.Array(SchemaType.String()),
defenderAvStatus: SchemaType.String(),
onboardingStatus: SchemaType.String(),
osArchitecture: SchemaType.String(),
managedBy: SchemaType.String(),
managedByStatus: SchemaType.String(),
vmId: SchemaType.Optional(SchemaType.String()),
cloudProvider: SchemaType.Optional(SchemaType.String()),
resourceId: SchemaType.Optional(SchemaType.String()),
subscriptionId: SchemaType.Optional(SchemaType.String()),
ipAddresses: SchemaType.Array(SchemaType.String()),
ipAddress: SchemaType.Array(SchemaType.String()),
macAddress: SchemaType.Array(SchemaType.String()),
}),
});
8 changes: 8 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createIntegrationHelpers } from '@jupiterone/integration-sdk-core';
import { typeboxClassSchemaMap } from '@jupiterone/data-model';

export const { createEntityType, createEntityMetadata } =
createIntegrationHelpers({
integrationName: 'microsoft_defender',
classSchemaMap: typeboxClassSchemaMap,
});
2 changes: 2 additions & 0 deletions src/steps/active-directory/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ exports[`#fetchAccount 1`] = `
"id": "19ae0f99-6fc6-444b-bd54-97504efc66ad",
"name": "JupiterOne Azure Integration Development",
"organizationName": "JupiterOne Azure Integration Development",
"vendor": "Microsoft Defender",
"verifiedDomains": [
"j1AzureIntegrationDev.onmicrosoft.com",
],
Expand Down Expand Up @@ -153,6 +154,7 @@ exports[`#fetchAccount 1`] = `
"id": "19ae0f99-6fc6-444b-bd54-97504efc66ad",
"name": "JupiterOne Azure Integration Development",
"organizationName": "JupiterOne Azure Integration Development",
"vendor": "Microsoft Defender",
"verifiedDomains": [
"j1AzureIntegrationDev.onmicrosoft.com",
],
Expand Down
27 changes: 3 additions & 24 deletions src/steps/active-directory/converters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,17 @@ import {
getMockOrganization,
getMockUser,
} from '../../../test/mocks';
import { ACCOUNT_ENTITY, USER_ENTITY } from '../../entities';

test('#createAccountEntityWithOrganization', () => {
expect(
createAccountEntityWithOrganization(
getMockInstance(),
getMockOrganization(),
),
).toMatchGraphObjectSchema({
_class: ['Account'],
schema: {
properties: {
_type: { const: 'microsoft_defender_account' },
_rawData: {
type: 'array',
items: { type: 'object' },
},
},
},
});
).toMatchGraphObjectSchema(ACCOUNT_ENTITY);
});

test('#createUserEntity', () => {
expect(createUserEntity(getMockUser())).toMatchGraphObjectSchema({
_class: ['User'],
schema: {
properties: {
_type: { const: 'microsoft_defender_user' },
_rawData: {
type: 'array',
items: { type: 'object' },
},
},
},
});
expect(createUserEntity(getMockUser())).toMatchGraphObjectSchema(USER_ENTITY);
});
Loading

0 comments on commit bae172a

Please sign in to comment.