From 2e9b91c2fe8cddd09063cba5f29fe982846fb52f Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 20 Jun 2022 13:52:00 +0200 Subject: [PATCH] basic login --- main.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index b8cc4ce..1999849 100644 --- a/main.js +++ b/main.js @@ -15,7 +15,6 @@ if (!fs.existsSync(configFile)) { } const findAll = `Client`; -const apiKey = `Bearer eyJrIjoickI3WVBab0lscldRdk9JV29YYUFKMEdqUDl6UmsyaHIiLCJuIjoiZ3JhZmFuYS1maW5kIiwiaWQiOjF9`; const config = require(configFile); const grafanaUrl = config.grafanaUrl; @@ -32,13 +31,16 @@ let nameVariables = new Array; const regexRawSQL = new RegExp(findAll, 'i'); +const user = `guillermo`; + async function main(){ const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout - });/* + }); + const answer = await new Promise(resolve => { rl.question(colors.yellow('Enter your password: '), resolve); }); @@ -46,17 +48,22 @@ async function main(){ console.error(`You need to put a password`.red); process.exit(0); } + const passw = `${answer}`; + + const credentials = `Basic ` + Buffer.from(`${user}:${passw}`).toString('base64'); rl.close(); - */ + console.clear(); console.log(colors.green.bold(`-------------------- Starting process --------------------`)); let responseAllUID = await fetch(urlDashboards, { method: "GET", headers: { - "Authorization": apiKey, + "Authorization": credentials, + "Content-Type" : "application/json" } }); + let allUID = await responseAllUID.json(); for (let i=0; i < allUID.length; i++) { @@ -65,7 +72,7 @@ async function main(){ let response = await fetch(url, { method: "GET", headers: { - "Authorization": apiKey, + "Authorization": credentials, } }); let data = await response.json();