-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send data_source_id from client
Signed-off-by: suzhou <[email protected]>
- Loading branch information
1 parent
b91ac6c
commit 5a69d95
Showing
4 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { set } from "lodash"; | ||
import { CoreStart, HttpFetchOptionsWithPath } from "opensearch-dashboards/public"; | ||
|
||
export class MDSIntercept { | ||
private pluginId: string; | ||
private http: CoreStart["http"]; | ||
private getDataSourceId: () => string; | ||
private interceptDestroyHandler: (() => void) | undefined; | ||
constructor(config: { pluginId: string; http: CoreStart["http"]; getDataSourceId: () => string }) { | ||
this.pluginId = config.pluginId; | ||
this.http = config.http; | ||
this.getDataSourceId = config.getDataSourceId; | ||
} | ||
private interceptRequest(fetchOptions: HttpFetchOptionsWithPath) { | ||
set(fetchOptions, `headers._${this.pluginId}_data_source_id_`, this.getDataSourceId()); | ||
return fetchOptions; | ||
} | ||
public start() { | ||
this.interceptDestroyHandler = this.http.intercept({ | ||
request: this.interceptRequest.bind(this), | ||
}); | ||
} | ||
public destroy() { | ||
this.interceptDestroyHandler?.(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters