Skip to content

Commit

Permalink
Add event hub support (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwatson484 authored Apr 14, 2023
1 parent b1f6894 commit a660d4e
Show file tree
Hide file tree
Showing 52 changed files with 1,892 additions and 8,205 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/Yelp/detect-secrets
rev: v0.14.2
rev: v1.4.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
141 changes: 122 additions & 19 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{
"custom_plugin_paths": [],
"exclude": {
"files": "package-lock.json",
"lines": null
},
"generated_at": "2020-08-16T12:22:01Z",
"version": "1.4.0",
"plugins_used": [
{
"name": "ArtifactoryDetector"
},
{
"name": "AWSKeyDetector"
},
{
"name": "ArtifactoryDetector"
"name": "AzureStorageKeyDetector"
},
{
"base64_limit": 4.5,
"name": "Base64HighEntropyString"
"name": "Base64HighEntropyString",
"limit": 4.5
},
{
"name": "BasicAuthDetector"
Expand All @@ -23,8 +21,14 @@
"name": "CloudantDetector"
},
{
"hex_limit": 3,
"name": "HexHighEntropyString"
"name": "DiscordBotTokenDetector"
},
{
"name": "GitHubTokenDetector"
},
{
"name": "HexHighEntropyString",
"limit": 3.0
},
{
"name": "IbmCloudIamDetector"
Expand All @@ -36,32 +40,131 @@
"name": "JwtTokenDetector"
},
{
"keyword_exclude": null,
"name": "KeywordDetector"
"name": "KeywordDetector",
"keyword_exclude": ""
},
{
"name": "MailchimpDetector"
},
{
"name": "NpmDetector"
},
{
"name": "PrivateKeyDetector"
},
{
"name": "SendGridDetector"
},
{
"name": "SlackDetector"
},
{
"name": "SoftlayerDetector"
},
{
"name": "SquareOAuthDetector"
},
{
"name": "StripeDetector"
},
{
"name": "TwilioKeyDetector"
}
],
"results": {},
"version": "0.14.2",
"word_list": {
"file": null,
"hash": null
}
"filters_used": [
{
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
},
{
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
"min_level": 2
},
{
"path": "detect_secrets.filters.heuristic.is_indirect_reference"
},
{
"path": "detect_secrets.filters.heuristic.is_likely_id_string"
},
{
"path": "detect_secrets.filters.heuristic.is_lock_file"
},
{
"path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string"
},
{
"path": "detect_secrets.filters.heuristic.is_potential_uuid"
},
{
"path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign"
},
{
"path": "detect_secrets.filters.heuristic.is_sequential_string"
},
{
"path": "detect_secrets.filters.heuristic.is_swagger_file"
},
{
"path": "detect_secrets.filters.heuristic.is_templated_secret"
}
],
"results": {
"docker-compose.override.yaml": [
{
"type": "Secret Keyword",
"filename": "docker-compose.override.yaml",
"hashed_secret": "3a9bc5cb5668e15fe0bcc6bfa6b5a0e6dd4d1c67",
"is_verified": false,
"line_number": 19
},
{
"type": "Azure Storage Account access key",
"filename": "docker-compose.override.yaml",
"hashed_secret": "5666459779d6a76bea73453137803fd27d8f79cd",
"is_verified": false,
"line_number": 19
}
],
"docker-compose.test.yaml": [
{
"type": "Secret Keyword",
"filename": "docker-compose.test.yaml",
"hashed_secret": "10f38898af083f58af3e236b345843571ea5b3d4",
"is_verified": false,
"line_number": 15
},
{
"type": "Secret Keyword",
"filename": "docker-compose.test.yaml",
"hashed_secret": "3a9bc5cb5668e15fe0bcc6bfa6b5a0e6dd4d1c67",
"is_verified": false,
"line_number": 20
},
{
"type": "Azure Storage Account access key",
"filename": "docker-compose.test.yaml",
"hashed_secret": "5666459779d6a76bea73453137803fd27d8f79cd",
"is_verified": false,
"line_number": 20
}
],
"docker-compose.yaml": [
{
"type": "Secret Keyword",
"filename": "docker-compose.yaml",
"hashed_secret": "d7f7a811463157aed6db3f8758aa6c93943d2a81",
"is_verified": false,
"line_number": 20
}
],
"helm/ffc-pay-web/values.yaml": [
{
"type": "Secret Keyword",
"filename": "helm/ffc-pay-web/values.yaml",
"hashed_secret": "d7f7a811463157aed6db3f8758aa6c93943d2a81",
"is_verified": false,
"line_number": 45
}
]
},
"generated_at": "2023-04-13T11:32:50Z"
}
3 changes: 1 addition & 2 deletions .snyk
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.22.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
version: v1.19.0
ignore: {}
patch: {}
8 changes: 6 additions & 2 deletions app/config/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const joi = require('joi')
const authConfig = require('./auth')
const storageConfig = require('./storage')
const messageConfig = require('./message')

// Define config schema
const schema = joi.object({
Expand All @@ -10,7 +11,8 @@ const schema = joi.object({
staticCacheTimeoutMillis: joi.number().default(7 * 24 * 60 * 60 * 1000),
googleTagManagerKey: joi.string().default(''),
paymentsEndpoint: joi.string().uri().required(),
holdReportName: joi.boolean().default('ffc-pay-hold-report.csv')
holdReportName: joi.boolean().default('ffc-pay-hold-report.csv'),
useV2Events: joi.boolean().default(true)
})

// Build config
Expand All @@ -21,7 +23,8 @@ const config = {
staticCacheTimeoutMillis: process.env.STATIC_CACHE_TIMEOUT_IN_MILLIS,
googleTagManagerKey: process.env.GOOGLE_TAG_MANAGER_KEY,
paymentsEndpoint: process.env.PAYMENTS_SERVICE_ENDPOINT,
holdReportName: process.env.HOLD_REPORT_NAME
holdReportName: process.env.HOLD_REPORT_NAME,
useV2Events: process.env.USE_V2_EVENTS
}

// Validate config
Expand All @@ -42,5 +45,6 @@ value.isTest = value.env === 'test'
value.isProd = value.env === 'production'

value.storageConfig = storageConfig
value.messageConfig = messageConfig

module.exports = value
50 changes: 50 additions & 0 deletions app/config/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const Joi = require('joi')
const { PRODUCTION } = require('../constants/environments')

const schema = Joi.object({
messageQueue: {
host: Joi.string(),
username: Joi.string(),
password: Joi.string(),
useCredentialChain: Joi.bool().default(false),
appInsights: Joi.object()
},
dataTopic: {
address: Joi.string()
},
dataQueue: {
address: Joi.string()
}
})

const config = {
messageQueue: {
host: process.env.MESSAGE_QUEUE_HOST,
username: process.env.MESSAGE_QUEUE_USER,
password: process.env.MESSAGE_QUEUE_PASSWORD,
useCredentialChain: process.env.NODE_ENV === PRODUCTION,
appInsights: process.env.NODE_ENV === PRODUCTION ? require('applicationinsights') : undefined
},
dataTopic: {
address: process.env.DATA_TOPIC_ADDRESS
},
dataQueue: {
address: process.env.DATARESPONSE_QUEUE_ADDRESS
}
}

const result = schema.validate(config, {
abortEarly: false
})

if (result.error) {
throw new Error(`The message config is invalid. ${result.error.message}`)
}

const dataTopic = { ...result.value.messageQueue, ...result.value.dataTopic }
const dataQueue = { ...result.value.messageQueue, ...result.value.dataQueue }

module.exports = {
dataTopic,
dataQueue
}
4 changes: 4 additions & 0 deletions app/constants/categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
FRN: 'frn',
CORRELATION_ID: 'correlationId'
}
5 changes: 5 additions & 0 deletions app/constants/environments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
DEVELOPMENT: 'development',
TEST: 'test',
PRODUCTION: 'production'
}
3 changes: 3 additions & 0 deletions app/constants/source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
SOURCE: 'ffc-pay-web'
}
3 changes: 3 additions & 0 deletions app/constants/type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
TYPE: 'uk.gov.defra.ffc.pay.data.request'
}
14 changes: 14 additions & 0 deletions app/messaging/create-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { SOURCE } = require('../constants/source')

