Skip to content
Closed
Changes from 1 commit
Commits
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 @@ -27,20 +27,23 @@ export const getCSRFToken = () => {
*/
export const getConsoleRequestHeaders = (): ConsoleRequestHeaders => {
const store = storeHandler.getStore();
if (!store) return undefined;
const state = store.getState();

const headers: ConsoleRequestHeaders = {
'X-CSRFToken': getCSRFToken(),
};

// Set impersonation headers
const { kind, name } = getImpersonate(state) || {};
if ((kind === 'User' || kind === 'Group') && name) {
// Even if we are impersonating a group, we still need to set Impersonate-User to something or k8s will complain
headers['Impersonate-User'] = name;
if (kind === 'Group') {
headers['Impersonate-Group'] = name;
// If store is available, add impersonation headers
if (store) {
const state = store.getState();

// Set impersonation headers
const { kind, name } = getImpersonate(state) || {};
if ((kind === 'User' || kind === 'Group') && name) {
// Even if we are impersonating a group, we still need to set Impersonate-User to something or k8s will complain
headers['Impersonate-User'] = name;
if (kind === 'Group') {
headers['Impersonate-Group'] = name;
}
}
}

Expand Down