From cf61b217ad6565ba167e7c960ef93420c73fa8a7 Mon Sep 17 00:00:00 2001 From: mkornyev Date: Mon, 26 Apr 2021 16:56:35 -0400 Subject: [PATCH] BugFixes & SQS Connector Added - updated valid Auth Token - set strict_slashes = False in Flask URL Map - added SQS connector to service --> to notify Queue on Customer#Create - updated package.json w/aws sdk --- bookBFF/app.py | 3 ++- customerBFF/app.py | 3 ++- customerService/index.js | 3 +++ customerService/package.json | 1 + customerService/sqs-connector.js | 38 ++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 customerService/sqs-connector.js diff --git a/bookBFF/app.py b/bookBFF/app.py index d88fb00..653f4e3 100644 --- a/bookBFF/app.py +++ b/bookBFF/app.py @@ -4,6 +4,7 @@ from flask import Flask, request, json import requests app = Flask(__name__) +app.url_map.strict_slashes = False # CONSTANTS @@ -13,7 +14,7 @@ RECC_CIRCUIT_BREAKER_HOST = 'http://10.100.236.41:83/books' BOOK_SERVICE_HOST = 'http://10.100.144.244:3002/books' -VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxM zIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkR PTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiV ENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFl SSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLy Q7SRw' +VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxMzIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiVENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLyQ7SRw' # VALIDATIONS diff --git a/customerBFF/app.py b/customerBFF/app.py index da6d4b8..cb79bf0 100644 --- a/customerBFF/app.py +++ b/customerBFF/app.py @@ -4,6 +4,7 @@ from flask import Flask, request, json import requests app = Flask(__name__) +app.url_map.strict_slashes = False # CONSTANTS @@ -12,7 +13,7 @@ SERVER_PORT = 80 CUSTOMER_SERVICE_HOST = 'http://10.100.74.210:3001/customers' -VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxM zIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkR PTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiV ENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFl SSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLy Q7SRw' +VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxMzIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiVENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLyQ7SRw' # VALIDATIONS diff --git a/customerService/index.js b/customerService/index.js index e567b4b..f9a2801 100644 --- a/customerService/index.js +++ b/customerService/index.js @@ -2,6 +2,7 @@ const express = require('express') const bodyParser = require('body-parser') +const sqsConn = require('./sqs-connector') const port = 3000 const conn = require('./db-connector') @@ -34,6 +35,8 @@ app.post('/customers', (req, res) => { res.statusCode = 201 res.location(`${req.headers.host}/customers/${customerId}`) res.json(req.body) + + sqsConn.sendNewCustomerMessage(req.body) // PING SQS QUEUE }) }) diff --git a/customerService/package.json b/customerService/package.json index 0fedea3..5ea95e2 100644 --- a/customerService/package.json +++ b/customerService/package.json @@ -9,6 +9,7 @@ "author": "Maksym Kornyev", "license": "ISC", "dependencies": { + "aws-sdk": "^2.893.0", "express": "^4.17.1", "mysql": "^2.18.1" } diff --git a/customerService/sqs-connector.js b/customerService/sqs-connector.js new file mode 100644 index 0000000..dd1893f --- /dev/null +++ b/customerService/sqs-connector.js @@ -0,0 +1,38 @@ + +//################ IMPORTS ################ + +const AWS = require('aws-sdk'); + +AWS.config.update({region: 'us-east-1'}); +AWS.config.update({ + accessKeyId: 'AKIAWQWWY3WMZBY2YZPJ', + secretAccessKey: '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', + region: 'us-east-1' +}) + + +//################ CONSTANTS ################ + +var SQS = new AWS.SQS(); +var SQS_QUEUE_URL = "https://sqs.us-east-1.amazonaws.com/448200760729/customers" + +function sendNewCustomerMessage(messageJson) { + var sqsParams = { + MessageBody: JSON.stringify(messageJson), + QueueUrl: SQS_QUEUE_URL + } + + SQS.sendMessage(sqsParams, function(err, data) { + if(err) { + console.log(err) + } else { + console.log("SQS Ping :: New Customer Created") + console.log(data) + } + }) +} + + +//################ MODULE EXPORT ################ + +module.exports = { sendNewCustomerMessage } \ No newline at end of file