Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Avalos Ribas authored and Gonzalo Avalos Ribas committed Nov 16, 2023
1 parent 377a6db commit 1ce50bb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docs/jupiterone.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The following relationships are created:
| `airwatch_account` | **MANAGES** | `user_endpoint` |
| `airwatch_group` | **HAS** | `airwatch_group` |
| `airwatch_group` | **HAS** | `airwatch_user` |
| `user_endpoint` | **IMPLEMENTS** | `airwatch_profile` |
| `user_endpoint` | **INSTALLED** | `airwatch_profile` |
| `user_endpoint` | **HAS** | `device_user` |

<!--
Expand Down
22 changes: 12 additions & 10 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
AirWatchOrganizationGroup,
AirWatchOrganizationGroupChild,
AirWatchOrganizationGroupsResponse,
AirwatchDeviceProfileResponse,
AirwatchProfile,
AirwatchProfileDetails,
AirwatchProfileResponse,
DevicesForProfile,
ResourceIteratee,
} from './types';

Expand Down Expand Up @@ -174,15 +174,17 @@ export default class AirWatchClient {
await iteratee(profile);
}
}
public async fetchProfilesOfDevice(
deviceId: string,
): Promise<AirwatchDeviceProfileResponse> {
const response: AirwatchDeviceProfileResponse = await this.makeRequest(
`/mdm/devices/${deviceId}/profiles`,
'GET',
undefined,
'1',
);

public async fetchDevicesForProfile(
profileUuid: string,
): Promise<DevicesForProfile> {
const response: DevicesForProfile =
await this.makeRequest<DevicesForProfile>(
`/mdm/profiles/${profileUuid}/devices`,
'GET',
undefined,
'1',
);
return response;
}

Expand Down
31 changes: 9 additions & 22 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,33 +143,20 @@ export interface ConfiguredPayload {
name: string;
display_key: string;
}
export interface AirwatchDeviceProfileResponse {
DeviceId: DeviceID;
DeviceProfiles: DeviceProfile[];
Page: number;
PageSize: number;
Total: number;
}

export interface DeviceID {
Name: string;
Uuid: string;
export interface DevicesForProfile {
profileAssignedDevices: ProfileAssignedDevice[];
AdditionalInfo: AdditionalInfo;
TotalResults: number;
}

export interface DeviceProfile {
Status: number;
Name: string;
Description: string;
LocationGroupId: object;
CurrentVersion: number;
AssignmentType: number;
InstalledProfileVersion: number;
Id: ID;
Uuid: string;
export interface AdditionalInfo {
Links: any[];
}

export interface ID {
Value: number;
export interface ProfileAssignedDevice {
Links: any[];
uuid: string;
}

export interface AirwatchProfileDetails {
Expand Down
35 changes: 19 additions & 16 deletions src/steps/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export const PROFILE_ENTITY_CLASS = ['Configuration'];

export const ACCOUNT_ORGANIZATION_GROUP_RELATIONSHIP_CLASS =
RelationshipClass.HAS;
export const ACCOUNT_ORGANIZATION_GROUP_RELATIONSHIP_TYPE = generateRelationshipType(
ACCOUNT_ORGANIZATION_GROUP_RELATIONSHIP_CLASS,
ACCOUNT_ENTITY_TYPE,
ORGANIZATION_GROUP_ENTITY_TYPE,
);
export const ACCOUNT_ORGANIZATION_GROUP_RELATIONSHIP_TYPE =
generateRelationshipType(
ACCOUNT_ORGANIZATION_GROUP_RELATIONSHIP_CLASS,
ACCOUNT_ENTITY_TYPE,
ORGANIZATION_GROUP_ENTITY_TYPE,
);

export const ACCOUNT_DEVICE_RELATIONSHIP_CLASS = RelationshipClass.MANAGES;
export const ACCOUNT_DEVICE_RELATIONSHIP_TYPE = generateRelationshipType(
Expand All @@ -45,11 +46,12 @@ export const ACCOUNT_DEVICE_RELATIONSHIP_TYPE = generateRelationshipType(

export const ORGANIZATION_GROUP_ADMIN_RELATIONSHIP_CLASS =
RelationshipClass.HAS;
export const ORGANIZATION_GROUP_ADMIN_RELATIONSHIP_TYPE = generateRelationshipType(
ORGANIZATION_GROUP_ADMIN_RELATIONSHIP_CLASS,
ORGANIZATION_GROUP_ENTITY_TYPE,
ADMIN_ENTITY_TYPE,
);
export const ORGANIZATION_GROUP_ADMIN_RELATIONSHIP_TYPE =
generateRelationshipType(
ORGANIZATION_GROUP_ADMIN_RELATIONSHIP_CLASS,
ORGANIZATION_GROUP_ENTITY_TYPE,
ADMIN_ENTITY_TYPE,
);

export const ORGANIZATION_GROUP_RELATIONSHIP_CLASS = RelationshipClass.HAS;
export const ORGANIZATION_GROUP_RELATIONSHIP_TYPE = generateRelationshipType(
Expand All @@ -60,13 +62,14 @@ export const ORGANIZATION_GROUP_RELATIONSHIP_TYPE = generateRelationshipType(

export const USER_ENDPOINT_DEVICE_USER_RELATIONSHIP_CLASS =
RelationshipClass.HAS;
export const USER_ENDPOINT_DEVICE_USER_RELATIONSHIP_TYPE = generateRelationshipType(
USER_ENDPOINT_DEVICE_USER_RELATIONSHIP_CLASS,
DEVICE_ENTITY_TYPE,
DEVICE_USER_ENTITY_TYPE,
);
export const USER_ENDPOINT_DEVICE_USER_RELATIONSHIP_TYPE =
generateRelationshipType(
USER_ENDPOINT_DEVICE_USER_RELATIONSHIP_CLASS,
DEVICE_ENTITY_TYPE,
DEVICE_USER_ENTITY_TYPE,
);

export const DEVICE_PROFILE_REATIONSHIP_CLASS = RelationshipClass.IMPLEMENTS;
export const DEVICE_PROFILE_REATIONSHIP_CLASS = RelationshipClass.INSTALLED;
export const DEVICE_PROFILE_REATIONSHIP_TYPE = generateRelationshipType(
DEVICE_PROFILE_REATIONSHIP_CLASS,
DEVICE_ENTITY_TYPE,
Expand Down
43 changes: 17 additions & 26 deletions src/steps/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,37 @@ export async function buildDeviceProfileRelationships({
}: IntegrationStepExecutionContext<IntegrationConfig>) {
const apiClient = createAPIClient(instance.config);
await jobState.iterateEntities(
{ _type: DEVICE_ENTITY_TYPE },
async (deviceEntity) => {
{ _type: PROFILE_ENTITY_TYPE },
async (profileEntity) => {
try {
const response = await apiClient.fetchProfilesOfDevice(
deviceEntity.deviceId! as string,
const response = await apiClient.fetchDevicesForProfile(
profileEntity._key,
);
// we don't have a way to test this - I'm using the model provided by the provider
// but its not working. Let's try logging.
for (const profile of response.DeviceProfiles) {
let profileUUid: string | undefined;
if (profile.Uuid) {
profileUUid = profile.Uuid;
} else if (profile.Id.Value) {
const details = await apiClient.fetchProfilesDetails(
profile.Id.Value?.toString(),
);
logger.info(
{ detailKeys: Object.keys(details.general) },
'TEMP - detail keys.',
);
profileUUid = details.general.uuid;
}
// Let's try logging.
for (const device of response.profileAssignedDevices) {
logger.info(
{ deviceKeys: Object.keys(device) },
'TEMP - Keys of device',
);
if (
response.DeviceId.Uuid &&
profileUUid &&
jobState.hasKey(response.DeviceId.Uuid) &&
jobState.hasKey(profileUUid)
device.uuid &&
profileEntity._key &&
jobState.hasKey(device.uuid) &&
jobState.hasKey(profileEntity._key)
) {
await jobState.addRelationship(
createDirectRelationship({
_class: DEVICE_PROFILE_REATIONSHIP_CLASS,
fromKey: response.DeviceId.Uuid,
fromKey: device.uuid,
fromType: DEVICE_ENTITY_TYPE,
toKey: profileUUid,
toKey: profileEntity._key,
toType: PROFILE_ENTITY_TYPE,
}),
);
} else {
logger.info(
{ fromKey: response.DeviceId.Uuid, toKey: profileUUid },
{ fromKey: device.uuid, toKey: profileEntity._key },
'Could not create a relationship',
);
}
Expand Down

0 comments on commit 1ce50bb

Please sign in to comment.