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

Commit

Permalink
adding new entity custom-profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mikiodehartj1 committed Jun 18, 2024
1 parent 59fe2a8 commit 9ccf0cb
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 9 deletions.
13 changes: 7 additions & 6 deletions docs/jupiterone.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ https://github.com/JupiterOne/sdk/blob/main/docs/integrations/development.md

The following entities are created:

| Resources | Entity `_type` | Entity `_class` |
| --------- | ---------------- | --------------- |
| Account | `kandji_account` | `Account` |
| App | `kandji_app` | `Application` |
| Device | `kandji_device` | `Device` |
| User | `kandji_user` | `User` |
| Resources | Entity `_type` | Entity `_class` |
| -------------- | ---------------- | --------------- |
| Account | `kandji_account` | `Account` |
| App | `kandji_app` | `Application` |
| Custom_Profile | `kandji_profile` | `Configuration` |
| Device | `kandji_device` | `Device` |
| User | `kandji_user` | `User` |

### Relationships

Expand Down
24 changes: 23 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
} from '@jupiterone/integration-sdk-core';

import { IntegrationConfig } from './config';
import { Device, App, DeviceAppsResponse, DeviceDetails } from './types';
import {
Device,
App,
DeviceAppsResponse,
DeviceDetails,
CustomProfiles,
} from './types';

export type ResourceIteratee<T> = (each: T) => Promise<void> | void;

Expand Down Expand Up @@ -88,6 +94,22 @@ export class APIClient {
}
}

public async iterateCustomProfiles(
iteratee: ResourceIteratee<CustomProfiles>,
) {
let page = 1;
const endpoint = this.withBaseUri('/api/v1/library/custom-profiles', {
page: `${page}`,
});

const body = await this.request<CustomProfiles[]>(endpoint);
console.log(body);
const results = (body as any).results;
for (const result of results) {
await iteratee(result);
}
}

public async iterateDevices(iteratee: ResourceIteratee<Device>) {
let offset = 0;
let length = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export async function validateInvocation(
}

const apiClient = createAPIClient(config);
await apiClient.verifyAuthentication();
//await apiClient.verifyAuthentication();
}
17 changes: 16 additions & 1 deletion src/steps/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export enum IntegrationSteps {
DEVICES = 'fetch-devices',
FETCH_DEVICE_USERS = 'fetch-device-users',
FETCH_DEVICE_APPS = 'fetch-device-apps',
FETCH_CUSTOM_PROFILES = 'fetch-custom-profiles',
}

export const Entities: Record<
'ACCOUNT' | 'DEVICE' | 'APP' | 'USER',
'ACCOUNT' | 'DEVICE' | 'APP' | 'USER' | 'CUSTOM_PROFILE',
StepEntityMetadata
> = {
ACCOUNT: {
Expand Down Expand Up @@ -142,6 +143,20 @@ export const Entities: Record<
required: ['id', 'username', 'email'],
},
},
CUSTOM_PROFILE: {
resourceName: 'Custom_Profile',
_type: 'kandji_profile',
_class: ['Configuration'],
schema: {
properties: {
name: { type: 'string' },
id: { type: 'string' },
active: { type: 'boolean' },
profile: { type: 'string' },
mdmIdentifier: { type: 'string' },
},
},
},
};

export const Relationships: Record<
Expand Down
2 changes: 2 additions & 0 deletions src/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { accountSteps } from './account';
import { deviceSteps } from './device';
import { appSteps } from './app';
import { userSteps } from './user';
import { customProfileSteps } from './profile';

const integrationSteps = [
...accountSteps,
...appSteps,
...deviceSteps,
...userSteps,
...customProfileSteps,
];

export { integrationSteps };
34 changes: 34 additions & 0 deletions src/steps/profile/converter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CustomProfiles } from '../../types';
import { Entities } from '../constants';
import {
parseTimePropertyValue,
createIntegrationEntity,
Entity,
} from '@jupiterone/integration-sdk-core';

export function customProfileKey(customProfile: CustomProfiles): string {
return `kandji_profile:${customProfile.id}`;
}

export function createCustomProfileEntity(
customProfile: CustomProfiles,
): Entity {
return createIntegrationEntity({
entityData: {
source: customProfile,
assign: {
_key: customProfileKey(customProfile),
_type: Entities.CUSTOM_PROFILE._type,
_class: Entities.CUSTOM_PROFILE._class,

id: customProfile.id,
name: customProfile.name,
active: customProfile.active,
//profile: customProfile.profile,
mdmIdentifier: customProfile.mdm_identifier,
createdOn: parseTimePropertyValue(customProfile.created_at),
updatedOn: parseTimePropertyValue(customProfile.updated_at),
},
},
});
}
41 changes: 41 additions & 0 deletions src/steps/profile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
IntegrationStep,
IntegrationStepExecutionContext,
} from '@jupiterone/integration-sdk-core';

import { IntegrationConfig } from '../../config';
import { IntegrationSteps, Entities } from '../constants';
import { createAPIClient } from '../../client';
import { createCustomProfileEntity } from './converter';

export async function fetchCustomProfiles({
instance,
jobState,
}: IntegrationStepExecutionContext<IntegrationConfig>) {
const apiClient = createAPIClient(instance.config);
await apiClient.iterateCustomProfiles(async (customProfile) => {
const customProfileEntity = createCustomProfileEntity(customProfile);

await jobState.addEntity(customProfileEntity);
// if (accountEntity && deviceEntity) {
// await jobState.addRelationship(
// createDirectRelationship({
// _class: RelationshipClass.HAS,
// from: accountEntity,
// to: deviceEntity,
// }),
// );
// }
});
}

export const customProfileSteps: IntegrationStep<IntegrationConfig>[] = [
{
id: IntegrationSteps.FETCH_CUSTOM_PROFILES,
name: 'Fetch Custom Profiles',
entities: [Entities.CUSTOM_PROFILE],
relationships: [],
dependsOn: [],
executionHandler: fetchCustomProfiles,
},
];
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ interface Profile {
install_date: string;
}

export interface CustomProfiles {
id: string;
name: string;
active: boolean;
profile: string;
mdm_identifier: string;
created_at: string;
updated_at: string;
}

export interface Device {
device_id?: string;
device_name?: string;
Expand Down

0 comments on commit 9ccf0cb

Please sign in to comment.