Skip to content

Commit

Permalink
IMplemented xauth
Browse files Browse the repository at this point in the history
  • Loading branch information
fu351 committed Dec 15, 2023
1 parent ffe4d52 commit 06a77fd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
7 changes: 5 additions & 2 deletions delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ router.delete('/package/:id', (req, res) => {
//delete every version of a package in the s3 bucket that matches the package name
router.delete('/package/byName/:name', (req, res) => {
const packageName = req.params.name;
const xAuth = req.headers['x-authorization'];
if ( !packageName || !xAuth) {
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
if ( !packageName || !xauth) {
return res.status(400).json('There is missing field(s) in the PackageName/AuthenticationToken or it is formed improperly, or the AuthenticationToken is invalid.');
}
const params = {
Expand Down
4 changes: 3 additions & 1 deletion reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ router.delete('/reset', async (req, res) => {
console.log('Reset route being used');
const s3 = new AWS.S3();
const bucketName = '461testbucket'; // Replace with your S3 bucket name

if (!req.body['x-authorization']) {
return res.status(401).json({ error: 'Missing x-authorization header' });
}
try {
// List all objects in the specified folder
const data = await s3.listObjectsV2({ Bucket: bucketName }).promise();
Expand Down
26 changes: 14 additions & 12 deletions search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ router.get('/package/:id', (req, res) => {
if (!packageID) {
return res.status(400).json({ error: 'Missing package ID' });
}
/* if (xauth != "0") {
if (xauth != "0") {
return res.status(400).json({ error: 'You do not have permission to download the package.' });
} */
}
if (!xauth) {
return res.status(400).json({ error: 'Missing AuthenticationToken' });
}
Expand Down Expand Up @@ -71,9 +71,9 @@ router.get('/package/:id', (req, res) => {
router.get('/package/byName/:name', async (req, res) => {
console.log('search by name happening');
const packageName = req.params.name;
const xAuth = req.headers['x-authorization'];
if (!xAuth) {
return res.status(400).json({ error: 'Missing AuthenticationToken' });
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
if (!packageName) {
return res.status(400).json({ error: 'Missing package name' });
Expand Down Expand Up @@ -109,9 +109,12 @@ router.post('/package/byRegEx', async (req, res) => {
console.log('search by regex happening');
//get the regular expression from the body
const regEx = new RegExp(req.body.RegEx);
const xAuth = req.headers['x-authorization'];
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
console.log(regEx);
if (!xAuth || !regEx) {
if (!xauth || !regEx) {
return res.status(400).json("There is missing field(s) in the PackageRegEx/AuthenticationToken or it is formed improperly, or the AuthenticationToken is invalid.");
}
const params = {
Expand Down Expand Up @@ -169,11 +172,10 @@ router.post('/packages', async (req, res) => {
console.log('error1');
return res.status(400).json("Missing package name");
}
const xAuth = req.headers['X-authorization'];
// if (!xAuth) {
// console.log('error2');
// return res.status(400).json("Missing AuthenticationToken");
// }
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
for (const req_query of req.body ){
const packageName = req_query.Name;
console.log(req_query);
Expand Down
16 changes: 16 additions & 0 deletions upload_update_download_rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ router.post('/package', upload.single('file'), async (req, res) => { //upload pa
try {
const packageData = req.body;
let content = packageData.Content;
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
if (!packageData) {
console.log('No package data uploaded.');
return res.status(400).json({ error: 'No package data uploaded' });
Expand Down Expand Up @@ -305,6 +309,10 @@ router.post('/package', upload.single('file'), async (req, res) => { //upload pa
//Assuming that the package will be based on the package ID and will be a path parameter
router.get('/download/:id', async (req, res) => { //download package from bucket
const ID = req.params.id; // Get the selected package name
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
const params = {
Bucket: '461testbucket',
Key: `packages/${ID}.zip`, // Use the selected package name to generate the Object key
Expand Down Expand Up @@ -333,6 +341,10 @@ router.put('/package/:id', async (req, res) => { //update package
console.log('package update being used');
const packageId = req.params.id;
const { Name, Version, ID } = req.body.metadata;
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
let { Content, URL } = req.body.data;
if(!Name || !Version || !ID || (!Content & !URL) || !packageId) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
Expand Down Expand Up @@ -440,6 +452,10 @@ router.put('/package/:id', async (req, res) => { //update package
router.get('/package/:id/rate', async (req, res) => { //rate package
console.log('package rate being used');
const packageId = req.params.id;
const xauth = req.headers['x-authorization'];
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
console.log("ID",packageId);
//There is missing field(s) in the PackageID/AuthenticationToken or it is formed improperly, or the AuthenticationToken is invalid. return 400 error
if (!packageId) {
Expand Down

0 comments on commit 06a77fd

Please sign in to comment.