From 1b13ff746c687d519f4074f1902c6e9558247af0 Mon Sep 17 00:00:00 2001 From: Karthik Venkateswaran Date: Thu, 24 Jan 2019 16:11:09 +0530 Subject: [PATCH 1/2] Passes x-hasura-* headers as part of the user object in the object and removes it from reqHeader as analyze is admin only endpoint --- console/src/components/ApiExplorer/Actions.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/console/src/components/ApiExplorer/Actions.js b/console/src/components/ApiExplorer/Actions.js index 98acdd8764526..370d1c4802adb 100644 --- a/console/src/components/ApiExplorer/Actions.js +++ b/console/src/components/ApiExplorer/Actions.js @@ -242,6 +242,18 @@ const analyzeFetcher = (url, headers, analyzeApiChange) => { 'x-hasura-role': 'admin', }; } + + // Check if x-hasura-role is available in some form in the headers + const totalHeaders = Object.keys(reqHeaders); + for (let i = 0; i < totalHeaders.length; i += 1) { + // If header has x-hasura-* + const lHead = totalHeaders[i].toLowerCase(); + if (lHead.indexOf('x-hasura-') !== -1) { + user[lHead] = reqHeaders[totalHeaders[i]]; + delete reqHeaders[totalHeaders[i]]; + } + } + editedQuery.user = user; return fetch(`${url}/explain`, { method: 'post', From 86b907cde3b0fc56171914a2d1e925fd4f3db723 Mon Sep 17 00:00:00 2001 From: Karthik Venkateswaran Date: Thu, 24 Jan 2019 17:39:12 +0530 Subject: [PATCH 2/2] Refactored a bit --- console/src/components/ApiExplorer/Actions.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/console/src/components/ApiExplorer/Actions.js b/console/src/components/ApiExplorer/Actions.js index 370d1c4802adb..4e8eb8371333a 100644 --- a/console/src/components/ApiExplorer/Actions.js +++ b/console/src/components/ApiExplorer/Actions.js @@ -245,14 +245,14 @@ const analyzeFetcher = (url, headers, analyzeApiChange) => { // Check if x-hasura-role is available in some form in the headers const totalHeaders = Object.keys(reqHeaders); - for (let i = 0; i < totalHeaders.length; i += 1) { + totalHeaders.forEach((t) => { // If header has x-hasura-* - const lHead = totalHeaders[i].toLowerCase(); - if (lHead.indexOf('x-hasura-') !== -1) { - user[lHead] = reqHeaders[totalHeaders[i]]; - delete reqHeaders[totalHeaders[i]]; + const lHead = t.toLowerCase(); + if (lHead.slice(0, 'x-hasura-'.length) === 'x-hasura-') { + user[lHead] = reqHeaders[t]; + delete reqHeaders[t]; } - } + }); editedQuery.user = user; return fetch(`${url}/explain`, {