Conversation
src/core/server/http/router/route.ts
Outdated
| authRequired?: boolean; | ||
|
|
||
| /** | ||
| * Additional meta-data information to attach fot the route. |
|
ACK: will take a look on Friday or Monday at the latest. |
💔 Build Failed |
azasypkin
left a comment
There was a problem hiding this comment.
Approach looks good to me, but can you please add a usage example into PR description? Just to have a better idea how it's going to be used.
src/core/server/http/router/route.ts
Outdated
| /** | ||
| * Additional meta-data information to attach fot the route. | ||
| */ | ||
| tags?: string[]; |
There was a problem hiding this comment.
question: do you think using ReadonlySet<string> would introduce too much unnecessary friction? I usually prefer Map and Set where uniqueness is implied unless it really reduces API ergonomics.
There was a problem hiding this comment.
I think using Set could be error-prone because strings are iterable in js
new Set('my:tag') // wrong declaration, don't throw
new Set(['my:tag']) // correct declaration, but not intuitiveThere was a problem hiding this comment.
Yeah, it's arguable and may not be the best choice in some cases, don't have a strong opinion on that, feel free to pick whatever you think is better.
P.S. We decided to move with Set for a similar thing in EcnrytpedSavedObjects to signify uniqueness of the setting. It's not super important, just slowly transforming my coding habits towards string[] ---> Set<string> and Record<string, string> ---> Map<string, string> where appropriate 🙂
| import { Request, ResponseToolkit } from 'hapi'; | ||
| import { merge } from 'lodash'; | ||
|
|
||
| type DeepPartial<T> = T extends any[] |
There was a problem hiding this comment.
@elastic/kibana-platform would be useful to declare some type helpers on project level or add a ready toolkit.
💔 Build Failed |
|
Pinging @elastic/kibana-platform |
|
Pinging @elastic/kibana-security |
💔 Build Failed |
|
retest |
💔 Build Failed |
| */ | ||
| import { CapabilitiesService, CapabilitiesStart } from './capabilities_service'; | ||
| import { deepFreeze } from '../../utils/deep_freeze'; | ||
| import { deepFreeze } from '../../../utils/'; |
There was a problem hiding this comment.
Remove trailing slash for import consistency.
There was a problem hiding this comment.
let's introduce linter rule explicitly if it's important. imo it doesn't make sense to perform manual check on every PR
related #36829 (comment)
| import { DiscoveredPlugin, PluginName } from '../../server'; | ||
| import { UiSettingsState } from '../ui_settings'; | ||
| import { deepFreeze } from '../utils/deep_freeze'; | ||
| import { deepFreeze } from '../../utils/'; |
There was a problem hiding this comment.
Remove trailing slash for import consistency.
| */ | ||
|
|
||
| import { deepFreeze } from '../../../deep_freeze'; | ||
| import { deepFreeze } from '../../../../../utils/deep_freeze'; |
There was a problem hiding this comment.
The other imports for deepFreeze pull this directly off of utils instead of utils/deep_freeze; did you want to do that here as well?
There was a problem hiding this comment.
this integration test compiles TS and declares its own tsconfig https://github.com/restrry/kibana/blob/5128c9bf3d2fc508d95d27414b912e1d12be5a55/src/core/public/utils/integration_tests/deep_freeze.test.ts
if I import ../../../../../utils/ TS compilation fails due to different setup for the Kibana project and test. I don't think we should keep both in sync, so I just narrowed import to the specific file.
|
|
||
| function createRawRequestMock(customization: DeepPartial<Request> = {}) { | ||
| return merge( | ||
| {}, |
There was a problem hiding this comment.
Using 2 anonymous objects here is redundant, so you can remove the first one:
return merge(
{
headers: {},
path: '/',
route: { settings: {} },
raw: {
req: {
url: '/',
},
},
},
customization
) as Request;There was a problem hiding this comment.
merge mutates the destination object https://lodash.com/docs/3.10.1#merge
if we mutate default value, the next test could be affected by the result of the previous createRawRequestMock call
| } as any, | ||
| undefined | ||
| ); | ||
| return KibanaRequest.from(httpServerMock.createRawRequest(), undefined); |
There was a problem hiding this comment.
Typically, passing undefined to a function is redundant, can this just be:
return KibanaRequest.from(httpServerMock.createRawRequest());There was a problem hiding this comment.
KibanaRequest.from declaration marks the second parameter as required
https://github.com/restrry/kibana/blob/5128c9bf3d2fc508d95d27414b912e1d12be5a55/src/core/server/http/router/request.ts#L49
I suspect it was done to force the caller to specify route schema. Although this method is used only by Kibana, so probably we can make it optional. @azasypkin
There was a problem hiding this comment.
Although this method is used only by Kibana, so probably we can make it optional.
Yeah, it seems we should do that. And probably mark it as @internal?
There was a problem hiding this comment.
there is no way to make a method as truly @internal on @public class. instead we can declare from method as an internal function, not a class static method
| path: this.request.path, | ||
| method: this.request.method, | ||
| options: { | ||
| authRequired: this.request.route.settings.auth !== false, |
There was a problem hiding this comment.
If auth is always a boolean, could this instead be:
authRequired: this.request.route.settings.auth,There was a problem hiding this comment.
- it's not boolean.
false | string | RouteOptionsAccess; - we invert the logic. authRequired always
trueif not specifiedfalseexplicitly
| * The set of common HTTP methods supported by Kibana routing. | ||
| * @public | ||
| * */ | ||
| export type RouteMethod = 'get' | 'post' | 'put' | 'delete'; |
There was a problem hiding this comment.
A couple questions:
- Why should these now be lower case? It looks like it would lead to less diff changes in this patch.
- Why not add
'patch' | 'options'to this list since they are also used in:method: RouteMethod | 'patch' | 'options';
There was a problem hiding this comment.
- current codebase relays on method names in lower case, because it's a default in hapi. changing to the upper case would lead to bugs during migration.
- the router doesn't support PATCH and OPTIONS methods as of now and typing should reflect this fact
💔 Build Failed |
💚 Build Succeeded |
|
Do we feel that sticking to the way that "tags" are implemented currently and replicating them in the new platform is strategically advantageous? At the time the I don't want to completely derail this effort though, if the legacy and new platform's interaction makes using the same approach across both strategically advantageous in the short-term. |
|
retest |
💔 Build Failed |
|
@elastic/kibana-platform could someone review, please? @eliperelman is on vacation |
rudolf
left a comment
There was a problem hiding this comment.
Looks good. I made a docs language suggestion, but if you accept it you'll need to re-generate the docs.
|
@skaapgif ok, then I will update wording manually. thanks ❤️ |
💚 Build Succeeded |
* expose route info in KibanaRequest * update mocks in test * make tags readonly, getRouteInfo is private method * add mocks for hapi internals * mode deepFreeze to core utils level as it env agnostic * freeze route props * fix typo * add tests for route options * fix integration tests. deep_freeze was moved under core utils * add comments, expose public types and regenerate docs * address comment. remove unnecessary async in route handlers * make routeSchema optional instead of union with undefined * @skaapgif improvements * update docs
* expose route info in KibanaRequest * update mocks in test * make tags readonly, getRouteInfo is private method * add mocks for hapi internals * mode deepFreeze to core utils level as it env agnostic * freeze route props * fix typo * add tests for route options * fix integration tests. deep_freeze was moved under core utils * add comments, expose public types and regenerate docs * address comment. remove unnecessary async in route handlers * make routeSchema optional instead of union with undefined * @skaapgif improvements * update docs
Summary
Related discussion that may require changing the whole approach to authorization: #38009
2 main changes
KibanaRequestexposes route configthere are tons of changes in docs after I merged master and run
yarn core:acceptApiChanges. looks like the reason for this is@microsoft/api-documenterupdate #37759Probably it's easier to review commit by commit
Checklist
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