Fix unreleased bug in run script UI (#14462)

This commit is contained in:
gillespi314 2023-10-12 10:57:19 -05:00 committed by GitHub
parent 05c5af1f2c
commit e139eb412f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -67,7 +67,10 @@ const Scripts = ({ hostId, page = 0, isHostOnline, router }: IScriptsProps) => {
break;
case "run":
try {
await scriptsAPI.runScript(script.script_id);
await scriptsAPI.runScript({
host_id: hostId,
script_id: script.script_id,
});
refetchScriptsData();
} catch (e) {
const error = e as AxiosResponse<IApiError>;

View file

@ -72,6 +72,27 @@ export interface IHostScriptsResponse {
};
}
/**
* Request body for POST /scripts/run
*
* https://fleetdm.com/docs/rest-api/rest-api#run-script-asynchronously
*/
export interface IScriptRunRequest {
host_id: number;
script_id: number; // script_id is not required by the API currently, but we require it here to ensure it is always provided
// script_contents: string; // script_contents is only supported for the CLI currently
}
/**
* Response body for POST /scripts/run
*
* https://fleetdm.com/docs/rest-api/rest-api#run-script-asynchronously
*/
export interface IScriptRunResponse {
host_id: number;
execution_id: string;
}
export default {
getHostScripts(id: number, page?: number) {
const { HOST_SCRIPTS } = endpoints;
@ -126,8 +147,8 @@ export default {
return sendRequest("GET", SCRIPT_RESULT(executionId));
},
runScript(id: number) {
runScript(request: IScriptRunRequest): Promise<IScriptRunResponse> {
const { SCRIPT_RUN } = endpoints;
return sendRequest("POST", SCRIPT_RUN, { script_id: id });
return sendRequest("POST", SCRIPT_RUN, request);
},
};