Skip to content

Commit 8cd2fb7

Browse files
committed
Validate the YAML files
1 parent 71cd251 commit 8cd2fb7

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

governance/xc_admin/packages/xc_admin_frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"sharp": "^0.33.4",
3737
"use-debounce": "^9.0.2",
3838
"web3": "^4.8.0",
39-
"yaml": "^2.1.1"
39+
"yaml": "^2.1.1",
40+
"zod": "^3.23.8"
4041
},
4142
"devDependencies": {
4243
"@svgr/webpack": "^6.3.1",

governance/xc_admin/packages/xc_admin_frontend/pages/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import YAML from 'yaml'
2+
import { z } from 'zod'
23
import { Tab } from '@headlessui/react'
34
import * as fs from 'fs'
45
import type { GetServerSideProps, NextPage } from 'next'
@@ -14,12 +15,16 @@ import { StatusFilterProvider } from '../contexts/StatusFilterContext'
1415
import { classNames } from '../utils/classNames'
1516
import '../mappings/signers.json'
1617

18+
const keyToNameMappingSchema = z.array(
19+
z.object({ key: z.string(), name: z.string() })
20+
)
21+
1722
const readPublisherKeyToNameMapping = async (filename: string) => {
1823
try {
1924
await fs.promises.access(filename)
20-
const arr = YAML.parse(await fs.promises.readFile(filename, 'utf8')).map(
21-
(key: string, name: string) => [key, name]
22-
)
25+
const arr = keyToNameMappingSchema
26+
.parse(YAML.parse(await fs.promises.readFile(filename, 'utf8')))
27+
.map((key, name) => [key, name])
2328
return Object.fromEntries(arr)
2429
} catch {
2530
return {}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)