Skip to content
10 changes: 10 additions & 0 deletions src/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ export class OceanNode {
return this.auth
}

public setConfig(config: OceanNodeConfig) {
this.config = config
if (this.config) {
this.escrow = new Escrow(
this.config.supportedNetworks,
this.config.claimDurationTimeout
)
}
}

/**
* Use this method to direct calls to the node as node cannot dial into itself
* @param message command message
Expand Down
14 changes: 12 additions & 2 deletions src/components/core/admin/pushConfigHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,31 @@
}

try {
const hasRunningJobs =
(await this.getOceanNode().getDatabase().c2d.getRunningJobs()).length > 0
if (hasRunningJobs) {
throw new Error('Node has running jobs')
}

const configPath = getConfigFilePath()
const configContent = await fs.promises.readFile(configPath, 'utf-8')

Check warning on line 61 in src/components/core/admin/pushConfigHandler.ts

View workflow job for this annotation

GitHub Actions / lint

Found readFile from package "fs" with non literal argument at index 0
const currentConfig = JSON.parse(configContent)

const mergedConfig = { ...currentConfig, ...task.config }
await this.saveConfigToFile(mergedConfig)

const newConfig = await getConfiguration(true, false)
newConfig.keys.privateKey = '[*** HIDDEN CONTENT ***]'
this.getOceanNode().setConfig(newConfig)
await this.getOceanNode().addC2DEngines()

const responseConfig = structuredClone(newConfig)
responseConfig.keys.privateKey = '[*** HIDDEN CONTENT ***]'
CORE_LOGGER.logMessage('Configuration reloaded successfully')

return new Promise<P2PCommandResponse>((resolve) => {
resolve({
status: { httpStatus: 200 },
stream: new ReadableString(JSON.stringify(newConfig))
stream: new ReadableString(JSON.stringify(responseConfig))
})
})
} catch (error) {
Expand All @@ -82,7 +92,7 @@
private async saveConfigToFile(config: Record<string, any>): Promise<void> {
const configPath = getConfigFilePath()
const content = JSON.stringify(config, null, 4)
await fs.promises.writeFile(configPath, content, 'utf-8')

Check warning on line 95 in src/components/core/admin/pushConfigHandler.ts

View workflow job for this annotation

GitHub Actions / lint

Found writeFile from package "fs" with non literal argument at index 0
CORE_LOGGER.logMessage(`Config saved to: ${configPath}`)
}
}
10 changes: 6 additions & 4 deletions src/components/httpRoutes/adminConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ export const adminConfigRoutes = express.Router()

adminConfigRoutes.get('/api/admin/config', express.json(), async (req, res) => {
try {
const { expiryTimestamp, signature } = req.body
const { expiryTimestamp, signature, address } = req.body

const response = await new FetchConfigHandler(req.oceanNode).handle({
command: PROTOCOL_COMMANDS.FETCH_CONFIG,
expiryTimestamp,
signature
signature,
address
})

if (response.status.httpStatus === 200) {
Expand All @@ -33,13 +34,14 @@ adminConfigRoutes.get('/api/admin/config', express.json(), async (req, res) => {

adminConfigRoutes.post('/api/admin/config/update', express.json(), async (req, res) => {
try {
const { expiryTimestamp, signature, config } = req.body
const { expiryTimestamp, signature, config, address } = req.body

const response = await new PushConfigHandler(req.oceanNode).handle({
command: PROTOCOL_COMMANDS.PUSH_CONFIG,
expiryTimestamp,
signature,
config
config,
address
})

if (response.status.httpStatus === 200) {
Expand Down
Loading