cleanup for aws
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
.well-known
|
||||||
|
wssGatewayConfig.json
|
||||||
|
nodeserver.cert
|
||||||
|
nodeserver.key
|
||||||
|
package-lock.json
|
||||||
|
/brol
|
||||||
|
/node_modules
|
||||||
|
*.log
|
||||||
@@ -7,22 +7,9 @@ module.exports = class configHelper {
|
|||||||
|
|
||||||
constructor(options){
|
constructor(options){
|
||||||
this.config = {}
|
this.config = {}
|
||||||
if(options.onAws) {
|
|
||||||
DynamoDBClient = require("@aws-sdk/client-dynamodb").DynamoDBClient
|
|
||||||
GetItemCommand = require("@aws-sdk/client-dynamodb").GetItemCommand
|
|
||||||
marshall = require("@aws-sdk/util-dynamodb").marshall
|
|
||||||
unmarshall = require("@aws-sdk/util-dynamodb").unmarshall
|
|
||||||
this. dynamoClient = new DynamoDBClient({ region: options.awsRegion })
|
|
||||||
|
|
||||||
this.awsTable = options.awsTable
|
|
||||||
this.awsServiceName = options.awsServiceName
|
|
||||||
this.fetchConfig = this.fetchConfigDynamo
|
|
||||||
this.refreshAccessRights = this.refreshAccessRightsDynamo
|
|
||||||
} else {
|
|
||||||
this.localfile = options.localfile
|
this.localfile = options.localfile
|
||||||
this.fetchConfig = this.fetchConfigFile
|
this.fetchConfig = this.fetchConfigFile
|
||||||
this.refreshAccessRights = this.refreshAccessRightsFile
|
this.refreshAccessRights = this.refreshAccessRightsFile
|
||||||
}
|
|
||||||
const ajv = new Ajv({
|
const ajv = new Ajv({
|
||||||
allowUnionTypes: true
|
allowUnionTypes: true
|
||||||
})
|
})
|
||||||
@@ -35,37 +22,6 @@ module.exports = class configHelper {
|
|||||||
return(false)
|
return(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
async dynamoGet(subKey = null){
|
|
||||||
let params = new GetItemCommand({
|
|
||||||
TableName: this.awsTable,
|
|
||||||
Key: {
|
|
||||||
serviceName: marshall(this.awsServiceName),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
let result = await this.dynamoClient.send(params)
|
|
||||||
let obj = unmarshall(result.Item)
|
|
||||||
if((typeof(subKey)=='string') && (subKey in obj)) return(obj[subKey])
|
|
||||||
return(obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchConfigDynamo(){
|
|
||||||
let curConfig = this.config
|
|
||||||
this.config = await this.dynamoGet()
|
|
||||||
|
|
||||||
if(process.env.UNSECURE) this.config.server.unsecure = Boolean(process.env.UNSECURE);
|
|
||||||
if(process.env.REDIS_HOST) this.config.redis.host = process.env.REDIS_HOST;
|
|
||||||
if(process.env.REDIS_TLS) this.config.redis.tls = Boolean(process.env.REDIS_TLS);
|
|
||||||
if(process.env.REDIS_PORT) this.config.redis.port = Number(process.env.REDIS_PORT);
|
|
||||||
if(process.env.REDIS_USER) this.config.redis.user = process.env.REDIS_USER;
|
|
||||||
if(process.env.REDIS_PASSWORD) this.config.redis.pass = process.env.REDIS_PASSWORD;
|
|
||||||
|
|
||||||
if(this.isValidConfig(this.config)) return(this.config)
|
|
||||||
console.error(this.isValidConfig.errors)
|
|
||||||
//revert if invalid conf
|
|
||||||
this.config = curConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchConfigFile(){
|
async fetchConfigFile(){
|
||||||
let curConfig = this.config
|
let curConfig = this.config
|
||||||
this.config = await require(this.localfile)
|
this.config = await require(this.localfile)
|
||||||
|
|||||||
+1
-4
@@ -15,13 +15,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^8.12.0",
|
"ajv": "^8.12.0",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"pm2": "^5.2.0",
|
"pm2": "^6.0.10",
|
||||||
"redis": "^4.3.0",
|
"redis": "^4.3.0",
|
||||||
"urldecode": "^1.0.1",
|
"urldecode": "^1.0.1",
|
||||||
"ws": "^8.8.1",
|
"ws": "^8.8.1",
|
||||||
"yargs": "^17.5.1"
|
"yargs": "^17.5.1"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"jest": "^29.7.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ const debug = Boolean(process.env.DEBUG) || argv.debug
|
|||||||
|
|
||||||
const cfgh = new configHelper({
|
const cfgh = new configHelper({
|
||||||
localfile: './wssGatewayConfig.json',
|
localfile: './wssGatewayConfig.json',
|
||||||
onAws: typeof(process.env.AWS_EXECUTION_ENV)=='string',
|
|
||||||
awsRegion: 'eu-west-1',
|
|
||||||
awsTable: 'bus-config',
|
|
||||||
awsServiceName: 'wssGateway',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function startRedis(wssGatewayConfig) {
|
async function startRedis(wssGatewayConfig) {
|
||||||
|
|||||||
Reference in New Issue
Block a user