-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(common): pass manifest json to sandbox #273
Changes from 1 commit
09ebd05
561464f
d7c9b21
6e131af
122dc16
f2f3e38
ca9a4c6
6f19373
d5e1d10
a615ae1
90b59de
acc9176
80f9d32
54fbea4
4081224
2319e6e
5c0439a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,39 @@ export const load = (): Manifest => { | |
try { | ||
const content: string = readFileSync(MANIFEST_FULL_PATH, 'utf8') | ||
|
||
return JSON.parse(content) as Manifest | ||
const manifest: Manifest = JSON.parse(content) | ||
|
||
validateSchema(manifest) | ||
|
||
return manifest | ||
} catch (err: any) { | ||
throw new Error('Error while loading the manifest file: ' + err.message) | ||
} | ||
} | ||
|
||
const validateSchema = (manifest: Manifest): void => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added this simple validation, without using any external packages, here since we decided not to go too far on this. |
||
const allowedProperties = ['options'] | ||
|
||
if (typeof manifest !== 'object') { | ||
throw new Error(`The manifest should be an object`) | ||
} | ||
|
||
Object.keys(manifest).forEach((prop) => { | ||
if (!allowedProperties.includes(prop)) { | ||
throw new Error(`The property ${prop} is not allowed`) | ||
} | ||
}) | ||
|
||
if (manifest.options !== undefined && !Array.isArray(manifest.options)) { | ||
throw new Error(`When declared, the 'options' property should be an array`) | ||
} | ||
|
||
manifest.options?.forEach((o) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's rename this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion here, @eunjae-lee. 🙌 I've just renamed it. If there is something else, let me know, please. |
||
if (!('name' in o && 'value' in o)) { | ||
throw new Error( | ||
`Some of the defined 'options' are invalid. ` + | ||
`Please, make sure they contain a 'name' and 'value' properties`, | ||
) | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I kept informing the
encoding
since otherwise it would return me a Buffer instead of a string.So, this way is the simplest one, I guess. If there is any other better way, let me know, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had some other code like
readFileSync(...).toString()
. I don't know what's better, though.