From d3c68bc333e9d8bd8371ff370fc463d1eb0ec03c Mon Sep 17 00:00:00 2001 From: Paul Walko Date: Wed, 23 Feb 2022 08:36:33 -0500 Subject: [PATCH] add lidar --- index.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 3ebb3c9..04860be 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3'); const KV = { 'skydusky': SKYDUSKY }; +const noauth = ['lidar']; /************************************************************/ /* @@ -69,12 +70,10 @@ function BadRequestException(reason) { * @throws {UnauthorizedException} */ async function verifyCredentials(store, user, pass) { - console.log(`STORE: ${store}`) if (!KV.hasOwnProperty(store)) { throw new UnauthorizedException('Invalid password.'); } const KVpass = await KV[store].get(user); - console.log(`PASS: ${KVpass}`) if (KVpass === 'null' || KVpass !== pass) { throw new UnauthorizedException('Invalid password.'); } @@ -89,20 +88,22 @@ async function handleRequest(request) { const path = requestURL.pathname.substring(1); const area = path.split('/')[0]; - // Prompt login - if (!request.headers.has('Authorization')) { - return new Response('Please login.', { - status: 401, - headers: { 'WWW-Authenticate': `Basic realm="${area.toUpperCase()}", charset="UTF-8"` } - }); - } + if (!noauth.includes(area)) { + // Prompt login + if (!request.headers.has('Authorization')) { + return new Response('Please login.', { + status: 401, + headers: { 'WWW-Authenticate': `Basic realm="${area.toUpperCase()}", charset="UTF-8"` } + }); + } - // Verify login - const { user, pass } = basicAuthentication(request); - try { - await verifyCredentials(area, user, pass); - } catch (e) { - return e; + // Verify login + const { user, pass } = basicAuthentication(request); + try { + await verifyCredentials(area, user, pass); + } catch (e) { + return e; + } } // S3 Client