add lidar

master
Paul Walko 2022-02-23 08:36:33 -05:00
parent ea50afa4ec
commit d3c68bc333
1 changed files with 16 additions and 15 deletions

View File

@ -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