-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution] Initiate endpoint package upgrade from security app #77498
Merged
jonathan-buttner
merged 24 commits into
elastic:master
from
jonathan-buttner:upgrade-endpoint-package
Sep 28, 2020
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1a3506e
Working on package update functionality
jonathan-buttner 5d39443
Correctly installing package
jonathan-buttner 5c3a58f
Moving upgrade component and working upgrade
jonathan-buttner ebaae00
Doing permissions check
jonathan-buttner dc9303d
Cleaning up imports
jonathan-buttner 3667f85
Merge branch 'master' of github.com:elastic/kibana into upgrade-endpo…
jonathan-buttner 76df74d
Adding bulk upgrade api
jonathan-buttner 6dea606
Addressing comments
jonathan-buttner 268c526
Removing todo
jonathan-buttner 04a39bd
Resolving conflicts
jonathan-buttner f3d3979
Merge branch 'master' of github.com:elastic/kibana into upgrade-endpo…
jonathan-buttner 8eb2cea
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner f111406
Changing body field
jonathan-buttner 5e19070
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner 2846b76
Adding helper for getting the bulk install route
jonathan-buttner 3fffaef
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner 20357fd
Adding request spec
jonathan-buttner ff0cbce
Merge branch 'ingest-bulk-upgrade' into upgrade-endpoint-package
jonathan-buttner 810b203
Using bulk install endpoint from ingest
jonathan-buttner 3c400fe
Resolving conflicts
jonathan-buttner b8a9fc7
Moving component to a hook
jonathan-buttner 44c32d9
Fixing merge conflicts
jonathan-buttner 46699bd
Pulling changes from master
jonathan-buttner fedc630
Addressing feedback
jonathan-buttner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
x-pack/plugins/security_solution/public/common/hooks/endpoint/upgrade.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { useEffect } from 'react'; | ||
import { HttpFetchOptions, HttpStart } from 'src/core/public'; | ||
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'; | ||
import { | ||
epmRouteService, | ||
appRoutesService, | ||
CheckPermissionsResponse, | ||
BulkInstallPackagesResponse, | ||
} from '../../../../../ingest_manager/common'; | ||
import { StartServices } from '../../../types'; | ||
import { useIngestEnabledCheck } from './ingest_enabled'; | ||
|
||
/** | ||
* Requests that the endpoint package be upgraded to the latest version | ||
* | ||
* @param http an http client for sending the request | ||
* @param options an object containing options for the request | ||
*/ | ||
const sendUpgradeEndpointPackage = async ( | ||
http: HttpStart, | ||
options: HttpFetchOptions = {} | ||
): Promise<BulkInstallPackagesResponse> => { | ||
return http.post<BulkInstallPackagesResponse>(epmRouteService.getBulkInstallPath(), { | ||
...options, | ||
body: JSON.stringify({ | ||
packages: ['endpoint'], | ||
}), | ||
}); | ||
}; | ||
|
||
/** | ||
* Checks with the ingest manager if the current user making these requests has the right permissions | ||
* to install the endpoint package. | ||
* | ||
* @param http an http client for sending the request | ||
* @param options an object containing options for the request | ||
*/ | ||
const sendCheckPermissions = async ( | ||
http: HttpStart, | ||
options: HttpFetchOptions = {} | ||
): Promise<CheckPermissionsResponse> => { | ||
return http.get<CheckPermissionsResponse>(appRoutesService.getCheckPermissionsPath(), { | ||
...options, | ||
}); | ||
}; | ||
|
||
export const useUpgradeEndpointPackage = () => { | ||
const context = useKibana<StartServices>(); | ||
const { allEnabled: ingestEnabled } = useIngestEnabledCheck(); | ||
|
||
useEffect(() => { | ||
const abortController = new AbortController(); | ||
|
||
// cancel any ongoing requests | ||
const abortRequests = () => { | ||
abortController.abort(); | ||
}; | ||
|
||
if (ingestEnabled) { | ||
const signal = abortController.signal; | ||
|
||
(async () => { | ||
try { | ||
// make sure we're a privileged user before trying to install the package | ||
const { success: hasPermissions } = await sendCheckPermissions(context.services.http, { | ||
signal, | ||
}); | ||
|
||
// if we're not a privileged user then return and don't try to check the status of the endpoint package | ||
if (!hasPermissions) { | ||
return abortRequests; | ||
} | ||
|
||
// ignore the response for now since we aren't notifying the user | ||
await sendUpgradeEndpointPackage(context.services.http, { signal }); | ||
} catch (error) { | ||
// Ignore Errors, since this should not hinder the user's ability to use the UI | ||
|
||
// ignore the error that occurs from aborting a request | ||
if (!abortController.signal.aborted) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
} | ||
} | ||
|
||
return abortRequests; | ||
})(); | ||
} | ||
}, [ingestEnabled, context.services.http]); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ Elaborating to explain when/how often that will happen and why may be helpful to the reader.