-
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.
Browse files
Browse the repository at this point in the history
# Backport This will backport the following commits from `main` to `8.x`: - [[Search][Onboarding] api-key plugin (#191926)](#191926) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Yan Savitski","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-02T08:45:20Z","message":"[Search][Onboarding] api-key plugin (#191926)\n\n## Summary\r\nKibana plugin that helps manage the session for the api-key that\r\nprovides two exports:\r\n- React custom hook to read the api-key stored in session. This hook\r\nshould return the api-key if it exists, otherwise null.\r\n- Component to present either the api key in storage or action to create\r\napi key and store into sessionStorage after callback.\r\n<img width=\"1255\" alt=\"Screenshot 2024-09-27 at 20 52 52\"\r\nsrc=\"https://github.com/user-attachments/assets/dc5bcd39-7fe6-433c-8aaa-ad3578a68b62\">\r\n<img width=\"1248\" alt=\"Screenshot 2024-09-27 at 20 52 39\"\r\nsrc=\"https://github.com/user-attachments/assets/d760c163-9017-4f57-ba1a-38ee8ee21534\">\r\n<img width=\"676\" alt=\"Screenshot 2024-09-27 at 20 52 28\"\r\nsrc=\"https://github.com/user-attachments/assets/e908d20a-7e0c-4f3b-9ea2-8e2d1a74c9eb\">","sha":"c5aa73991463dee50b036bb51645e03cc283bb8c","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor"],"number":191926,"url":"https://github.com/elastic/kibana/pull/191926","mergeCommit":{"message":"[Search][Onboarding] api-key plugin (#191926)\n\n## Summary\r\nKibana plugin that helps manage the session for the api-key that\r\nprovides two exports:\r\n- React custom hook to read the api-key stored in session. This hook\r\nshould return the api-key if it exists, otherwise null.\r\n- Component to present either the api key in storage or action to create\r\napi key and store into sessionStorage after callback.\r\n<img width=\"1255\" alt=\"Screenshot 2024-09-27 at 20 52 52\"\r\nsrc=\"https://github.com/user-attachments/assets/dc5bcd39-7fe6-433c-8aaa-ad3578a68b62\">\r\n<img width=\"1248\" alt=\"Screenshot 2024-09-27 at 20 52 39\"\r\nsrc=\"https://github.com/user-attachments/assets/d760c163-9017-4f57-ba1a-38ee8ee21534\">\r\n<img width=\"676\" alt=\"Screenshot 2024-09-27 at 20 52 28\"\r\nsrc=\"https://github.com/user-attachments/assets/e908d20a-7e0c-4f3b-9ea2-8e2d1a74c9eb\">","sha":"c5aa73991463dee50b036bb51645e03cc283bb8c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/191926","number":191926,"mergeCommit":{"message":"[Search][Onboarding] api-key plugin (#191926)\n\n## Summary\r\nKibana plugin that helps manage the session for the api-key that\r\nprovides two exports:\r\n- React custom hook to read the api-key stored in session. This hook\r\nshould return the api-key if it exists, otherwise null.\r\n- Component to present either the api key in storage or action to create\r\napi key and store into sessionStorage after callback.\r\n<img width=\"1255\" alt=\"Screenshot 2024-09-27 at 20 52 52\"\r\nsrc=\"https://github.com/user-attachments/assets/dc5bcd39-7fe6-433c-8aaa-ad3578a68b62\">\r\n<img width=\"1248\" alt=\"Screenshot 2024-09-27 at 20 52 39\"\r\nsrc=\"https://github.com/user-attachments/assets/d760c163-9017-4f57-ba1a-38ee8ee21534\">\r\n<img width=\"676\" alt=\"Screenshot 2024-09-27 at 20 52 28\"\r\nsrc=\"https://github.com/user-attachments/assets/e908d20a-7e0c-4f3b-9ea2-8e2d1a74c9eb\">","sha":"c5aa73991463dee50b036bb51645e03cc283bb8c"}}]}] BACKPORT--> --------- Co-authored-by: Yan Savitski <[email protected]>
- Loading branch information
1 parent
654aed0
commit 522fffb
Showing
51 changed files
with
1,205 additions
and
126 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Search API Key Components | ||
|
||
The Search API Keys components package is a shared components and utilities to simplify managing the API Keys experience for elasticsearch users across stack and serverless search solutions. |
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,13 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export * from './src/components/api_key_flyout_wrapper'; | ||
export * from './src/components/api_key_form'; | ||
export * from './src/hooks/use_search_api_key'; | ||
export * from './src/providers/search_api_key_provider'; |
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,20 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-search-api-keys-components'], | ||
coverageDirectory: | ||
'<rootDir>/target/kibana-coverage/jest/packages/kbn-search-api-keys-components', | ||
coverageReporters: ['text', 'html'], | ||
collectCoverageFrom: [ | ||
'<rootDir>/packages/kbn-search-api-keys-components/public/{components,hooks}/**/*.{ts,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,5 @@ | ||
{ | ||
"type": "shared-browser", | ||
"id": "@kbn/search-api-keys-components", | ||
"owner": "@elastic/search-kibana" | ||
} |
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,6 @@ | ||
{ | ||
"name": "@kbn/search-api-keys-components", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0" | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/kbn-search-api-keys-components/src/components/api_key_flyout_wrapper.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,25 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import React from 'react'; | ||
import { ApiKeyFlyout, ApiKeyFlyoutProps } from '@kbn/security-api-key-management'; | ||
import type { SecurityCreateApiKeyResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
|
||
const API_KEY_NAME = 'Unrestricted API Key'; | ||
|
||
type ApiKeyFlyoutWrapperProps = Pick<ApiKeyFlyoutProps, 'onCancel'> & { | ||
onSuccess?: (createApiKeyResponse: SecurityCreateApiKeyResponse) => void; | ||
}; | ||
|
||
export const ApiKeyFlyoutWrapper: React.FC<ApiKeyFlyoutWrapperProps> = ({ | ||
onCancel, | ||
onSuccess, | ||
}) => { | ||
return <ApiKeyFlyout onCancel={onCancel} onSuccess={onSuccess} defaultName={API_KEY_NAME} />; | ||
}; |
101 changes: 101 additions & 0 deletions
101
packages/kbn-search-api-keys-components/src/components/api_key_form.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,101 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
EuiBadge, | ||
EuiButton, | ||
EuiButtonIcon, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormInfoField } from '@kbn/search-shared-ui'; | ||
import { ApiKeyFlyoutWrapper } from './api_key_flyout_wrapper'; | ||
import { useSearchApiKey } from '../hooks/use_search_api_key'; | ||
import { Status } from '../constants'; | ||
|
||
interface ApiKeyFormProps { | ||
hasTitle?: boolean; | ||
} | ||
|
||
export const ApiKeyForm: React.FC<ApiKeyFormProps> = ({ hasTitle = true }) => { | ||
const [showFlyout, setShowFlyout] = useState(false); | ||
const { apiKey, status, updateApiKey, toggleApiKeyVisibility, displayedApiKey, apiKeyIsVisible } = | ||
useSearchApiKey(); | ||
|
||
const titleLocale = i18n.translate('searchApiKeysComponents.apiKeyForm.title', { | ||
defaultMessage: 'API Key', | ||
}); | ||
|
||
if (apiKey && displayedApiKey) { | ||
return ( | ||
<FormInfoField | ||
label={hasTitle ? titleLocale : undefined} | ||
value={displayedApiKey} | ||
copyValue={apiKey} | ||
dataTestSubj="apiKeyFormAPIKey" | ||
actions={[ | ||
<EuiButtonIcon | ||
iconType={apiKeyIsVisible ? 'eyeClosed' : 'eye'} | ||
color="success" | ||
onClick={toggleApiKeyVisibility} | ||
data-test-subj="showAPIKeyButton" | ||
aria-label={i18n.translate('searchApiKeysComponents.apiKeyForm.showApiKey', { | ||
defaultMessage: 'Show API Key', | ||
})} | ||
/>, | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup alignItems="center" gutterSize="s" justifyContent="flexStart" responsive={false}> | ||
{hasTitle && ( | ||
<EuiFlexItem grow={0}> | ||
<EuiTitle size="xxxs" css={{ whiteSpace: 'nowrap' }}> | ||
<h6>{titleLocale}</h6> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
)} | ||
{status === Status.showUserPrivilegesError && ( | ||
<EuiFlexItem grow={0}> | ||
<EuiBadge data-test-subj="apiKeyFormNoUserPrivileges"> | ||
{i18n.translate('searchApiKeysComponents.apiKeyForm.noUserPrivileges', { | ||
defaultMessage: "You don't have access to manage API keys", | ||
})} | ||
</EuiBadge> | ||
</EuiFlexItem> | ||
)} | ||
{status === Status.showCreateButton && ( | ||
<EuiFlexItem grow={0}> | ||
<EuiButton | ||
color="primary" | ||
size="s" | ||
iconSide="left" | ||
iconType="key" | ||
onClick={() => setShowFlyout(true)} | ||
data-test-subj="createAPIKeyButton" | ||
> | ||
<FormattedMessage | ||
id="searchApiKeysComponents.apiKeyForm.createButton" | ||
defaultMessage="Create an API Key" | ||
/> | ||
</EuiButton> | ||
{showFlyout && ( | ||
<ApiKeyFlyoutWrapper onCancel={() => setShowFlyout(false)} onSuccess={updateApiKey} /> | ||
)} | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
}; |
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,17 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export enum Status { | ||
uninitialized = 'uninitialized', | ||
loading = 'loading', | ||
showCreateButton = 'showCreateButton', | ||
showHiddenKey = 'showHiddenKey', | ||
showPreviewKey = 'showPreviewKey', | ||
showUserPrivilegesError = 'showUserPrivilegesError', | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/kbn-search-api-keys-components/src/hooks/use_search_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,19 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { useContext, useEffect } from 'react'; | ||
import { ApiKeyContext } from '../providers/search_api_key_provider'; | ||
|
||
export const useSearchApiKey = () => { | ||
const { initialiseKey, ...context } = useContext(ApiKeyContext); | ||
useEffect(() => { | ||
initialiseKey(); | ||
}, [initialiseKey]); | ||
return context; | ||
}; |
Oops, something went wrong.