mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
bd9176d67e
relates to #10935 This is the UI for all the flows around adding, removing, downloading, and viewing information about a bootstrap package for fleet mdm. This is pretty comprehensive but includes: ### Backend **Update `Get host/id`** to include bootstrap package name ```json { "macos_setup": { ... "bootstrap_package_name": "test.pkg" } } ``` ### Frontend **UI for ABM not being set up**: ![image](https://user-images.githubusercontent.com/1153709/234018772-3221e27b-50a4-454e-8e9f-b62c9d349010.png) **UIs for uploading, downloading, and deleting bootstrap package**: ![image](https://user-images.githubusercontent.com/1153709/234017915-871f252f-bf80-4282-9acf-5ebea12c6efa.png) ![image](https://user-images.githubusercontent.com/1153709/234018029-322a5f30-dd22-44e3-b9ae-a4af7acb68b4.png) ![image](https://user-images.githubusercontent.com/1153709/234018163-4b84a2ce-a064-4952-a63d-0c8307391052.png) **UIs for seeing bootstrap status aggregate data** ![image](https://user-images.githubusercontent.com/1153709/234018107-455d63ab-5b2c-4727-ad20-eef6b269c336.png) **UIs for filtering hosts by bootstrap status** ![image](https://user-images.githubusercontent.com/1153709/234018334-170fe93a-700e-48eb-b198-2a1cc54d31a7.png) **UIs for seeing package status on host details and my device page**: ![image](https://user-images.githubusercontent.com/1153709/234018488-7b515db4-1248-4be7-8de3-9b74bb5d4795.png) ![image](https://user-images.githubusercontent.com/1153709/234018525-d653cb2d-9ef9-437e-8eba-141e557f4f39.png) - [x] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Roberto Dip <dip.jesusr@gmail.com> Co-authored-by: gillespi314 <73313222+gillespi314@users.noreply.github.com> Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
348 lines
9.0 KiB
TypeScript
348 lines
9.0 KiB
TypeScript
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
import sendRequest from "services";
|
|
import endpoints from "utilities/endpoints";
|
|
import { IHost, HostStatus } from "interfaces/host";
|
|
import {
|
|
buildQueryStringFromParams,
|
|
getLabelParam,
|
|
reconcileMutuallyExclusiveHostParams,
|
|
reconcileMutuallyInclusiveHostParams,
|
|
} from "utilities/url";
|
|
import { ISelectedPlatform } from "interfaces/platform";
|
|
import { ISoftware } from "interfaces/software";
|
|
import {
|
|
FileVaultProfileStatus,
|
|
BootstrapPackageStatus,
|
|
IMdmSolution,
|
|
} from "interfaces/mdm";
|
|
import { IMunkiIssuesAggregate } from "interfaces/macadmins";
|
|
|
|
export interface ISortOption {
|
|
key: string;
|
|
direction: string;
|
|
}
|
|
|
|
export interface ILoadHostsResponse {
|
|
hosts: IHost[];
|
|
software: ISoftware;
|
|
munki_issue: IMunkiIssuesAggregate;
|
|
mobile_device_management_solution: IMdmSolution;
|
|
}
|
|
|
|
export interface ILoadHostsQueryKey extends ILoadHostsOptions {
|
|
scope: "hosts";
|
|
}
|
|
|
|
export type MacSettingsStatusQueryParam = "latest" | "pending" | "failing";
|
|
|
|
export interface ILoadHostsOptions {
|
|
page?: number;
|
|
perPage?: number;
|
|
selectedLabels?: string[];
|
|
globalFilter?: string;
|
|
sortBy?: ISortOption[];
|
|
teamId?: number;
|
|
policyId?: number;
|
|
policyResponse?: string;
|
|
macSettingsStatus?: MacSettingsStatusQueryParam;
|
|
softwareId?: number;
|
|
status?: HostStatus;
|
|
mdmId?: number;
|
|
mdmEnrollmentStatus?: string;
|
|
lowDiskSpaceHosts?: number;
|
|
osId?: number;
|
|
osName?: string;
|
|
osVersion?: string;
|
|
munkiIssueId?: number;
|
|
device_mapping?: boolean;
|
|
columns?: string;
|
|
visibleColumns?: string;
|
|
diskEncryptionStatus?: FileVaultProfileStatus;
|
|
bootstrapPackageStatus?: BootstrapPackageStatus;
|
|
}
|
|
|
|
export interface IExportHostsOptions {
|
|
sortBy: ISortOption[];
|
|
page?: number;
|
|
perPage?: number;
|
|
selectedLabels?: string[];
|
|
globalFilter?: string;
|
|
teamId?: number;
|
|
policyId?: number;
|
|
policyResponse?: string;
|
|
macSettingsStatus?: MacSettingsStatusQueryParam;
|
|
softwareId?: number;
|
|
status?: HostStatus;
|
|
mdmId?: number;
|
|
munkiIssueId?: number;
|
|
mdmEnrollmentStatus?: string;
|
|
lowDiskSpaceHosts?: number;
|
|
osId?: number;
|
|
osName?: string;
|
|
osVersion?: string;
|
|
device_mapping?: boolean;
|
|
columns?: string;
|
|
visibleColumns?: string;
|
|
diskEncryptionStatus?: FileVaultProfileStatus;
|
|
}
|
|
|
|
export interface IActionByFilter {
|
|
teamId: number | null;
|
|
query: string;
|
|
status: string;
|
|
labelId?: number;
|
|
}
|
|
|
|
export type ILoadHostDetailsExtension = "device_mapping" | "macadmins";
|
|
|
|
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;
|
|
if (selectedLabels === undefined) return HOSTS;
|
|
|
|
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,
|
|
};
|
|
};
|
|
|
|
const createMdmParams = (platform?: ISelectedPlatform, teamId?: number) => {
|
|
if (platform === "all") {
|
|
return buildQueryStringFromParams({ team_id: teamId });
|
|
}
|
|
|
|
return buildQueryStringFromParams({ platform, team_id: teamId });
|
|
};
|
|
|
|
export default {
|
|
destroy: (host: IHost) => {
|
|
const { HOSTS } = endpoints;
|
|
const path = `${HOSTS}/${host.id}`;
|
|
|
|
return sendRequest("DELETE", path);
|
|
},
|
|
destroyBulk: (hostIds: number[]) => {
|
|
const { HOSTS_DELETE } = endpoints;
|
|
|
|
return sendRequest("POST", HOSTS_DELETE, { ids: hostIds });
|
|
},
|
|
destroyByFilter: ({ teamId, query, status, labelId }: IActionByFilter) => {
|
|
const { HOSTS_DELETE } = endpoints;
|
|
return sendRequest("POST", HOSTS_DELETE, {
|
|
filters: {
|
|
query,
|
|
status,
|
|
label_id: labelId,
|
|
team_id: teamId,
|
|
},
|
|
});
|
|
},
|
|
exportHosts: (options: IExportHostsOptions) => {
|
|
const sortBy = options.sortBy;
|
|
const selectedLabels = options?.selectedLabels || [];
|
|
const globalFilter = options?.globalFilter || "";
|
|
const teamId = options?.teamId;
|
|
const policyId = options?.policyId;
|
|
const policyResponse = options?.policyResponse || "passing";
|
|
const softwareId = options?.softwareId;
|
|
const macSettingsStatus = options?.macSettingsStatus;
|
|
const status = options?.status;
|
|
const mdmId = options?.mdmId;
|
|
const mdmEnrollmentStatus = options?.mdmEnrollmentStatus;
|
|
const lowDiskSpaceHosts = options?.lowDiskSpaceHosts;
|
|
const visibleColumns = options?.visibleColumns;
|
|
const label = getLabelParam(selectedLabels);
|
|
const munkiIssueId = options?.munkiIssueId;
|
|
const diskEncryptionStatus = options?.diskEncryptionStatus;
|
|
|
|
if (!sortBy.length) {
|
|
throw Error("sortBy is a required field.");
|
|
}
|
|
|
|
const queryParams = {
|
|
order_key: sortBy[0].key,
|
|
order_direction: sortBy[0].direction,
|
|
query: globalFilter,
|
|
...reconcileMutuallyInclusiveHostParams({ teamId, macSettingsStatus }),
|
|
...reconcileMutuallyExclusiveHostParams({
|
|
label,
|
|
policyId,
|
|
policyResponse,
|
|
mdmId,
|
|
mdmEnrollmentStatus,
|
|
munkiIssueId,
|
|
softwareId,
|
|
lowDiskSpaceHosts,
|
|
diskEncryptionStatus,
|
|
}),
|
|
status,
|
|
label_id: label,
|
|
columns: visibleColumns,
|
|
format: "csv",
|
|
};
|
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
|
const endpoint = endpoints.HOSTS_REPORT;
|
|
const path = `${endpoint}?${queryString}`;
|
|
|
|
return sendRequest("GET", path);
|
|
},
|
|
loadHosts: ({
|
|
page = 0,
|
|
perPage = 100,
|
|
globalFilter,
|
|
teamId,
|
|
policyId,
|
|
policyResponse = "passing",
|
|
macSettingsStatus,
|
|
softwareId,
|
|
status,
|
|
mdmId,
|
|
mdmEnrollmentStatus,
|
|
munkiIssueId,
|
|
lowDiskSpaceHosts,
|
|
osId,
|
|
osName,
|
|
osVersion,
|
|
device_mapping,
|
|
selectedLabels,
|
|
sortBy,
|
|
diskEncryptionStatus,
|
|
bootstrapPackageStatus,
|
|
}: ILoadHostsOptions): Promise<ILoadHostsResponse> => {
|
|
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,
|
|
status,
|
|
...reconcileMutuallyInclusiveHostParams({
|
|
teamId,
|
|
macSettingsStatus,
|
|
}),
|
|
...reconcileMutuallyExclusiveHostParams({
|
|
label,
|
|
policyId,
|
|
policyResponse,
|
|
mdmId,
|
|
mdmEnrollmentStatus,
|
|
munkiIssueId,
|
|
softwareId,
|
|
lowDiskSpaceHosts,
|
|
osId,
|
|
osName,
|
|
osVersion,
|
|
diskEncryptionStatus,
|
|
bootstrapPackageStatus,
|
|
}),
|
|
};
|
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
|
|
|
const endpoint = getHostEndpoint(selectedLabels);
|
|
const path = `${endpoint}?${queryString}`;
|
|
return sendRequest("GET", path);
|
|
},
|
|
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);
|
|
},
|
|
search: (searchText: string) => {
|
|
const { HOSTS } = endpoints;
|
|
const path = `${HOSTS}?query=${searchText}`;
|
|
|
|
return sendRequest("GET", path);
|
|
},
|
|
transferToTeam: (teamId: number | null, hostIds: number[]) => {
|
|
const { HOSTS_TRANSFER } = endpoints;
|
|
|
|
return sendRequest("POST", HOSTS_TRANSFER, {
|
|
team_id: teamId,
|
|
hosts: hostIds,
|
|
});
|
|
},
|
|
|
|
// TODO confirm interplay with policies
|
|
transferToTeamByFilter: ({
|
|
teamId,
|
|
query,
|
|
status,
|
|
labelId,
|
|
}: IActionByFilter) => {
|
|
const { HOSTS_TRANSFER_BY_FILTER } = endpoints;
|
|
return sendRequest("POST", HOSTS_TRANSFER_BY_FILTER, {
|
|
team_id: teamId,
|
|
filters: {
|
|
query,
|
|
status,
|
|
label_id: labelId,
|
|
},
|
|
});
|
|
},
|
|
|
|
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);
|
|
},
|
|
|
|
getEncryptionKey: (id: number) => {
|
|
const { HOST_ENCRYPTION_KEY } = endpoints;
|
|
return sendRequest("GET", HOST_ENCRYPTION_KEY(id));
|
|
},
|
|
};
|