This repository was 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
Add Device and Users Steps #2
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0a1c557
add gaxios dependency and update config
zemberdotnet 391659b
feat: add device and end user steps
zemberdotnet f51ab33
add retry logic to client
zemberdotnet 4824760
return empty promise in verifyAuth
zemberdotnet 4aa62cc
pr feedback
zemberdotnet d1c8a52
update test config env var
zemberdotnet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.