Skip to content

Commit

Permalink
Tidy env vars for redeployment of version 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
pmshaw15 committed Dec 15, 2023
1 parent 27e911b commit de75776
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 58 deletions.
11 changes: 10 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ DEFRA_USERNAME=smart
DEFRA_PASSWORD=JDJhJDEwJGJkTmxoazdRZ2pHckxybkNxcjNtWWUxZ21qcHNObS9kQVUxN2xjYUdOWms5eS9HaS9XaEt5

# Flag to toggle the incident submission to backend: true / false
SUBMIT_INCIDENT=true
SUBMIT_INCIDENT=true

# Endpoints for service bus
FISHING_CONNECTION_STRING=''
WATER_CONNECTION_STRING=''
FISHING_QUEUE=''
WATER_QUEUE=''

# Ordnance Survey key
OS_KEY=''
4 changes: 2 additions & 2 deletions server/routes/water-quality/contact.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views /** ,RedisKeys */ } = require('../../utils/constants')
// const RedisService = require('../../services/redis.service')

const handlers = {
get: (request, h) => {
Expand Down
4 changes: 2 additions & 2 deletions server/routes/water-quality/location-address-option.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views /** , RedisKeys */ } = require('../../utils/constants')
// const RedisService = require('../../services/redis.service')

const handlers = {
get: (request, h) => {
Expand Down
3 changes: 1 addition & 2 deletions server/routes/water-quality/location-desc-option.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views } = require('../../utils/constants')

const handlers = {
get: (request, h) => {
Expand Down
3 changes: 1 addition & 2 deletions server/routes/water-quality/location-map-or-desc.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views } = require('../../utils/constants')

const handlers = {
get: (request, h) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { Paths, Views, RedisKeys, SirpRedisKeys } = require('../../utils/constants')
const { Paths, Views, SirpRedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')

const handlers = {
Expand Down
4 changes: 2 additions & 2 deletions server/routes/water-quality/past.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views /** , RedisKeys */ } = require('../../utils/constants')
// const RedisService = require('../../services/redis.service')

const handlers = {
get: (request, h) => {
Expand Down
4 changes: 2 additions & 2 deletions server/routes/water-quality/recurring.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views /** , RedisKeys */ } = require('../../utils/constants')
// const RedisService = require('../../services/redis.service')

const handlers = {
get: (request, h) => {
Expand Down
1 change: 0 additions & 1 deletion server/routes/water-quality/smell-desc.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const {
Paths,
Views,
RedisKeys,
WQSirpRedisKeys
} = require('../../utils/constants')

Expand Down
3 changes: 1 addition & 2 deletions server/routes/water-quality/volunteer-media-contact.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views } = require('../../utils/constants')
const IncidentUtilsService = require('../../services/incident.service')
const ASBService = require('../../services/asb.send')
const config = require('../../utils/config')
Expand Down
3 changes: 1 addition & 2 deletions server/routes/water-quality/when.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const { Paths, Views, RedisKeys } = require('../../utils/constants')
const RedisService = require('../../services/redis.service')
const { Paths, Views } = require('../../utils/constants')

const handlers = {
get: (request, h) => {
Expand Down
13 changes: 7 additions & 6 deletions server/services/asb.send.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const config = require('../utils/config')
const { ServiceBusClient } = require('@azure/service-bus')

// Define connection string and related Service Bus entity names here
// Get it from the azure portal
const fishingConnectionString = '' // TODO this should go in the env vars
const waterConnectionString = '' // TODO this should go in the env vars
const fishingConnectionString = config.fishingConnectionString
const waterConnectionString = config.waterConnectionString

const fishingQueue = 'devsirinfsb1401-sbncomq-illegal-fishing' // TODO this should go in the env vars
const waterQueue = 'devsirinfsb1401-sbncomq-water-quality' // TODO this should go in the env vars
const fishingQueue = config.fishingQueue
const waterQueue = config.waterQueue

module.exports = class ASBService {
static async sendMessageToQueue(incidentToPublish, incidentType) {
static async sendMessageToQueue (incidentToPublish, incidentType) {
let sbClient, sender

if (incidentType === 300) {
Expand All @@ -28,7 +29,7 @@ module.exports = class ASBService {
myCustomPropertyName: 'Custom property'
}
}
//console.log(`Sending message: ${message.body}`)
// console.log(`Sending message: ${message.body}`)
await sender.sendMessages(message)

await sbClient.close()
Expand Down
12 changes: 6 additions & 6 deletions server/services/incident.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const RedisService = require('./redis.service')
const { v4: uuidv4 } = require('uuid')

module.exports = class IncidentService {
static async generateIncidentJson(request) {
static async generateIncidentJson (request) {
const incidentTypeFishing = 200

const iJsonObj = {}
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = class IncidentService {
return iJsonObj
}

static async generateWaterIncidentJson(request) {
static async generateWaterIncidentJson (request) {
const incidentTypeWater = 300

const iJsonObj = {}
Expand Down Expand Up @@ -130,7 +130,7 @@ module.exports = class IncidentService {

const howfaralongthewaterfeaturedoesthepollutio = []
howfaralongthewaterfeaturedoesthepollutio.push(
howfaralongthewaterfeaturedoesthepollutioText
howfaralongthewaterfeaturedoesthepollutio
)
incidentObj.sirp_WaterQuality.sirp_Howfaralongthewaterfeaturedoesthepollutio =
howfaralongthewaterfeaturedoesthepollutio
Expand Down Expand Up @@ -160,7 +160,7 @@ module.exports = class IncidentService {
return iJsonObj
}

static async generateWaterIncidentJson2(request) {
static async generateWaterIncidentJson2 (request) {
const incidentTypeWater = 300

const iJsonObj = {}
Expand Down Expand Up @@ -221,15 +221,15 @@ module.exports = class IncidentService {
incidentObj.sirp_WaterQuality.sirp_inWaterOther = whatIsInTheWaterOther
}

//Is there a smell? - Test
// Is there a smell? - Test
const smell = await RedisService.get(
request,
WQSirpRedisKeys.WQ_SIRP_SMELL_SOURCE
)
if (smell !== undefined) {
incidentObj.sirp_WaterQuality.sirp_isthereasmell = Boolean(smell)
}
//Is there a smell - other ? - Test
// Is there a smell - other ? - Test
const smellOther = await RedisService.get(
request,
WQSirpRedisKeys.WQ_SIRP_SMELL_SOURCE_OTHER
Expand Down
4 changes: 2 additions & 2 deletions server/services/incidentLocation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = require('../utils/config')
const util = require('../utils/util')

const apiKey = '50br44ij15V5hIAAhLoeFTiY57NZBYHS' // // TODO this should go in the env vars, this should never be in the source code!!

const apiKey = config.osKey
module.exports = {
findByPostcode: async (postcode) => {
try {
Expand Down
14 changes: 12 additions & 2 deletions server/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ const schema = joi.object().keys({
.string()
.default('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
osDataURI: joi.string().default('https://osdatahub.co.uk'),
osKey: joi.string(),
useBasicAuth: joi.bool().valid(true, false),
defraUsername: joi.string(),
defraPassword: joi.string(),
submitIncident: joi.bool().valid(true, false)
submitIncident: joi.bool().valid(true, false),
fishingConnectionString: joi.string(),
waterConnectionString: joi.string(),
fishingQueue: joi.string(),
waterQueue: joi.string()
})

// Build config
Expand All @@ -49,10 +54,15 @@ const config = {
redisPort: process.env.REDIS_PORT,
redisPassword: process.env.REDIS_PASSWORD,
osDataURI: process.env.OS_DATA_HUB_URI,
osKey: process.env.OS_KEY,
useBasicAuth: getBoolean(process.env.USE_BASIC_AUTH || false),
defraUsername: process.env.DEFRA_USERNAME,
defraPassword: process.env.DEFRA_PASSWORD,
submitIncident: getBoolean(process.env.SUBMIT_INCIDENT || false)
submitIncident: getBoolean(process.env.SUBMIT_INCIDENT || false),
fishingConnectionString: process.env.FISHING_CONNECTION_STRING,
waterConnectionString: process.env.WATER_CONNECTION_STRING,
fishingQueue: process.env.FISHING_QUEUE,
waterQueue: process.env.WATER_QUEUE
}

// Validate config
Expand Down
9 changes: 0 additions & 9 deletions server/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,12 @@ const WQSirpRedisKeys = {
WQ_SIRP_WHAT_CAN_YOU_SEE: 'WQ_sirp_Whatcanyouseeinoronthewater',
WQ_SIRP_WHAT_IS_IN_WATER: 'WQ_sirp_Whatdoyouthinkisinthewater',
WQ_SIRP_WHAT_IS_IN_WATER_OTHER: 'WQ_sirp_inWaterOther',

WQ_SIRP_SMELL_SOURCE: 'WQ_sirp_isthereasmell',
WQ_SIRP_SMELL_SOURCE_OTHER: 'WQ_sirp_isthereasmellother',

WQ_SIRP_POLLUTION_SOURCE: 'WQ_sirp_Doyouthinkyouknowwherethepollutioniscomin',
WQ_SIRP_POLLUTION_SOURCE_OTHER: 'WQ_sirp_pollutionSourceOther',

WQ_SIRP_HOW_FAR_ACROSS: 'WQ_sirp_Howfaracrossthewaterfeaturecanyouseethe',

WQ_SIRP_HOW_FAR_ALONG: 'WQ_sirp_Howfaralongthewaterfeaturedoesthepollutio',



WQ_SIRP_HOW_FAR_ALONG: 'WQ_',

WQ_SIRP_SEEN_DEAD_FISH: 'WQ_sirp_Haveyouseendeadfishnearby',
WQ_SIRP_HOW_MANY_DEAD_FISH: 'WQ_sirp_Howmanydeadfishhaveyouseen',
ANONYMOUS_PAYLOAD: 'anonymous.payload',
Expand Down
21 changes: 7 additions & 14 deletions server/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ const wreck = require('@hapi/wreck').defaults({
})

const makeRequest = async (method, url, options, _ext = false) => {
try {
const response = await wreck[method](url, options)
const { res, payload } = response

if (res.statusCode !== 200) {
if (payload) {
throw payload
}

throw new Error('Unknown error')
const response = await wreck[method](url, options)
const { res, payload } = response
if (res.statusCode !== 200) {
if (payload) {
throw payload
}

return payload
} catch (error) {
throw error
throw new Error('Unknown error')
}
return payload
}

const get = async (url, options, ext = false) =>
Expand Down

0 comments on commit de75776

Please sign in to comment.