in dashboards-notebooks/public/components/helpers/reporting_context_menu_helper.tsx [92:113]
function addTenantToURL(url, userRequestedTenant) {
// build fake url from relative url
const fakeUrl = `http://opensearch.com${url}`;
const tenantKey = 'security_tenant';
const tenantKeyAndValue =
tenantKey + '=' + encodeURIComponent(userRequestedTenant);
const { pathname, search } = parse(fakeUrl);
const queryDelimiter = !search ? '?' : '&';
// The url parser returns null if the search is empty. Change that to an empty
// string so that we can use it to build the values later
if (search && search.toLowerCase().indexOf(tenantKey) > -1) {
// If we for some reason already have a tenant in the URL we skip any updates
return url;
}
// A helper for finding the part in the string that we want to extend/replace
const valueToReplace = pathname + (search || '');
const replaceWith = valueToReplace + queryDelimiter + tenantKeyAndValue;
return url.replace(valueToReplace, replaceWith);
}