mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Fix API links when generating API key snippet (#155435)
Fixes the Search Applications API page to set an URL to the ES plugin rather than Enterprise Search URL. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
2c14b584f8
commit
3d78370aa5
2 changed files with 21 additions and 12 deletions
|
@ -12,23 +12,24 @@ import { useValues } from 'kea';
|
|||
import { EuiCodeBlock, EuiSpacer, EuiText, EuiTabs, EuiTab } from '@elastic/eui';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { getEnterpriseSearchUrl } from '../../../../shared/enterprise_search_url';
|
||||
|
||||
import { useCloudDetails } from '../../../../shared/cloud_details/cloud_details';
|
||||
import { EngineViewLogic } from '../engine_view_logic';
|
||||
|
||||
import { EngineApiLogic } from './engine_api_logic';
|
||||
|
||||
const SearchUISnippet = (enterpriseSearchUrl: string, engineName: string, apiKey: string) => `
|
||||
import { elasticsearchUrl } from './search_application_api';
|
||||
|
||||
const SearchUISnippet = (esUrl: string, engineName: string, apiKey: string) => `6
|
||||
import EnginesAPIConnector from "@elastic/search-ui-engines-connector";
|
||||
|
||||
const connector = new EnginesAPIConnector({
|
||||
host: "${enterpriseSearchUrl}",
|
||||
host: "${esUrl}",
|
||||
engineName: "${engineName}",
|
||||
apiKey: "${apiKey || '<YOUR_API_KEY>'}"
|
||||
});`;
|
||||
|
||||
const cURLSnippet = (enterpriseSearchUrl: string, engineName: string, apiKey: string) => `
|
||||
curl --location --request GET '${enterpriseSearchUrl}/api/engines/${engineName}/_search' \\
|
||||
const cURLSnippet = (esUrl: string, engineName: string, apiKey: string) => `
|
||||
curl --location --request GET '${esUrl}/${engineName}/_search' \\
|
||||
--header 'Authorization: apiKey ${apiKey || '<YOUR_API_KEY>'}' \\
|
||||
--header 'Content-Type: application/json' \\
|
||||
--data-raw '{
|
||||
|
@ -47,19 +48,19 @@ interface Tab {
|
|||
export const EngineApiIntegrationStage: React.FC = () => {
|
||||
const [selectedTab, setSelectedTab] = React.useState<TabId>('curl');
|
||||
const { engineName } = useValues(EngineViewLogic);
|
||||
const enterpriseSearchUrl = getEnterpriseSearchUrl();
|
||||
const { apiKey } = useValues(EngineApiLogic);
|
||||
const cloudContext = useCloudDetails();
|
||||
|
||||
const Tabs: Record<TabId, Tab> = {
|
||||
curl: {
|
||||
code: cURLSnippet(enterpriseSearchUrl, engineName, apiKey),
|
||||
code: cURLSnippet(elasticsearchUrl(cloudContext), engineName, apiKey),
|
||||
language: 'bash',
|
||||
title: i18n.translate('xpack.enterpriseSearch.content.engine.api.step3.curlTitle', {
|
||||
defaultMessage: 'cURL',
|
||||
}),
|
||||
},
|
||||
searchui: {
|
||||
code: SearchUISnippet(enterpriseSearchUrl, engineName, apiKey),
|
||||
code: SearchUISnippet(elasticsearchUrl(cloudContext), engineName, apiKey),
|
||||
language: 'javascript',
|
||||
title: i18n.translate('xpack.enterpriseSearch.content.engine.api.step3.searchUITitle', {
|
||||
defaultMessage: 'Search UI',
|
||||
|
|
|
@ -23,9 +23,10 @@ import { i18n } from '@kbn/i18n';
|
|||
|
||||
import { ANALYTICS_PLUGIN } from '../../../../../../common/constants';
|
||||
import { COLLECTION_INTEGRATE_PATH } from '../../../../analytics/routes';
|
||||
import { CloudDetails, useCloudDetails } from '../../../../shared/cloud_details/cloud_details';
|
||||
import { decodeCloudId } from '../../../../shared/decode_cloud_id/decode_cloud_id';
|
||||
import { docLinks } from '../../../../shared/doc_links';
|
||||
import { generateEncodedPath } from '../../../../shared/encode_path_params';
|
||||
import { getEnterpriseSearchUrl } from '../../../../shared/enterprise_search_url';
|
||||
import { KibanaLogic } from '../../../../shared/kibana';
|
||||
|
||||
import { EngineViewLogic } from '../engine_view_logic';
|
||||
|
@ -34,12 +35,19 @@ import { EngineApiIntegrationStage } from './engine_api_integration';
|
|||
import { EngineApiLogic } from './engine_api_logic';
|
||||
import { GenerateEngineApiKeyModal } from './generate_engine_api_key_modal/generate_engine_api_key_modal';
|
||||
|
||||
export const elasticsearchUrl = (cloudContext: CloudDetails): string => {
|
||||
const defaultUrl = 'https://localhost:9200';
|
||||
const url =
|
||||
(cloudContext.cloudId && decodeCloudId(cloudContext.cloudId)?.elasticsearchUrl) || defaultUrl;
|
||||
return url;
|
||||
};
|
||||
|
||||
export const SearchApplicationAPI = () => {
|
||||
const { engineName } = useValues(EngineViewLogic);
|
||||
const { isGenerateModalOpen } = useValues(EngineApiLogic);
|
||||
const { openGenerateModal, closeGenerateModal } = useActions(EngineApiLogic);
|
||||
const enterpriseSearchUrl = getEnterpriseSearchUrl();
|
||||
const { navigateToUrl } = useValues(KibanaLogic);
|
||||
const cloudContext = useCloudDetails();
|
||||
|
||||
const steps = [
|
||||
{
|
||||
|
@ -132,7 +140,7 @@ export const SearchApplicationAPI = () => {
|
|||
<EuiFlexGroup>
|
||||
<EuiFlexItem grow>
|
||||
<EuiCodeBlock language="markup" fontSize="m" paddingSize="m" isCopyable>
|
||||
{enterpriseSearchUrl}
|
||||
{elasticsearchUrl(cloudContext)}
|
||||
</EuiCodeBlock>
|
||||
</EuiFlexItem>
|
||||
</EuiFlexGroup>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue