-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Add option to Reauthorize transform in Management page (#154736)
Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
2f8a729
commit dd46350
Showing
27 changed files
with
1,160 additions
and
20 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/transform/common/api_schemas/reauthorize_transforms.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,14 @@ | ||
/* | ||
* 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 { TypeOf } from '@kbn/config-schema'; | ||
|
||
import { transformIdsSchema, CommonResponseStatusSchema } from './common'; | ||
|
||
export const reauthorizeTransformsRequestSchema = transformIdsSchema; | ||
export type ReauthorizeTransformsRequestSchema = TypeOf<typeof reauthorizeTransformsRequestSchema>; | ||
export type ReauthorizeTransformsResponseSchema = CommonResponseStatusSchema; |
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
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
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
41 changes: 41 additions & 0 deletions
41
x-pack/plugins/transform/common/utils/transform_api_key.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,41 @@ | ||
/* | ||
* 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 type { GrantAPIKeyResult } from '@kbn/security-plugin/server'; | ||
import type { SecurityCreateApiKeyResponse } from '@elastic/elasticsearch/lib/api/types'; | ||
import { isPopulatedObject } from '@kbn/ml-is-populated-object'; | ||
|
||
export interface TransformAPIKey extends GrantAPIKeyResult { | ||
/** | ||
* Generated encoded API key used for headers | ||
*/ | ||
encoded: string; | ||
} | ||
|
||
export interface SecondaryAuthorizationHeader { | ||
headers?: { 'es-secondary-authorization': string | string[] }; | ||
} | ||
|
||
export function isTransformApiKey(arg: any): arg is TransformAPIKey { | ||
return isPopulatedObject(arg, ['api_key', 'encoded']) && typeof arg.encoded === 'string'; | ||
} | ||
|
||
export function generateTransformSecondaryAuthHeaders( | ||
apiKeyWithCurrentUserPermission: | ||
| GrantAPIKeyResult | ||
| null | ||
| undefined | ||
| SecurityCreateApiKeyResponse | ||
): SecondaryAuthorizationHeader | undefined { | ||
return isTransformApiKey(apiKeyWithCurrentUserPermission) | ||
? { | ||
headers: { | ||
'es-secondary-authorization': `ApiKey ${apiKeyWithCurrentUserPermission.encoded}`, | ||
}, | ||
} | ||
: undefined; | ||
} |
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/transform/public/app/common/reauthorization_utils.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,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 { isPopulatedObject } from '@kbn/ml-is-populated-object'; | ||
import type { TransformHealthIssue } from '../../../common/types/transform_stats'; | ||
import { TRANSFORM_HEALTH } from '../../../common/constants'; | ||
import type { TransformListRow } from './transform_list'; | ||
|
||
export const needsReauthorization = (transform: Partial<TransformListRow>) => { | ||
return ( | ||
isPopulatedObject(transform.config?.authorization, ['api_key']) && | ||
isPopulatedObject(transform.stats) && | ||
transform.stats.health.status === TRANSFORM_HEALTH.red && | ||
transform.stats.health.issues?.find( | ||
(issue) => (issue as TransformHealthIssue).issue === 'Privileges check failed' | ||
) !== undefined | ||
); | ||
}; |
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
81 changes: 81 additions & 0 deletions
81
x-pack/plugins/transform/public/app/hooks/use_reauthorize_transform.tsx
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,81 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { toMountPoint } from '@kbn/kibana-react-plugin/public'; | ||
|
||
import type { StartTransformsRequestSchema } from '../../../common/api_schemas/start_transforms'; | ||
import { isStartTransformsResponseSchema } from '../../../common/api_schemas/type_guards'; | ||
|
||
import { getErrorMessage } from '../../../common/utils/errors'; | ||
|
||
import { useAppDependencies, useToastNotifications } from '../app_dependencies'; | ||
import { refreshTransformList$, REFRESH_TRANSFORM_LIST_STATE } from '../common'; | ||
import { ToastNotificationText } from '../components'; | ||
|
||
import { useApi } from './use_api'; | ||
|
||
export const useReauthorizeTransforms = () => { | ||
const { overlays, theme } = useAppDependencies(); | ||
const toastNotifications = useToastNotifications(); | ||
const api = useApi(); | ||
|
||
return async (transformsInfo: StartTransformsRequestSchema) => { | ||
const results = await api.reauthorizeTransforms(transformsInfo); | ||
|
||
if (!isStartTransformsResponseSchema(results)) { | ||
toastNotifications.addDanger({ | ||
title: i18n.translate( | ||
'xpack.transform.stepCreateForm.reauthorizeTransformResponseSchemaErrorMessage', | ||
{ | ||
defaultMessage: 'An error occurred calling the reauthorize transforms request.', | ||
} | ||
), | ||
text: toMountPoint( | ||
<ToastNotificationText | ||
overlays={overlays} | ||
theme={theme} | ||
text={getErrorMessage(results)} | ||
/>, | ||
{ theme$: theme.theme$ } | ||
), | ||
}); | ||
return; | ||
} | ||
|
||
for (const transformId in results) { | ||
// hasOwnProperty check to ensure only properties on object itself, and not its prototypes | ||
if (results.hasOwnProperty(transformId)) { | ||
const result = results[transformId]; | ||
if (result.success === true) { | ||
toastNotifications.addSuccess( | ||
i18n.translate('xpack.transform.transformList.reauthorizeTransformSuccessMessage', { | ||
defaultMessage: 'Request to reauthorize transform {transformId} acknowledged.', | ||
values: { transformId }, | ||
}) | ||
); | ||
} else { | ||
toastNotifications.addError(new Error(JSON.stringify(result.error!.caused_by, null, 2)), { | ||
title: i18n.translate( | ||
'xpack.transform.transformList.reauthorizeTransformErrorMessage', | ||
{ | ||
defaultMessage: 'An error occurred reauthorizing the transform {transformId}', | ||
values: { transformId }, | ||
} | ||
), | ||
toastMessage: result.error!.reason, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
refreshTransformList$.next(REFRESH_TRANSFORM_LIST_STATE.REFRESH); | ||
}; | ||
}; |
10 changes: 10 additions & 0 deletions
10
...transform/public/app/sections/transform_management/components/action_reauthorize/index.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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { useReauthorizeAction } from './use_reauthorize_action'; | ||
export { ReauthorizeActionModal } from './reauthorize_action_modal'; | ||
export { isReauthorizeActionDisabled, ReauthorizeActionName } from './reauthorize_action_name'; |
64 changes: 64 additions & 0 deletions
64
.../sections/transform_management/components/action_reauthorize/reauthorize_action_modal.tsx
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,64 @@ | ||
/* | ||
* 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 React, { FC } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EUI_MODAL_CONFIRM_BUTTON, EuiConfirmModal } from '@elastic/eui'; | ||
import type { ReauthorizeAction } from './use_reauthorize_action'; | ||
|
||
export const ReauthorizeActionModal: FC<ReauthorizeAction> = ({ | ||
closeModal, | ||
items, | ||
reauthorizeAndCloseModal, | ||
}) => { | ||
const isBulkAction = items.length > 1; | ||
|
||
const bulkReauthorizeModalTitle = i18n.translate( | ||
'xpack.transform.transformList.bulkReauthorizeModalTitle', | ||
{ | ||
defaultMessage: 'Reauthorize {count} {count, plural, one {transform} other {transforms}}?', | ||
values: { count: items && items.length }, | ||
} | ||
); | ||
const reauthorizeModalTitle = i18n.translate( | ||
'xpack.transform.transformList.reauthorizeModalTitle', | ||
{ | ||
defaultMessage: 'Reauthorize {transformId}?', | ||
values: { transformId: items[0] && items[0].config.id }, | ||
} | ||
); | ||
|
||
return ( | ||
<EuiConfirmModal | ||
data-test-subj="transformReauthorizeModal" | ||
title={isBulkAction === true ? bulkReauthorizeModalTitle : reauthorizeModalTitle} | ||
onCancel={closeModal} | ||
onConfirm={reauthorizeAndCloseModal} | ||
cancelButtonText={i18n.translate( | ||
'xpack.transform.transformList.reauthorizeModalCancelButton', | ||
{ | ||
defaultMessage: 'Cancel', | ||
} | ||
)} | ||
confirmButtonText={i18n.translate( | ||
'xpack.transform.transformList.reauthorizeModalConfirmButton', | ||
{ | ||
defaultMessage: 'Reauthorize', | ||
} | ||
)} | ||
defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON} | ||
buttonColor="primary" | ||
> | ||
<p> | ||
{i18n.translate('xpack.transform.transformList.reauthorizeModalBody', { | ||
defaultMessage: | ||
'Your current roles are used to update and start the transform. Starting a transform increases search and indexing load in your cluster. If excessive load is experienced, stop the transform.', | ||
})} | ||
</p> | ||
</EuiConfirmModal> | ||
); | ||
}; |
Oops, something went wrong.