-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Reporting] Define shims of legacy dependencies #54082
Conversation
Pinging @elastic/kibana-reporting-services (Team:Reporting Services) |
a5cdf86
to
c931081
Compare
headers: Legacy.Request['headers']; | ||
params: Legacy.Request['params']; | ||
payload: JobParamPostPayload | GenerateExportTypePayload; | ||
query: ListQuery & GenerateQuery; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this isn't ListQuery | GenerateQuery
@elasticmachine merge upstream |
@elasticmachine merge upstream |
import { ServerFacade } from '../../types'; | ||
|
||
export function getUserFactory(server: ServerFacade) { | ||
return async (request: Legacy.Request) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function takes a Legacy request because it is called from middleware. That means we get into this code before we get into any request handlers which is where we pick the properties for RequestFacade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pgayvallet @restrry this means that I don't actually need to call request.getRawRequest
- doing so made all the code break since this isn't an actual RequestFacade :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ddf8fac added that method back, but for a different usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking loudly: why not call this function from a route handler? NP routing doesn't provide a pre-middleware mechanism at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP routing doesn't provide a pre-middleware mechanism at the moment.
Hm, if that is the case it will be a major blocker for Reporting migration.
@rudolf can you confirm whether we will be able to register routing middleware in the new platform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rudolf can you confirm whether we will be able to register routing middleware in the new platform?
ATM this is not something we are planing to provide.
Hm, if that is the case it will be a major blocker for Reporting migration.
Correct me if I'm wrong, but the whole pre-routing mechanism can easily be replaced by some wrapper around the actual route handlers. The usage would be really close to what you currently have and should not be that big of a change
Looking at your getRouteConfigFactoryReportingPre
method and usages in x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts
, the pre-routing can be moved to an higher level. This would be something similar as what we are going in src/core/server/http/router/error_wrapper.ts
const getRouteConfig = () => {
const getOriginalRouteConfig: GetRouteConfigFactoryFn = getRouteConfigFactoryReportingPre(
server
);
const routeConfigFactory: RouteConfigFactory = getOriginalRouteConfig(
({ params: { exportType } }) => exportType
);
return {
...routeConfigFactory,
validate: {
params: Joi.object({
[...]
},
};
};
// generate report
server.route({
path: `${BASE_GENERATE}/{exportType}`,
method: 'POST',
options: getRouteConfig(),
handler: async (legacyRequest: Legacy.Request, h: ReportingResponseToolkit) => {
[...]
return response;
},
});
would become something like (also adapted to NP router format)
const getRouteConfig = () => {
const getOriginalRouteConfig: GetRouteConfigFactoryFn = getRouteConfigFactoryReportingPre(
server
);
const routeConfigFactory: RouteConfigFactory = getOriginalRouteConfig(
({ params: { exportType } }) => exportType
);
return {
...routeConfigFactory,
validate: {
params: schema.object({
[...]
},
};
};
const routeConfig = getRouteConfig()
router.post(
{
path: `${BASE_GENERATE}/{exportType}`,
options: routeConfig.options
validate: routeConfig.validate,
},
routeConfig.performPreAuth(async (ctx, req, res, preAuthResult) => {
const request = makeRequestFacade(legacyRequest, preAuthResults);
....
})
);
The performPreAuth
generated from getRouteConfigFactoryReportingPre
would need some adaption from the existing code to execute all pre-handlers and either returns a response error if one throws or execute the underlying handler with an additional parameter containing the resolved objects from the pre handlers (basically what HAPI was doing itself before), but that doesn't sound like big changes, the actual pre-hook handlers would remains unchanged.
Please ping me if you want me to go a little more in-details with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ++ on any solution that will allow us to move further, and I don't see any problems with your proposals. I think there are a lot of ways to achieve the goal that the code is doing and pre-routing is just one of them.
@elasticmachine merge upstream |
aee133f
to
ddf8fac
Compare
@elasticmachine merge upstream |
management: { | ||
jobTypes: any; | ||
}; | ||
user: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw Security exports AuthenticatedUser
type
export { AuthenticatedUser } from '../common/model'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approve of this message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, when I tried that, I get an ESLint error:
@kbn/eslint/no-restricted-paths: Unexpected path "../../../plugins/security/server" imported in restricted zone. Server modules cannot be imported into client modules or shared modules.
if (!server.plugins.security) { | ||
return null; | ||
} | ||
|
||
try { | ||
return await server.plugins.security.getUser(request); | ||
} catch (err) { | ||
server.log(['reporting', 'getUser', 'debug'], err); | ||
server.log(['reporting', 'getUser', 'error'], err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch here.
@@ -27,10 +27,6 @@ export function oncePerServer(fn: ServerFn) { | |||
throw new TypeError('This function expects to be called with a single argument'); | |||
} | |||
|
|||
if (!server || typeof server.expose !== 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yesssss
@@ -54,7 +56,8 @@ export function registerGenerateFromJobParams( | |||
path: `${BASE_GENERATE}/{exportType}`, | |||
method: 'POST', | |||
options: getRouteConfig(), | |||
handler: async (request: RequestFacade, h: ReportingResponseToolkit) => { | |||
handler: async (originalRequest: Legacy.Request, h: ReportingResponseToolkit) => { | |||
const request = makeRequestFacade(originalRequest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to keep with the legacy
naming convention here? originalRequest
to legacyRequest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Saw the note below on Type's we can use for the user
, which I'm a +1 on.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* simplify serverfacade definition * simplify requestfacade definition * use the shim * makeRequestFacade * requestFacade * import sorting * originalServer * reduce loc change * remove consolelog * hacks to fix tests * ServerFacade in index * Cosmetic * remove field from serverfacade * add raw to the request * fix types * add fieldFormatServiceFactory to legacy * Pass the complete request object to sec plugin * Fix test * fix test 2 * getUser takes a legacy request * add unit test for new lib * add getRawRequest to pass to saved objects method * update test snapshot * leave a TODO comment for type import * variable rename for legacy id Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
…t-of-legacy * 'master' of github.com:elastic/kibana: (142 commits) [Vis] Move Timelion Vis to vis_type_timelion (elastic#52069) Deprecate `chrome.navlinks.update` and add documentation (elastic#54893) [ML] Single Metric Viewer: Fix time bounds with custom strings. (elastic#55045) [Vis: Default editor] EUIficate and Reactify the sidebar (elastic#49864) [Mappings editor] Fix cannot set boolean value for "null_value" param (elastic#55015) [SIEM] Adds support for apm-* to the network map (elastic#54876) [Reporting] Define shims of legacy dependencies (elastic#54082) Resolver is overflow: hidden to prevent obscured elements from showing up (elastic#55076) Upgraded EUI to 18.2.1 (elastic#55090) [Maps] Support styles on agg fields with _of_ in name (elastic#54965) Remove xpack_main requirement, it's no longer in use (elastic#55060) Fix Snapshots Policies Alignment Issue in IE11 (elastic#54866) first rule cuts (elastic#54990) [DOCS] Adds geocentroid note to coordinate map (elastic#54389) [Canvas] Fixes the Copy Post Url link (elastic#54831) Fixes bugs with full screen filters (elastic#54792) [ML] Fix decoding in the URL state (elastic#54915) Remove redundant `x-pack/typings`. (elastic#55042) [SIEM][Detection Engine] Adds critical missing status route to prepackaged rules Generate legacy vars when rendering all applications (elastic#54768) ... # Conflicts: # x-pack/plugins/translations/translations/ja-JP.json # x-pack/plugins/translations/translations/zh-CN.json
* simplify serverfacade definition * simplify requestfacade definition * use the shim * makeRequestFacade * requestFacade * import sorting * originalServer * reduce loc change * remove consolelog * hacks to fix tests * ServerFacade in index * Cosmetic * remove field from serverfacade * add raw to the request * fix types * add fieldFormatServiceFactory to legacy * Pass the complete request object to sec plugin * Fix test * fix test 2 * getUser takes a legacy request * add unit test for new lib * add getRawRequest to pass to saved objects method * update test snapshot * leave a TODO comment for type import * variable rename for legacy id Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
* upstream/master: (83 commits) [Reporting] Fix map tiles not loading by using Chrome's Remote Protocol (elastic#55137) [Data Plugin] combine autocomplete provider and suggestions provider (elastic#54451) resolves elastic#53038 - remove references to specific license levels (elastic#53858) highlighting rules should still know about url parts when in sql state (elastic#55200) [Metric] convert mocha tests to jest (elastic#54054) [skip-ci] Update vector styling docs for 7.6 UI changes and new features (elastic#55087) Fix enable API to schedule task after alert is updated (elastic#55095) chore(NA): add 7.6 branch to the list of backport branches (elastic#54998) Convert tests to jest in vis_type_timeseries/public & common folders (elastic#55023) [ML] Accessibility fix for structural markup on table rows (elastic#55075) [Mappings editor] include/exclude fields only support custom options (elastic#54949) [Vis] Move Timelion Vis to vis_type_timelion (elastic#52069) Deprecate `chrome.navlinks.update` and add documentation (elastic#54893) [ML] Single Metric Viewer: Fix time bounds with custom strings. (elastic#55045) [Vis: Default editor] EUIficate and Reactify the sidebar (elastic#49864) [Mappings editor] Fix cannot set boolean value for "null_value" param (elastic#55015) [SIEM] Adds support for apm-* to the network map (elastic#54876) [Reporting] Define shims of legacy dependencies (elastic#54082) Resolver is overflow: hidden to prevent obscured elements from showing up (elastic#55076) Upgraded EUI to 18.2.1 (elastic#55090) ...
* [Reporting] Define shims of legacy dependencies (#54082) * simplify serverfacade definition * simplify requestfacade definition * use the shim * makeRequestFacade * requestFacade * import sorting * originalServer * reduce loc change * remove consolelog * hacks to fix tests * ServerFacade in index * Cosmetic * remove field from serverfacade * add raw to the request * fix types * add fieldFormatServiceFactory to legacy * Pass the complete request object to sec plugin * Fix test * fix test 2 * getUser takes a legacy request * add unit test for new lib * add getRawRequest to pass to saved objects method * update test snapshot * leave a TODO comment for type import * variable rename for legacy id Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * update legacy to fix ts errors Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
Part of #53898
This PR defines
serverFacade
andrequestFacade
objects that use bare-bones types of the legacy dependenciesChecklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers