Skip to content

Commit

Permalink
[Enterprise Search] Remove access control as well if exists (#161122)
Browse files Browse the repository at this point in the history
## Summary

- Add access control remove
- Deletes access control index too after content index is deleted.


### Checklist

Delete any items that are not applicable to this PR.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
efegurkan and kibanamachine authored Jul 4, 2023
1 parent 54e613b commit 472d843
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { isIndexNotFoundException } from '@kbn/core-saved-objects-migration-server-internal';
import { IScopedClusterClient } from '@kbn/core/server';

import { CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX } from '../..';

export const deleteAccessControlIndex = async (client: IScopedClusterClient, index: string) => {
try {
await client.asCurrentUser.indices.delete({
index: index.replace('search-', CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX),
});
} catch (e) {
// Gracefully exit if index not found. This is a valid case.
if (!isIndexNotFoundException(e)) throw e;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { fetchConnectorByIndexName, fetchConnectors } from '../../lib/connectors
import { fetchCrawlerByIndexName, fetchCrawlers } from '../../lib/crawler/fetch_crawlers';

import { createIndex } from '../../lib/indices/create_index';
import { deleteAccessControlIndex } from '../../lib/indices/delete_access_control_index';
import { indexOrAliasExists } from '../../lib/indices/exists_index';
import { fetchIndex } from '../../lib/indices/fetch_index';
import { fetchIndices, fetchSearchIndices } from '../../lib/indices/fetch_indices';
Expand Down Expand Up @@ -201,6 +202,7 @@ export function registerIndexRoutes({
}

await deleteIndexPipelines(client, indexName);
await deleteAccessControlIndex(client, indexName);

await client.asCurrentUser.indices.delete({ index: indexName });

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/enterprise_search/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@
"@kbn/shared-ux-link-redirect-app",
"@kbn/global-search-plugin",
"@kbn/share-plugin",
"@kbn/core-saved-objects-migration-server-internal",
]
}

0 comments on commit 472d843

Please sign in to comment.