2021-10-04 20:26:10 +00:00
|
|
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
2021-08-03 19:42:48 +00:00
|
|
|
import sendRequest from "services";
|
2022-04-22 16:45:35 +00:00
|
|
|
import endpoints from "utilities/endpoints";
|
2022-10-10 18:07:47 +00:00
|
|
|
import { IHost, HostStatus } from "interfaces/host";
|
2022-08-31 21:18:32 +00:00
|
|
|
import {
|
|
|
|
buildQueryStringFromParams,
|
|
|
|
getLabelParam,
|
|
|
|
reconcileMutuallyExclusiveHostParams,
|
2023-03-15 22:44:48 +00:00
|
|
|
reconcileMutuallyInclusiveHostParams,
|
2022-08-31 21:18:32 +00:00
|
|
|
} from "utilities/url";
|
2022-12-16 21:12:11 +00:00
|
|
|
import { ISelectedPlatform } from "interfaces/platform";
|
2023-03-31 17:40:14 +00:00
|
|
|
import { ISoftware } from "interfaces/software";
|
2023-04-27 15:10:41 +00:00
|
|
|
import {
|
|
|
|
FileVaultProfileStatus,
|
|
|
|
BootstrapPackageStatus,
|
|
|
|
IMdmSolution,
|
|
|
|
} from "interfaces/mdm";
|
2023-03-31 17:40:14 +00:00
|
|
|
import { IMunkiIssuesAggregate } from "interfaces/macadmins";
|
2021-08-03 19:42:48 +00:00
|
|
|
|
2021-09-30 19:32:06 +00:00
|
|
|
export interface ISortOption {
|
|
|
|
key: string;
|
2021-08-03 19:42:48 +00:00
|
|
|
direction: string;
|
|
|
|
}
|
|
|
|
|
2023-03-31 17:40:14 +00:00
|
|
|
export interface ILoadHostsResponse {
|
|
|
|
hosts: IHost[];
|
|
|
|
software: ISoftware;
|
|
|
|
munki_issue: IMunkiIssuesAggregate;
|
|
|
|
mobile_device_management_solution: IMdmSolution;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ILoadHostsQueryKey extends ILoadHostsOptions {
|
|
|
|
scope: "hosts";
|
|
|
|
}
|
|
|
|
|
2023-03-14 17:05:43 +00:00
|
|
|
export type MacSettingsStatusQueryParam = "latest" | "pending" | "failing";
|
|
|
|
|
2021-12-27 23:57:15 +00:00
|
|
|
export interface ILoadHostsOptions {
|
2021-09-30 19:32:06 +00:00
|
|
|
page?: number;
|
|
|
|
perPage?: number;
|
|
|
|
selectedLabels?: string[];
|
|
|
|
globalFilter?: string;
|
|
|
|
sortBy?: ISortOption[];
|
|
|
|
teamId?: number;
|
|
|
|
policyId?: number;
|
|
|
|
policyResponse?: string;
|
2023-03-14 17:05:43 +00:00
|
|
|
macSettingsStatus?: MacSettingsStatusQueryParam;
|
2021-10-18 15:01:01 +00:00
|
|
|
softwareId?: number;
|
2022-10-10 18:07:47 +00:00
|
|
|
status?: HostStatus;
|
2022-08-15 22:47:07 +00:00
|
|
|
mdmId?: number;
|
|
|
|
mdmEnrollmentStatus?: string;
|
2022-10-14 20:21:30 +00:00
|
|
|
lowDiskSpaceHosts?: number;
|
2022-08-31 21:18:32 +00:00
|
|
|
osId?: number;
|
|
|
|
osName?: string;
|
|
|
|
osVersion?: string;
|
2022-09-02 22:05:07 +00:00
|
|
|
munkiIssueId?: number;
|
2022-05-23 19:27:30 +00:00
|
|
|
device_mapping?: boolean;
|
2022-05-19 22:21:06 +00:00
|
|
|
columns?: string;
|
2022-05-24 03:46:40 +00:00
|
|
|
visibleColumns?: string;
|
2023-04-26 18:31:38 +00:00
|
|
|
diskEncryptionStatus?: FileVaultProfileStatus;
|
2023-04-27 15:10:41 +00:00
|
|
|
bootstrapPackageStatus?: BootstrapPackageStatus;
|
2021-08-03 19:42:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 23:48:48 +00:00
|
|
|
export interface IExportHostsOptions {
|
|
|
|
sortBy: ISortOption[];
|
|
|
|
page?: number;
|
|
|
|
perPage?: number;
|
|
|
|
selectedLabels?: string[];
|
|
|
|
globalFilter?: string;
|
|
|
|
teamId?: number;
|
|
|
|
policyId?: number;
|
|
|
|
policyResponse?: string;
|
2023-03-14 17:05:43 +00:00
|
|
|
macSettingsStatus?: MacSettingsStatusQueryParam;
|
2022-05-25 23:48:48 +00:00
|
|
|
softwareId?: number;
|
2022-10-10 18:07:47 +00:00
|
|
|
status?: HostStatus;
|
2022-08-15 22:47:07 +00:00
|
|
|
mdmId?: number;
|
2022-09-02 22:05:07 +00:00
|
|
|
munkiIssueId?: number;
|
2022-08-15 22:47:07 +00:00
|
|
|
mdmEnrollmentStatus?: string;
|
2022-10-14 20:21:30 +00:00
|
|
|
lowDiskSpaceHosts?: number;
|
2022-08-31 21:18:32 +00:00
|
|
|
osId?: number;
|
|
|
|
osName?: string;
|
|
|
|
osVersion?: string;
|
2022-05-25 23:48:48 +00:00
|
|
|
device_mapping?: boolean;
|
|
|
|
columns?: string;
|
|
|
|
visibleColumns?: string;
|
2023-04-26 18:31:38 +00:00
|
|
|
diskEncryptionStatus?: FileVaultProfileStatus;
|
2022-05-25 23:48:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 18:07:47 +00:00
|
|
|
export interface IActionByFilter {
|
|
|
|
teamId: number | null;
|
|
|
|
query: string;
|
|
|
|
status: string;
|
|
|
|
labelId?: number;
|
|
|
|
}
|
|
|
|
|
2021-12-27 23:57:15 +00:00
|
|
|
export type ILoadHostDetailsExtension = "device_mapping" | "macadmins";
|
|
|
|
|
2022-08-09 11:25:49 +00:00
|
|
|
const LABEL_PREFIX = "labels/";
|
|
|
|
|
|
|
|
const getLabel = (selectedLabels?: string[]) => {
|
|
|
|
if (selectedLabels === undefined) return undefined;
|
|
|
|
return selectedLabels.find((filter) => filter.includes(LABEL_PREFIX));
|
|
|
|
};
|
|
|
|
|
|
|
|
const getHostEndpoint = (selectedLabels?: string[]) => {
|
|
|
|
const { HOSTS, LABEL_HOSTS } = endpoints;
|
2022-08-31 21:18:32 +00:00
|
|
|
if (selectedLabels === undefined) return HOSTS;
|
2022-08-09 11:25:49 +00:00
|
|
|
|
|
|
|
const label = getLabel(selectedLabels);
|
|
|
|
if (label) {
|
|
|
|
const labelId = label.substr(LABEL_PREFIX.length);
|
|
|
|
return LABEL_HOSTS(parseInt(labelId, 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
return HOSTS;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getSortParams = (sortOptions?: ISortOption[]) => {
|
|
|
|
if (sortOptions === undefined || sortOptions.length === 0) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const sortItem = sortOptions[0];
|
|
|
|
return {
|
|
|
|
order_key: sortItem.key,
|
|
|
|
order_direction: sortItem.direction,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-12-16 21:12:11 +00:00
|
|
|
const createMdmParams = (platform?: ISelectedPlatform, teamId?: number) => {
|
|
|
|
if (platform === "all") {
|
|
|
|
return buildQueryStringFromParams({ team_id: teamId });
|
|
|
|
}
|
|
|
|
|
|
|
|
return buildQueryStringFromParams({ platform, team_id: teamId });
|
|
|
|
};
|
|
|
|
|
2021-08-03 19:42:48 +00:00
|
|
|
export default {
|
|
|
|
destroy: (host: IHost) => {
|
|
|
|
const { HOSTS } = endpoints;
|
|
|
|
const path = `${HOSTS}/${host.id}`;
|
|
|
|
|
|
|
|
return sendRequest("DELETE", path);
|
|
|
|
},
|
2021-10-04 20:20:56 +00:00
|
|
|
destroyBulk: (hostIds: number[]) => {
|
|
|
|
const { HOSTS_DELETE } = endpoints;
|
|
|
|
|
|
|
|
return sendRequest("POST", HOSTS_DELETE, { ids: hostIds });
|
|
|
|
},
|
2022-10-10 18:07:47 +00:00
|
|
|
destroyByFilter: ({ teamId, query, status, labelId }: IActionByFilter) => {
|
2021-10-04 20:20:56 +00:00
|
|
|
const { HOSTS_DELETE } = endpoints;
|
|
|
|
return sendRequest("POST", HOSTS_DELETE, {
|
|
|
|
filters: {
|
|
|
|
query,
|
|
|
|
status,
|
|
|
|
label_id: labelId,
|
|
|
|
team_id: teamId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2022-05-25 23:48:48 +00:00
|
|
|
exportHosts: (options: IExportHostsOptions) => {
|
|
|
|
const sortBy = options.sortBy;
|
2022-04-04 18:53:14 +00:00
|
|
|
const selectedLabels = options?.selectedLabels || [];
|
|
|
|
const globalFilter = options?.globalFilter || "";
|
2022-08-31 21:18:32 +00:00
|
|
|
const teamId = options?.teamId;
|
|
|
|
const policyId = options?.policyId;
|
2022-05-25 23:48:48 +00:00
|
|
|
const policyResponse = options?.policyResponse || "passing";
|
2022-08-31 21:18:32 +00:00
|
|
|
const softwareId = options?.softwareId;
|
2023-03-14 17:05:43 +00:00
|
|
|
const macSettingsStatus = options?.macSettingsStatus;
|
2022-10-10 18:07:47 +00:00
|
|
|
const status = options?.status;
|
2022-08-31 21:18:32 +00:00
|
|
|
const mdmId = options?.mdmId;
|
|
|
|
const mdmEnrollmentStatus = options?.mdmEnrollmentStatus;
|
2022-10-14 20:21:30 +00:00
|
|
|
const lowDiskSpaceHosts = options?.lowDiskSpaceHosts;
|
2022-08-31 21:18:32 +00:00
|
|
|
const visibleColumns = options?.visibleColumns;
|
|
|
|
const label = getLabelParam(selectedLabels);
|
2022-09-02 22:05:07 +00:00
|
|
|
const munkiIssueId = options?.munkiIssueId;
|
2023-04-05 18:34:30 +00:00
|
|
|
const diskEncryptionStatus = options?.diskEncryptionStatus;
|
2022-04-04 18:53:14 +00:00
|
|
|
|
2022-05-25 23:48:48 +00:00
|
|
|
if (!sortBy.length) {
|
|
|
|
throw Error("sortBy is a required field.");
|
2022-04-04 18:53:14 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 21:18:32 +00:00
|
|
|
const queryParams = {
|
|
|
|
order_key: sortBy[0].key,
|
|
|
|
order_direction: sortBy[0].direction,
|
|
|
|
query: globalFilter,
|
2023-03-15 22:44:48 +00:00
|
|
|
...reconcileMutuallyInclusiveHostParams({ teamId, macSettingsStatus }),
|
2022-10-14 20:21:30 +00:00
|
|
|
...reconcileMutuallyExclusiveHostParams({
|
2022-08-31 21:18:32 +00:00
|
|
|
label,
|
|
|
|
policyId,
|
|
|
|
policyResponse,
|
|
|
|
mdmId,
|
|
|
|
mdmEnrollmentStatus,
|
2022-09-02 22:05:07 +00:00
|
|
|
munkiIssueId,
|
2022-10-14 20:21:30 +00:00
|
|
|
softwareId,
|
|
|
|
lowDiskSpaceHosts,
|
2023-04-05 18:34:30 +00:00
|
|
|
diskEncryptionStatus,
|
2022-10-14 20:21:30 +00:00
|
|
|
}),
|
2022-10-10 18:07:47 +00:00
|
|
|
status,
|
2022-08-31 21:18:32 +00:00
|
|
|
label_id: label,
|
|
|
|
columns: visibleColumns,
|
|
|
|
format: "csv",
|
|
|
|
};
|
2022-05-24 03:46:40 +00:00
|
|
|
|
2022-08-31 21:18:32 +00:00
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
|
|
|
const endpoint = endpoints.HOSTS_REPORT;
|
|
|
|
const path = `${endpoint}?${queryString}`;
|
2022-04-04 18:53:14 +00:00
|
|
|
|
|
|
|
return sendRequest("GET", path);
|
|
|
|
},
|
2022-08-09 11:25:49 +00:00
|
|
|
loadHosts: ({
|
|
|
|
page = 0,
|
2022-10-18 15:11:19 +00:00
|
|
|
perPage = 100,
|
2022-08-09 11:25:49 +00:00
|
|
|
globalFilter,
|
|
|
|
teamId,
|
|
|
|
policyId,
|
|
|
|
policyResponse = "passing",
|
2023-03-14 17:05:43 +00:00
|
|
|
macSettingsStatus,
|
2022-08-09 11:25:49 +00:00
|
|
|
softwareId,
|
2022-10-10 18:07:47 +00:00
|
|
|
status,
|
2022-08-15 22:47:07 +00:00
|
|
|
mdmId,
|
|
|
|
mdmEnrollmentStatus,
|
2022-09-02 22:05:07 +00:00
|
|
|
munkiIssueId,
|
2022-10-14 20:21:30 +00:00
|
|
|
lowDiskSpaceHosts,
|
2022-08-31 21:18:32 +00:00
|
|
|
osId,
|
|
|
|
osName,
|
|
|
|
osVersion,
|
2022-08-09 11:25:49 +00:00
|
|
|
device_mapping,
|
|
|
|
selectedLabels,
|
|
|
|
sortBy,
|
2023-04-05 18:34:30 +00:00
|
|
|
diskEncryptionStatus,
|
2023-04-27 15:10:41 +00:00
|
|
|
bootstrapPackageStatus,
|
2023-03-31 17:40:14 +00:00
|
|
|
}: ILoadHostsOptions): Promise<ILoadHostsResponse> => {
|
2022-08-09 11:25:49 +00:00
|
|
|
const label = getLabel(selectedLabels);
|
|
|
|
const sortParams = getSortParams(sortBy);
|
|
|
|
|
|
|
|
const queryParams = {
|
|
|
|
page,
|
|
|
|
per_page: perPage,
|
|
|
|
query: globalFilter,
|
|
|
|
device_mapping,
|
|
|
|
order_key: sortParams.order_key,
|
|
|
|
order_direction: sortParams.order_direction,
|
2022-10-10 18:07:47 +00:00
|
|
|
status,
|
2023-03-15 22:44:48 +00:00
|
|
|
...reconcileMutuallyInclusiveHostParams({
|
|
|
|
teamId,
|
|
|
|
macSettingsStatus,
|
|
|
|
}),
|
2022-10-14 20:21:30 +00:00
|
|
|
...reconcileMutuallyExclusiveHostParams({
|
2022-08-15 22:47:07 +00:00
|
|
|
label,
|
|
|
|
policyId,
|
2022-08-31 21:18:32 +00:00
|
|
|
policyResponse,
|
2022-08-22 19:34:00 +00:00
|
|
|
mdmId,
|
|
|
|
mdmEnrollmentStatus,
|
2022-09-02 22:05:07 +00:00
|
|
|
munkiIssueId,
|
2022-08-31 21:18:32 +00:00
|
|
|
softwareId,
|
2022-10-14 20:21:30 +00:00
|
|
|
lowDiskSpaceHosts,
|
2022-08-31 21:18:32 +00:00
|
|
|
osId,
|
|
|
|
osName,
|
2022-10-14 20:21:30 +00:00
|
|
|
osVersion,
|
2023-04-05 18:34:30 +00:00
|
|
|
diskEncryptionStatus,
|
2023-04-27 15:10:41 +00:00
|
|
|
bootstrapPackageStatus,
|
2022-10-14 20:21:30 +00:00
|
|
|
}),
|
2022-08-09 11:25:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
2022-08-15 22:47:07 +00:00
|
|
|
|
2022-08-09 11:25:49 +00:00
|
|
|
const endpoint = getHostEndpoint(selectedLabels);
|
|
|
|
const path = `${endpoint}?${queryString}`;
|
2021-08-03 19:42:48 +00:00
|
|
|
return sendRequest("GET", path);
|
|
|
|
},
|
2021-12-27 23:57:15 +00:00
|
|
|
loadHostDetails: (hostID: number) => {
|
|
|
|
const { HOSTS } = endpoints;
|
|
|
|
const path = `${HOSTS}/${hostID}`;
|
|
|
|
|
|
|
|
return sendRequest("GET", path);
|
|
|
|
},
|
|
|
|
loadHostDetailsExtension: (
|
|
|
|
hostID: number,
|
|
|
|
extension: ILoadHostDetailsExtension
|
|
|
|
) => {
|
|
|
|
const { HOSTS } = endpoints;
|
|
|
|
const path = `${HOSTS}/${hostID}/${extension}`;
|
|
|
|
|
|
|
|
return sendRequest("GET", path);
|
|
|
|
},
|
|
|
|
refetch: (host: IHost) => {
|
|
|
|
const { HOSTS } = endpoints;
|
|
|
|
const path = `${HOSTS}/${host.id}/refetch`;
|
|
|
|
|
|
|
|
return sendRequest("POST", path);
|
|
|
|
},
|
2021-09-10 19:06:37 +00:00
|
|
|
search: (searchText: string) => {
|
|
|
|
const { HOSTS } = endpoints;
|
|
|
|
const path = `${HOSTS}?query=${searchText}`;
|
|
|
|
|
|
|
|
return sendRequest("GET", path);
|
|
|
|
},
|
2021-08-03 19:42:48 +00:00
|
|
|
transferToTeam: (teamId: number | null, hostIds: number[]) => {
|
|
|
|
const { HOSTS_TRANSFER } = endpoints;
|
|
|
|
|
|
|
|
return sendRequest("POST", HOSTS_TRANSFER, {
|
|
|
|
team_id: teamId,
|
|
|
|
hosts: hostIds,
|
|
|
|
});
|
|
|
|
},
|
2021-08-30 23:02:53 +00:00
|
|
|
|
|
|
|
// TODO confirm interplay with policies
|
2022-10-10 18:07:47 +00:00
|
|
|
transferToTeamByFilter: ({
|
|
|
|
teamId,
|
|
|
|
query,
|
|
|
|
status,
|
|
|
|
labelId,
|
|
|
|
}: IActionByFilter) => {
|
2021-08-03 19:42:48 +00:00
|
|
|
const { HOSTS_TRANSFER_BY_FILTER } = endpoints;
|
|
|
|
return sendRequest("POST", HOSTS_TRANSFER_BY_FILTER, {
|
|
|
|
team_id: teamId,
|
|
|
|
filters: {
|
|
|
|
query,
|
|
|
|
status,
|
|
|
|
label_id: labelId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2022-12-16 21:12:11 +00:00
|
|
|
|
|
|
|
getMdm: (id: number) => {
|
|
|
|
const { HOST_MDM } = endpoints;
|
|
|
|
return sendRequest("GET", HOST_MDM(id));
|
|
|
|
},
|
|
|
|
|
|
|
|
getMdmSummary: (platform?: ISelectedPlatform, teamId?: number) => {
|
|
|
|
const { MDM_SUMMARY } = endpoints;
|
|
|
|
|
|
|
|
if (!platform || platform === "linux") {
|
|
|
|
throw new Error("mdm not supported for this platform");
|
|
|
|
}
|
|
|
|
|
|
|
|
const params = createMdmParams(platform, teamId);
|
|
|
|
const fullPath = params !== "" ? `${MDM_SUMMARY}?${params}` : MDM_SUMMARY;
|
|
|
|
return sendRequest("GET", fullPath);
|
|
|
|
},
|
2023-02-14 17:00:36 +00:00
|
|
|
|
|
|
|
getEncryptionKey: (id: number) => {
|
|
|
|
const { HOST_ENCRYPTION_KEY } = endpoints;
|
|
|
|
return sendRequest("GET", HOST_ENCRYPTION_KEY(id));
|
|
|
|
},
|
2021-08-03 19:42:48 +00:00
|
|
|
};
|