-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[eem] add option to delete indices when deleting definition #188116
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import { RequestHandlerContext } from '@kbn/core/server'; | ||
import { getFakeKibanaRequest } from '@kbn/security-plugin/server/authentication/api_keys/fake_kibana_request'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { SetupRouteOptions } from '../types'; | ||
import { ENTITY_INTERNAL_API_PREFIX } from '../../../common/constants_entities'; | ||
import { | ||
|
@@ -16,17 +17,20 @@ import { | |
} from '../../lib/auth'; | ||
import { ERROR_API_KEY_NOT_FOUND, ERROR_API_KEY_NOT_VALID } from '../../../common/errors'; | ||
import { uninstallBuiltInEntityDefinitions } from '../../lib/entities/uninstall_entity_definition'; | ||
import { DisableManagedEntityResponse } from '../../../common/types_api'; | ||
|
||
export function disableEntityDiscoveryRoute<T extends RequestHandlerContext>({ | ||
router, | ||
server, | ||
logger, | ||
}: SetupRouteOptions<T>) { | ||
router.delete<unknown, unknown, DisableManagedEntityResponse>( | ||
router.delete<unknown, { deleteData?: boolean }, unknown>( | ||
{ | ||
path: `${ENTITY_INTERNAL_API_PREFIX}/managed/enablement`, | ||
validate: false, | ||
validate: { | ||
query: schema.object({ | ||
deleteData: schema.maybe(schema.boolean({ defaultValue: false })), | ||
}), | ||
}, | ||
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we convert this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, logged #188171 |
||
}, | ||
async (context, req, res) => { | ||
try { | ||
|
@@ -48,7 +52,12 @@ export function disableEntityDiscoveryRoute<T extends RequestHandlerContext>({ | |
const soClient = server.core.savedObjects.getScopedClient(fakeRequest); | ||
const esClient = server.core.elasticsearch.client.asScoped(fakeRequest).asCurrentUser; | ||
|
||
await uninstallBuiltInEntityDefinitions({ soClient, esClient, logger }); | ||
await uninstallBuiltInEntityDefinitions({ | ||
soClient, | ||
esClient, | ||
logger, | ||
deleteData: req.query.deleteData, | ||
}); | ||
|
||
await deleteEntityDiscoveryAPIKey((await context.core).savedObjects.client); | ||
await server.security.authc.apiKeys.invalidateAsInternalUser({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,16 @@ export function deleteEntityDefinitionRoute<T extends RequestHandlerContext>({ | |
router, | ||
server, | ||
}: SetupRouteOptions<T>) { | ||
router.delete<{ id: string }, unknown, unknown>( | ||
router.delete<{ id: string }, { deleteData?: boolean }, unknown>( | ||
{ | ||
path: `${ENTITY_INTERNAL_API_PREFIX}/definition/{id}`, | ||
validate: { | ||
params: schema.object({ | ||
id: schema.string(), | ||
}), | ||
query: schema.object({ | ||
deleteData: schema.maybe(schema.boolean({ defaultValue: false })), | ||
}), | ||
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. zod-ify please |
||
}, | ||
}, | ||
async (context, req, res) => { | ||
|
@@ -35,7 +38,13 @@ export function deleteEntityDefinitionRoute<T extends RequestHandlerContext>({ | |
const esClient = (await context.core).elasticsearch.client.asCurrentUser; | ||
|
||
const definition = await readEntityDefinition(soClient, req.params.id, logger); | ||
await uninstallEntityDefinition({ definition, soClient, esClient, logger }); | ||
await uninstallEntityDefinition({ | ||
definition, | ||
soClient, | ||
esClient, | ||
logger, | ||
deleteData: req.query.deleteData, | ||
}); | ||
|
||
return res.ok({ body: { acknowledged: true } }); | ||
} catch (e) { | ||
|
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.
wrongly assumed this parameter to be the response type instead of the body type