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

Document how to extend request handler context #53271

Merged

Conversation

mshustov
Copy link
Contributor

Summary

Closes #47689
Document what is provided via request handler context & how to extend it with custom API.

@mshustov mshustov added chore Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes v7.6.0 labels Dec 17, 2019
@mshustov mshustov requested a review from a team as a code owner December 17, 2019 10:41
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@mshustov
Copy link
Contributor Author

retest

@mshustov
Copy link
Contributor Author

retest

Comment on lines +3 to +5
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [Logger](./kibana-plugin-server.logger.md) > [get](./kibana-plugin-server.logger.get.md)

## Logger.get() method
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about this one

Comment on lines +1472 to +1481
core.http.registerRouteHandlerContext('myPlugin', (context, req, res) => {
return { client: client.asScoped(req) };
});

router.get(
{ path: '/api/my-plugin/', validate },
async (context, req, res) => {
const data = await context.myPlugin.client.callAsCurrentUser('endpoint');
...
}
Copy link
Contributor

@pgayvallet pgayvallet Dec 17, 2019

Choose a reason for hiding this comment

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

TIL

Does that works without casting context to any though ?

export type RequestHandler<
  P extends ObjectType,
  Q extends ObjectType,
  B extends ObjectType | Type<Buffer> | Type<Stream>,
  Method extends RouteMethod = any
> = (
  context: RequestHandlerContext,
  request: KibanaRequest<TypeOf<P>, TypeOf<Q>, TypeOf<B>, Method>,
  response: KibanaResponseFactory
) => IKibanaResponse<any> | Promise<IKibanaResponse<any>>;
export interface RequestHandlerContext {
  core: {
    savedObjects: {
      client: SavedObjectsClientContract;
    };
    elasticsearch: {
      dataClient: IScopedClusterClient;
      adminClient: IScopedClusterClient;
    };
    uiSettings: {
      client: IUiSettingsClient;
    };
  };
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, I did not see the declare module 'src/core/server' statement

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mshustov mshustov merged commit ecf8657 into elastic:master Dec 19, 2019
@mshustov mshustov deleted the issue-47689-document-context-extension branch December 19, 2019 09:12
mbondyra added a commit to mbondyra/kibana that referenced this pull request Dec 19, 2019
…f github.com:mbondyra/kibana into IS-51910_share-lens-change-index-pattern-in-discover

* 'IS-51910_share-lens-change-index-pattern-in-discover' of github.com:mbondyra/kibana:
  [Discover] Remove angular field filter template code (elastic#53513)
  [APM] Improve table and other panel loading states (elastic#53459)
  Security/Spaces - cleanup react warnings (elastic#53287)
  Revert "NP licensing add functional tests (elastic#53002)" (elastic#53577)
  NP licensing add functional tests (elastic#53002)
  fix onLicenseInfoChange callback to be called on update (elastic#53559)
  Document how to extend request handler context (elastic#53271)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported chore Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document how to extend context with elasticsearch.createCluster result
3 participants