cleanup for aws

This commit is contained in:
STEINNI
2025-09-11 20:58:43 +00:00
parent de69b3d4de
commit f4ac7df4a7
4 changed files with 12 additions and 55 deletions
+3 -47
View File
@@ -7,22 +7,9 @@ module.exports = class configHelper {
constructor(options){
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.fetchConfig = this.fetchConfigFile
this.refreshAccessRights = this.refreshAccessRightsFile
}
this.localfile = options.localfile
this.fetchConfig = this.fetchConfigFile
this.refreshAccessRights = this.refreshAccessRightsFile
const ajv = new Ajv({
allowUnionTypes: true
})
@@ -35,37 +22,6 @@ module.exports = class configHelper {
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(){
let curConfig = this.config
this.config = await require(this.localfile)