From 04bd0fb97f7c594dbcb02589dd8506edf46ae30b Mon Sep 17 00:00:00 2001 From: Achal Singh Date: Mon, 24 Jun 2024 22:40:58 +0530 Subject: [PATCH] chore: Update-Config script added --- scripts/update_config.ts | 50 ++++++++++++++++++++++++++++++++++++++++ src/API.ts | 4 ++++ 2 files changed, 54 insertions(+) create mode 100644 scripts/update_config.ts diff --git a/scripts/update_config.ts b/scripts/update_config.ts new file mode 100644 index 00000000..f78657a4 --- /dev/null +++ b/scripts/update_config.ts @@ -0,0 +1,50 @@ +import axios from 'axios' +import { join } from 'path' +import { Utils } from '@shardus/types' +import * as crypto from '@shardus/crypto-utils' +import { config, overrideDefaultConfig } from '../src/Config' + +const configFile = join(process.cwd(), 'archiver-config.json') +overrideDefaultConfig(configFile) + +crypto.init(config.ARCHIVER_HASH_KEY) + +const DEV_KEYS = { + pk: config.ARCHIVER_PUBLIC_KEY, + sk: config.ARCHIVER_SECRET_KEY, +} + +function sign(obj: T, sk: string, pk: string): T & any { + const objCopy = JSON.parse(crypto.stringify(obj)) + crypto.signObj(objCopy, sk, pk) + return objCopy +} + +function createSignature(data: any, pk: string, sk: string): any { + return sign({ ...data }, sk, pk) +} + +const UPDATE_CONFIG = { + /* Add Config properties that need to be updated here */ + VERBOSE: true, + RATE_LIMIT: 200, +} + +const INPUT = Utils.safeStringify(createSignature(UPDATE_CONFIG, DEV_KEYS.pk, DEV_KEYS.sk)) + +axios + .patch('http://127.0.0.1:4000/set-config', INPUT, { + headers: { + 'Content-Type': 'application/json', + }, + }) + .then((response) => { + console.log(response.data) + }) + .catch((error) => { + if (error.response) { + console.error(error.response) + } else { + console.error(error.message) + } + }) diff --git a/src/API.ts b/src/API.ts index c011f0c4..95273a11 100644 --- a/src/API.ts +++ b/src/API.ts @@ -911,6 +911,10 @@ export function registerRoutes(server: FastifyInstance