Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Transform] Replace legacy elasticsearch client #84932

Merged
merged 15 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
144 changes: 0 additions & 144 deletions x-pack/plugins/transform/server/client/elasticsearch_transform.ts

This file was deleted.

46 changes: 6 additions & 40 deletions x-pack/plugins/transform/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
import {
CoreSetup,
ILegacyCustomClusterClient,
Plugin,
ILegacyScopedClusterClient,
Logger,
PluginInitializerContext,
} from 'src/core/server';
import { CoreSetup, Plugin, Logger, PluginInitializerContext } from 'src/core/server';

import { LicenseType } from '../../licensing/common/types';

import { elasticsearchJsPlugin } from './client/elasticsearch_transform';
import { Dependencies } from './types';
import { ApiRoutes } from './routes';
import { License } from './services';

declare module 'kibana/server' {
interface RequestHandlerContext {
transform?: {
dataClient: ILegacyScopedClusterClient;
};
}
}

const basicLicense: LicenseType = 'basic';

const PLUGIN = {
Expand All @@ -39,26 +23,21 @@ const PLUGIN = {
}),
};

async function getCustomEsClient(getStartServices: CoreSetup['getStartServices']) {
const [core] = await getStartServices();
return core.elasticsearch.legacy.createClient('transform', {
plugins: [elasticsearchJsPlugin],
});
}

export class TransformServerPlugin implements Plugin<{}, void, any, any> {
private readonly apiRoutes: ApiRoutes;
private readonly license: License;
private readonly logger: Logger;
private transformESClient?: ILegacyCustomClusterClient;

constructor(initContext: PluginInitializerContext) {
this.logger = initContext.logger.get();
this.apiRoutes = new ApiRoutes();
this.license = new License();
}

setup({ http, getStartServices }: CoreSetup, { licensing, features }: Dependencies): {} {
setup(
{ http, getStartServices, elasticsearch }: CoreSetup,
{ licensing, features }: Dependencies
): {} {
const router = http.createRouter();

this.license.setup(
Expand Down Expand Up @@ -94,23 +73,10 @@ export class TransformServerPlugin implements Plugin<{}, void, any, any> {
license: this.license,
});

// Can access via new platform router's handler function 'context' parameter - context.transform.client
http.registerRouteHandlerContext('transform', async (context, request) => {
this.transformESClient =
this.transformESClient ?? (await getCustomEsClient(getStartServices));
return {
dataClient: this.transformESClient.asScoped(request),
};
});

return {};
}

start() {}

stop() {
if (this.transformESClient) {
this.transformESClient.close();
}
}
stop() {}
}
11 changes: 6 additions & 5 deletions x-pack/plugins/transform/server/routes/api/privileges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ export function registerPrivilegesRoute({ router, license }: RouteDependencies)
return res.ok({ body: privilegesResult });
}

// Get cluster priviliges
// Get cluster privileges
const {
has_all_requested: hasAllPrivileges,
cluster,
} = await ctx.transform!.dataClient.callAsCurrentUser('transport.request', {
body: { has_all_requested: hasAllPrivileges, cluster },
} = await ctx.core.elasticsearch.client.asCurrentUser.transport.request({
Copy link
Member

Choose a reason for hiding this comment

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

I think this should use hasPrivileges from the security namespace.
ctx.core.elasticsearch.client.asCurrentUser.security.hasPrivileges

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 4e44a09

path: '/_security/user/_has_privileges',
method: 'POST',
body: {
Expand All @@ -43,7 +42,9 @@ export function registerPrivilegesRoute({ router, license }: RouteDependencies)
privilegesResult.hasAllPrivileges = hasAllPrivileges;

// Get all index privileges the user has
const { indices } = await ctx.transform!.dataClient.callAsCurrentUser('transport.request', {
const {
body: { indices },
} = await ctx.core.elasticsearch.client.asCurrentUser.transport.request({
Copy link
Member

Choose a reason for hiding this comment

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

same as above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 4e44a09

path: '/_security/user/_privileges',
method: 'GET',
});
Expand Down
Loading