Skip to content

Commit

Permalink
[Search] Add beats/logstash api key format (#168124)
Browse files Browse the repository at this point in the history
## Summary

This adds a beast/logstash format to the API key in getting started in
Serverless Search.

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
sphilipse and kibanamachine authored Oct 6, 2023
1 parent b3b5d10 commit ec31315
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
export const MANAGEMENT_API_KEYS = '/app/management/security/api_keys';

// Server Routes
export const CREATE_API_KEY_PATH = '/internal/security/api_key';
export const CREATE_API_KEY_PATH = '/internal/serverless_search/api_key';
export const FETCH_INDICES_PATH = '/internal/serverless_search/indices';
export const CREATE_CONNECTOR_PATH = '/internal/connectors';
export const CREATE_CONNECTORS_PATH = '/internal/connectors';
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ApiKey } from '@kbn/security-plugin/common';
import { useQuery } from '@tanstack/react-query';
import React, { useState } from 'react';
import { useKibanaServices } from '../../hooks/use_kibana';
import { MANAGEMENT_API_KEYS } from '../../routes';
import { MANAGEMENT_API_KEYS } from '../../../../common/routes';
import { CreateApiKeyFlyout } from './create_api_key_flyout';
import { CreateApiKeyResponse } from './types';
import './api_key.scss';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from '../../../../common/i18n_string';
import { CreateAPIKeyArgs } from '../../../../common/types';
import { useKibanaServices } from '../../hooks/use_kibana';
import { CREATE_API_KEY_PATH } from '../../routes';
import { CREATE_API_KEY_PATH } from '../../../../common/routes';
import { isApiError } from '../../../utils/api';
import { BasicSetupForm, DEFAULT_EXPIRES_VALUE } from './basic_setup_form';
import { MetadataForm } from './metadata_form';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface CreateApiKeyResponse {
expiration?: number;
api_key: string;
encoded?: string;
beats_logstash_format: string;
}
21 changes: 21 additions & 0 deletions x-pack/plugins/serverless_search/server/routes/api_key_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { schema } from '@kbn/config-schema';
import { RouteDependencies } from '../plugin';

export const registerApiKeyRoutes = ({ logger, router, security }: RouteDependencies) => {
Expand All @@ -27,4 +28,24 @@ export const registerApiKeyRoutes = ({ logger, router, security }: RouteDependen
});
}
);

router.post(
{
path: '/internal/serverless_search/api_key',
validate: {
body: schema.any(),
},
},
async (context, request, response) => {
const result = await security.authc.apiKeys.create(request, request.body);
if (result) {
const apiKey = { ...result, beats_logstash_format: `${result.id}:${result.api_key}` };
return response.ok({ body: apiKey });
}
return response.customError({
statusCode: 502,
body: 'Could not retrieve current user, security plugin is not ready',
});
}
);
};

0 comments on commit ec31315

Please sign in to comment.