-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Session storage refactoring #37992
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
Session storage refactoring #37992
Changes from all commits
c26ca80
cc4e689
db0c258
440854c
9cef7fd
71e7bf5
181d162
c6fe0e1
4d44555
13188db
ea82988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SessionStorage](./kibana-plugin-server.sessionstorage.md) > [clear](./kibana-plugin-server.sessionstorage.clear.md) | ||
|
|
||
| ## SessionStorage.clear() method | ||
|
|
||
| Clears current session. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| clear(): void; | ||
| ``` | ||
| <b>Returns:</b> | ||
|
|
||
| `void` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SessionStorage](./kibana-plugin-server.sessionstorage.md) > [get](./kibana-plugin-server.sessionstorage.get.md) | ||
|
|
||
| ## SessionStorage.get() method | ||
|
|
||
| Retrieves session value from the session storage. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| get(): Promise<T | null>; | ||
| ``` | ||
| <b>Returns:</b> | ||
|
|
||
| `Promise<T | null>` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SessionStorage](./kibana-plugin-server.sessionstorage.md) | ||
|
|
||
| ## SessionStorage interface | ||
|
|
||
| Provides an interface to store and retrieve data across requests. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| export interface SessionStorage<T> | ||
| ``` | ||
|
|
||
| ## Methods | ||
|
|
||
| | Method | Description | | ||
| | --- | --- | | ||
| | [clear()](./kibana-plugin-server.sessionstorage.clear.md) | Clears current session. | | ||
| | [get()](./kibana-plugin-server.sessionstorage.get.md) | Retrieves session value from the session storage. | | ||
| | [set(sessionValue)](./kibana-plugin-server.sessionstorage.set.md) | Puts current session value into the session storage. | | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SessionStorage](./kibana-plugin-server.sessionstorage.md) > [set](./kibana-plugin-server.sessionstorage.set.md) | ||
|
|
||
| ## SessionStorage.set() method | ||
|
|
||
| Puts current session value into the session storage. | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| set(sessionValue: T): void; | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --- | --- | --- | | ||
| | sessionValue | <code>T</code> | value to put | | ||
|
|
||
| <b>Returns:</b> | ||
|
|
||
| `void` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SessionStorageFactory](./kibana-plugin-server.sessionstoragefactory.md) > [asScoped](./kibana-plugin-server.sessionstoragefactory.asscoped.md) | ||
|
|
||
| ## SessionStorageFactory.asScoped property | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| asScoped: (request: Readonly<Request> | KibanaRequest) => SessionStorage<T>; | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SessionStorageFactory](./kibana-plugin-server.sessionstoragefactory.md) | ||
|
|
||
| ## SessionStorageFactory interface | ||
|
|
||
| SessionStorage factory to bind one to an incoming request | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| export interface SessionStorageFactory<T> | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| | Property | Type | Description | | ||
| | --- | --- | --- | | ||
| | [asScoped](./kibana-plugin-server.sessionstoragefactory.asscoped.md) | <code>(request: Readonly<Request> | KibanaRequest) => SessionStorage<T></code> | | | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
|
|
||
| import { Request, Server } from 'hapi'; | ||
| import hapiAuthCookie from 'hapi-auth-cookie'; | ||
|
|
||
| import { KibanaRequest, toRawRequest } from './router'; | ||
| import { SessionStorageFactory, SessionStorage } from './session_storage'; | ||
|
|
||
| export interface SessionStorageCookieOptions<T> { | ||
|
|
@@ -29,10 +31,10 @@ export interface SessionStorageCookieOptions<T> { | |
| } | ||
|
|
||
| class ScopedCookieSessionStorage<T extends Record<string, any>> implements SessionStorage<T> { | ||
| constructor(private readonly server: Server, private readonly request: Request) {} | ||
| constructor(private readonly server: Server, private readonly request: Readonly<Request>) {} | ||
| public async get(): Promise<T | null> { | ||
| try { | ||
| return await this.server.auth.test('security-cookie', this.request); | ||
| return await this.server.auth.test('security-cookie', this.request as Request); | ||
| } catch (error) { | ||
| return null; | ||
| } | ||
|
|
@@ -71,8 +73,9 @@ export async function createCookieSessionStorageFactory<T>( | |
| }); | ||
|
|
||
| return { | ||
| asScoped(request: Request) { | ||
| return new ScopedCookieSessionStorage<T>(server, request); | ||
| asScoped(request: Readonly<Request> | KibanaRequest) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As soon as #36509 is implemented we pass bound session storage to a consumer. There is an open question on how to restrict access to this API outside of the plugin boundaries. |
||
| const req = request instanceof KibanaRequest ? toRawRequest(request) : request; | ||
| return new ScopedCookieSessionStorage<T>(server, req); | ||
| }, | ||
| }; | ||
| } | ||
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.
issue #33775 has point to restrict access to hapi
Requestobject inregisterAuthhandler. thus we will operateKibanaRequest-ish object here