Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ export const ConnectorDeployment: React.FC = () => {
return <></>;
}

const hasApiKey = !!(connector.api_key_id ?? generatedData?.apiKey);
const hasApiKey = !!(connector.api_key_id ?? generatedData?.apiKey ?? apiKeyData);

const isWaitingForConnector = !connector.status || connector.status === ConnectorStatus.CREATED;
const apiKey = generatedData?.apiKey || apiKeyData || apiKeyMetaData;
const apiKey = apiKeyData || generatedData?.apiKey || apiKeyMetaData;

return (
<EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { SavedObjectsClient } from '@kbn/core/server';
import type { ElasticsearchErrorDetails } from '@kbn/es-errors';

import { i18n } from '@kbn/i18n';
import type { ConnectorStatus, FilteringRule, Connector } from '@kbn/search-connectors';
import type {
ConnectorStatus,
FilteringRule,
Connector,
ConnectorDocument,
} from '@kbn/search-connectors';
import {
CONNECTORS_INDEX,
cancelSync,
Expand Down Expand Up @@ -1315,4 +1320,67 @@ export function registerConnectorRoutes({
});
})
);

router.post(
{
path: '/internal/content_connectors/indices/{indexName}/api_key',
security: {
authz: {
enabled: false,
reason: 'This route delegates authorization to the scoped ES client',
},
},
validate: {
params: schema.object({
indexName: schema.string(),
}),
body: schema.object({
is_native: schema.boolean(),
}),
},
},
elasticsearchErrorHandler(log, async (context, request, response) => {
const indexName = decodeURIComponent(request.params.indexName);
const { client } = (await context.core).elasticsearch;
const [_core, start] = await getStartServices();
const isAgentlessEnabled = start.fleet?.agentless?.enabled === true;

const connectorResult = await client.asCurrentUser.search<ConnectorDocument>({
index: CONNECTORS_INDEX,
query: { term: { index_name: indexName } },
});
Comment on lines +1348 to +1351

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we passed the connector id here so we didn't have to search like this. But I don't think we should get into a refactor for this bug fix.

const connector = connectorResult.hits.hits[0];
if (!connector) {
return createError({
errorCode: ErrorCode.RESOURCE_NOT_FOUND,
message: i18n.translate(
'xpack.contentConnectors.routes.indices.apiKey.connectorNotFound',
{
defaultMessage: 'No connector found for index {indexName}.',
values: { indexName },
}
),
response,
statusCode: 404,
});
}

const apiKeyResult = await generateApiKey(
client,
indexName,
request.body.is_native,
isAgentlessEnabled
);

return response.ok({
body: {
api_key: apiKeyResult.api_key,
encoded: apiKeyResult.encoded,
id: apiKeyResult.id,
name: apiKeyResult.name,
},
Comment thread
meghanmurphy1 marked this conversation as resolved.
Outdated
headers: { 'content-type': 'application/json' },
});
})
);
}
1 change: 1 addition & 0 deletions x-pack/platform/plugins/shared/streams/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ dependsOn:
- '@kbn/esql-language'
- '@kbn/core-elasticsearch-server-mocks'
- '@kbn/core-logging-server-mocks'
- '@kbn/logging-mocks'
tags:
- plugin
- prod
Expand Down