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

[Obs AI Assistant] Fall back to request.url for kibana function #173717

Merged
merged 20 commits into from
Dec 22, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
55a3f2c
[Obs AI Assistant] Fall back to request.url for kibana function
dgieselaar Dec 18, 2023
bdbeef9
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Dec 18, 2023
ce5f20b
Merge branch 'main' into obs-ai-assistant-kibana-ssl
justinkambic Dec 18, 2023
a8c713c
Merge branch 'main' into obs-ai-assistant-kibana-ssl
kibanamachine Dec 20, 2023
17f7be6
Merge branch 'main' into obs-ai-assistant-kibana-ssl
kibanamachine Dec 20, 2023
5763a32
Allow unauthorized certs
dgieselaar Dec 20, 2023
6639902
Merge branch 'obs-ai-assistant-kibana-ssl' of github.com:dgieselaar/k…
dgieselaar Dec 20, 2023
3e0fccc
Import it
dgieselaar Dec 20, 2023
6a55a78
Remove certs
dgieselaar Dec 20, 2023
93fbe3e
Less headers
dgieselaar Dec 20, 2023
465136a
Logging
dgieselaar Dec 20, 2023
9d6007b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Dec 20, 2023
695251f
Merge branch 'obs-ai-assistant-kibana-ssl' of github.com:dgieselaar/k…
dgieselaar Dec 21, 2023
1376557
Merge branch 'main' of github.com:elastic/kibana into obs-ai-assistan…
dgieselaar Dec 21, 2023
da6968d
More logging
dgieselaar Dec 22, 2023
8175c63
Merge branch 'main' of github.com:elastic/kibana into obs-ai-assistan…
dgieselaar Dec 22, 2023
4e7d356
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Dec 22, 2023
2ee5f5f
Use origin to call Kibana API
dgieselaar Dec 22, 2023
3519825
Merge branch 'obs-ai-assistant-kibana-ssl' of github.com:dgieselaar/k…
dgieselaar Dec 22, 2023
db0d3ce
Remove debugging statements
dgieselaar Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import axios from 'axios';
import { format } from 'url';
import { format, parse } from 'url';
import { castArray, first, pick, pickBy } from 'lodash';
import type { FunctionRegistrationParameters } from '.';

export function registerKibanaFunction({
Expand Down Expand Up @@ -51,28 +52,45 @@ export function registerKibanaFunction({
({ arguments: { method, pathname, body, query } }, signal) => {
const { request } = resources;

const {
protocol,
host,
username,
password,
pathname: pathnameFromRequest,
} = request.rewrittenUrl!;
const { protocol, host, pathname: pathnameFromRequest } = request.rewrittenUrl || request.url;

const origin = first(castArray(request.headers.origin));

const nextUrl = {
host,
protocol,
username,
password,
...(origin ? pick(parse(origin), 'host', 'protocol') : {}),
pathname: pathnameFromRequest.replace(
'/internal/observability_ai_assistant/chat/complete',
pathname
),
query,
};

const copiedHeaderNames = [
'accept-encoding',
'accept-language',
'accept',
'content-type',
'cookie',
'kbn-build-number',
'kbn-version',
'origin',
'referer',
'user-agent',
'x-elastic-internal-origin',
'x-kbn-context',
];

const headers = pickBy(request.headers, (value, key) => {
return (
copiedHeaderNames.includes(key.toLowerCase()) || key.toLowerCase().startsWith('sec-')
);
});

return axios({
method,
headers: request.headers,
headers,
url: format(nextUrl),
data: body ? JSON.stringify(body) : undefined,
signal,
Expand Down
Loading