This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71170e5
commit 0be1ffd
Showing
7 changed files
with
199 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
createDirectRelationship, | ||
createIntegrationEntity, | ||
Entity, | ||
parseTimePropertyValue, | ||
Relationship, | ||
RelationshipClass, | ||
} from '@jupiterone/integration-sdk-core'; | ||
|
||
import { Entities } from '../constants'; | ||
|
||
export function createLocalUserKey(id: string) { | ||
return `${Entities.LOCAL_USER._type}:${id}`; | ||
} | ||
|
||
export function createLocalUserEntity(user: any): Entity { | ||
const id = user.SID0?.toString(); | ||
return createIntegrationEntity({ | ||
entityData: { | ||
source: user, | ||
assign: { | ||
_key: createLocalUserKey(id), | ||
_type: Entities.LOCAL_USER._type, | ||
_class: Entities.LOCAL_USER._class, | ||
id: id, | ||
name: id, | ||
displayName: id, | ||
localPath: user.LocalPath0, | ||
createdOn: parseTimePropertyValue(user.TimeStamp), | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
export function createDeviceLocalUserRelationship( | ||
device: Entity, | ||
user: Entity, | ||
): Relationship { | ||
return createDirectRelationship({ | ||
_class: RelationshipClass.HAS, | ||
from: device, | ||
to: user, | ||
}); | ||
} |
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 { executeStepWithDependencies } from '@jupiterone/integration-sdk-testing'; | ||
import { buildStepTestConfigForStep } from '../../../test/config'; | ||
import { Steps } from '../constants'; | ||
import sql from 'mssql'; | ||
import { deviceRecords, localUserRecords } from '../../../test/mockData'; | ||
|
||
test('fetch-local-users', async () => { | ||
jest.mock('mssql'); | ||
sql.connect = jest | ||
.fn() | ||
.mockResolvedValueOnce({ | ||
query: jest.fn().mockResolvedValue({ | ||
recordset: deviceRecords, | ||
recordsets: [0, 0], | ||
}), | ||
close: jest.fn(), | ||
}) | ||
.mockReturnValueOnce({ | ||
query: jest.fn().mockResolvedValue({ | ||
recordset: localUserRecords, | ||
recordsets: [0, 0], | ||
}), | ||
close: jest.fn(), | ||
}); | ||
|
||
const stepConfig = buildStepTestConfigForStep(Steps.FETCH_LOCAL_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,48 @@ | ||
import { | ||
IntegrationStep, | ||
IntegrationStepExecutionContext, | ||
} from '@jupiterone/integration-sdk-core'; | ||
|
||
import { IntegrationConfig } from '../../config'; | ||
import { Steps, Entities, Relationships } from '../constants'; | ||
import { createMicrosoftConfigurationManagerClient } from '../../configuration-manager'; | ||
import { | ||
createDeviceLocalUserRelationship, | ||
createLocalUserEntity, | ||
} from './converters'; | ||
import { createDeviceKey } from '../devices/converters'; | ||
|
||
export const fetchLocalUserSteps: IntegrationStep<IntegrationConfig>[] = [ | ||
{ | ||
id: Steps.FETCH_LOCAL_USERS, | ||
name: 'Fetch-Local-Users', | ||
entities: [Entities.LOCAL_USER], | ||
relationships: [Relationships.DEVICE_HAS_LOCAL_USER], | ||
dependsOn: [Steps.FETCH_DEVICES], | ||
executionHandler: fetchLocalUsers, | ||
}, | ||
]; | ||
|
||
export async function fetchLocalUsers({ | ||
instance: { config }, | ||
jobState, | ||
logger, | ||
}: IntegrationStepExecutionContext<IntegrationConfig>) { | ||
const client = await createMicrosoftConfigurationManagerClient( | ||
config, | ||
logger, | ||
); | ||
|
||
await client.listLocalUsers(async (user: any) => { | ||
const userEntity = await jobState.addEntity(createLocalUserEntity(user)); | ||
|
||
const deviceEntity = await jobState.findEntity( | ||
createDeviceKey(user.ResourceID), | ||
); | ||
if (deviceEntity) { | ||
await jobState.addRelationship( | ||
createDeviceLocalUserRelationship(deviceEntity, userEntity), | ||
); | ||
} | ||
}); | ||
} |
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