const createMessage = (body, type, options) => {
return {
body,
type,
source: SOURCE,
...options
}
}

module.exports = {
createMessage
}
7 changes: 7 additions & 0 deletions app/messaging/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { sendMessage } = require('./send-message')
const { receiveMessage } = require('./receive-message')

module.exports = {
sendMessage,
receiveMessage
}
18 changes: 18 additions & 0 deletions app/messaging/receive-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { MessageReceiver } = require('ffc-messaging')

const receiveMessage = async (messageId, config) => {
let result
const receiver = new MessageReceiver(config)
await receiver.acceptSession(messageId)
const messages = await receiver.receiveMessages(1, { maxWaitTimeInMs: 50000 })
if (messages.length) {
result = messages[0].body
await receiver.completeMessage(messages[0])
}
await receiver.closeConnection()
return result
}

module.exports = {
receiveMessage
}
13 changes: 13 additions & 0 deletions app/messaging/send-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { MessageSender } = require('ffc-messaging')
const { createMessage } = require('./create-message')

const sendMessage = async (body, type, config, options) => {
const message = createMessage(body, type, options)
const sender = new MessageSender(config)
await sender.sendMessage(message)
await sender.closeConnection()
}

module.exports = {
sendMessage
}
21 changes: 21 additions & 0 deletions app/payments/get-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { v4: uuidv4 } = require('uuid')
const util = require('util')
const { TYPE } = require('../constants/type')
const config = require('../config')
const { sendMessage, receiveMessage } = require('../messaging')

const getData = async (category, value) => {
const messageId = uuidv4()
const request = { category, value }
await sendMessage(request, TYPE, config.messageConfig.dataTopic, { messageId })
console.info('Data request sent:', util.inspect(request, false, null, true))
const response = await receiveMessage(messageId, config.messageConfig.dataQueue)
if (response) {
console.info('Data response received:', util.inspect(response, false, null, true))
return response.data
}
}

module.exports = {
getData
}
10 changes: 10 additions & 0 deletions app/payments/get-payments-by-correlation-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { CORRELATION_ID } = require('../constants/categories')
const { getData } = require('./get-data')

const getPaymentsByCorrelationId = async (correlationId) => {
return getData(CORRELATION_ID, correlationId)
}

module.exports = {
getPaymentsByCorrelationId
}
Loading

0 comments on commit a660d4e

Please sign in to comment.