Skip to content

Commit

Permalink
chore: Update-Config script added
Browse files Browse the repository at this point in the history
  • Loading branch information
achal-singh committed Jun 24, 2024
1 parent d76993e commit 04bd0fb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions scripts/update_config.ts
Original file line number Diff line number Diff line change
@@ -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<T>(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)
}
})
4 changes: 4 additions & 0 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,10 @@ export function registerRoutes(server: FastifyInstance<Server, IncomingMessage,
reply.send(res)
})

/**
* This endpoint is used to update the archiver config.
* @script A test script to hit this endpoint is available at `scripts/update_config.ts`
*/
server.patch(
'/set-config',
{
Expand Down

0 comments on commit 04bd0fb

Please sign in to comment.