This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
generated from JupiterOne-Archives/integration-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from JupiterOne/int-add-device-users
Add Device and Users Steps
- Loading branch information
Showing
19 changed files
with
1,730 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
CLIENT_ID= | ||
CLIENT_SECRET= | ||
BASE_URL= | ||
DEVICE_42_USERNAME= | ||
PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
312 changes: 312 additions & 0 deletions
312
src/steps/devices/__recordings__/fetch-devices_1249334749/recording.har
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createIntegrationEntity } from '@jupiterone/integration-sdk-core'; | ||
import { Device42Device } from '../../types'; | ||
import { Entities } from '../constants'; | ||
|
||
export function createDeviceEntity(device: Device42Device) { | ||
return createIntegrationEntity({ | ||
entityData: { | ||
source: device, | ||
assign: { | ||
_key: `device42_device:${device.id}`, | ||
_type: Entities.DEVICE._type, | ||
_class: Entities.DEVICE._class, | ||
id: device.id.toString(), | ||
name: device.name, | ||
type: device.type, | ||
serial: device.serial_no || undefined, | ||
ipAddress: device.ip_addresses.map((o) => o.ip), | ||
macAddress: device.mac_addresses.map((o) => o.mac), | ||
active: device.in_service, | ||
inService: device.in_service, | ||
uuid: device.uuid || undefined, | ||
osName: device.os, | ||
osVersion: device.osver, | ||
serviceLevel: device.service_level, | ||
category: device.type, | ||
make: device.manufacturer, | ||
model: device.hw_model, | ||
deviceId: device.uuid, | ||
hostname: null, | ||
}, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { executeStepWithDependencies } from '@jupiterone/integration-sdk-testing'; | ||
import { buildStepTestConfigForStep } from '../../../test/config'; | ||
import { Recording, setupProjectRecording } from '../../../test/recording'; | ||
import { Steps } from '../constants'; | ||
|
||
// pagination takes some time for this test | ||
jest.setTimeout(100_000); | ||
// See test/README.md for details | ||
let recording: Recording; | ||
afterEach(async () => { | ||
await recording.stop(); | ||
}); | ||
|
||
test('fetch-devices', async () => { | ||
recording = setupProjectRecording({ | ||
directory: __dirname, | ||
name: 'fetch-devices', | ||
}); | ||
|
||
const stepConfig = buildStepTestConfigForStep(Steps.DEVICES); | ||
const stepResult = await executeStepWithDependencies(stepConfig); | ||
expect(stepResult.collectedEntities.length).toBeGreaterThan(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
IntegrationStep, | ||
IntegrationStepExecutionContext, | ||
} from '@jupiterone/integration-sdk-core'; | ||
import { createAPIClient } from '../../client'; | ||
import { IntegrationConfig } from '../../config'; | ||
import { Entities, Steps } from '../constants'; | ||
import { createDeviceEntity } from './converter'; | ||
|
||
export const devicesSteps: IntegrationStep<IntegrationConfig>[] = [ | ||
{ | ||
id: Steps.DEVICES, | ||
name: 'Fetch Devices', | ||
entities: [Entities.DEVICE], | ||
relationships: [], | ||
dependsOn: [], | ||
executionHandler: fetchDevices, | ||
}, | ||
]; | ||
|
||
async function fetchDevices({ | ||
instance, | ||
jobState, | ||
}: IntegrationStepExecutionContext<IntegrationConfig>) { | ||
const client = createAPIClient(instance.config); | ||
await client.iterateDevices(async (d) => { | ||
await jobState.addEntity(createDeviceEntity(d)); | ||
}); | ||
} |
739 changes: 739 additions & 0 deletions
739
src/steps/end-users/__recordings__/fetch-end-users_2245482038/recording.har
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createIntegrationEntity } from '@jupiterone/integration-sdk-core'; | ||
import { Device42EndUser } from '../../types'; | ||
import { Entities } from '../constants'; | ||
|
||
export function createEndUserEntity(endUser: Device42EndUser) { | ||
return createIntegrationEntity({ | ||
entityData: { | ||
source: endUser, | ||
assign: { | ||
_key: `device42_enduser:${endUser.id}`, | ||
_class: Entities.END_USER._class, | ||
_type: Entities.END_USER._type, | ||
id: endUser.id.toString(), | ||
email: endUser.email || undefined, | ||
contact: endUser.contact || undefined, | ||
domain: endUser.domain || undefined, | ||
name: endUser.name, | ||
activeDirectoryUsername: endUser.adusername || undefined, | ||
username: endUser.adusername || undefined, | ||
notes: undefined, | ||
}, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { executeStepWithDependencies } from '@jupiterone/integration-sdk-testing'; | ||
import { buildStepTestConfigForStep } from '../../../test/config'; | ||
import { Recording, setupProjectRecording } from '../../../test/recording'; | ||
import { Steps } from '../constants'; | ||
|
||
// See test/README.md for details | ||
let recording: Recording; | ||
afterEach(async () => { | ||
await recording.stop(); | ||
}); | ||
|
||
test('fetch-end-users', async () => { | ||
recording = setupProjectRecording({ | ||
directory: __dirname, | ||
name: 'fetch-end-users', | ||
}); | ||
|
||
const stepConfig = buildStepTestConfigForStep(Steps.END_USERS); | ||
const stepResult = await executeStepWithDependencies(stepConfig); | ||
expect(stepResult).toMatchStepMetadata(stepConfig); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
IntegrationStep, | ||
IntegrationStepExecutionContext, | ||
} from '@jupiterone/integration-sdk-core'; | ||
import { createAPIClient } from '../../client'; | ||
import { IntegrationConfig } from '../../config'; | ||
import { Entities, Steps } from '../constants'; | ||
import { createEndUserEntity } from './converters'; | ||
|
||
export const endUsersSteps: IntegrationStep<IntegrationConfig>[] = [ | ||
{ | ||
id: Steps.END_USERS, | ||
name: 'Fetch End Users', | ||
entities: [Entities.END_USER], | ||
relationships: [], | ||
dependsOn: [], | ||
executionHandler: fetchEndUsers, | ||
}, | ||
]; | ||
|
||
async function fetchEndUsers({ | ||
instance, | ||
jobState, | ||
}: IntegrationStepExecutionContext<IntegrationConfig>) { | ||
const client = createAPIClient(instance.config); | ||
await client.iterateEndUsers(async (e) => { | ||
await jobState.addEntity(createEndUserEntity(e)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
const integrationSteps = []; | ||
import { devicesSteps } from './devices'; | ||
import { endUsersSteps } from './end-users'; | ||
|
||
const integrationSteps = [...endUsersSteps, ...devicesSteps]; | ||
|
||
export { integrationSteps }; |
Oops, something went wrong.