-
Notifications
You must be signed in to change notification settings - Fork 5
Use the VM loader for loading plugin modules as well resource modules #209
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
66f0dc5
Create an ApplicationScope that holds the top level context for the a…
kriszyp efd52b7
Fix root handling and unit tests
kriszyp d15dfcf
Respect verifyPath if it is already set
kriszyp 59ef091
Update components/ApplicationScope.ts
kriszyp 23c0505
Remove unused import
kriszyp 0e4f4dc
Apply suggestions from code review
kriszyp 9f04538
Updates for optional verifyPath and assignment of config
kriszyp 592d314
Merge remote-tracking branch 'origin/main' into vm-load-plugins
kriszyp 6588350
Merge remote-tracking branch 'origin/main' into vm-load-plugins
kriszyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import type { Resources } from '../resources/Resources.ts'; | ||
| import { type Server } from '../server/Server.ts'; | ||
| import { loggerWithTag } from '../utility/logging/harper_logger.js'; | ||
| import { scopedImport } from '../security/jsLoader.ts'; | ||
| import * as env from '../utility/environment/environmentManager.js'; | ||
| import { CONFIG_PARAMS } from '../utility/hdbTerms.ts'; | ||
|
|
||
| export class MissingDefaultFilesOptionError extends Error { | ||
| constructor() { | ||
| super('No default files option exists. Ensure `files` is specified in config.yaml'); | ||
| this.name = 'MissingDefaultFilesOptionError'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This class is used to represent the application scope for the VM context used for loading modules within an application | ||
| */ | ||
| export class ApplicationScope { | ||
| logger: any; | ||
| resources: Resources; | ||
| server: Server; | ||
| mode?: 'none' | 'vm' | 'compartment'; // option to set this from the scope | ||
| dependencyContainment?: boolean; // option to set this from the scope | ||
| verifyPath?: string; | ||
| config: any; | ||
| constructor(name: string, resources: Resources, server: Server, verifyPath?: string) { | ||
| this.logger = loggerWithTag(name); | ||
|
|
||
| this.resources = resources; | ||
| this.server = server; | ||
|
|
||
| this.mode = env.get(CONFIG_PARAMS.APPLICATIONS_CONTAINMENT) ?? 'vm'; | ||
| this.dependencyContainment = Boolean(env.get(CONFIG_PARAMS.APPLICATIONS_DEPENDENCYCONTAINMENT)); | ||
| this.verifyPath = verifyPath; | ||
| } | ||
|
|
||
| /** | ||
| * The compartment that is used for this scope and any imports that it makes | ||
| */ | ||
| compartment?: Promise<any>; | ||
| /** | ||
| * Import a file into the scope's sandbox. | ||
| * @param filePath - The path of the file to import. | ||
| * @returns A promise that resolves with the imported module or value. | ||
| */ | ||
| async import(filePath: string): Promise<unknown> { | ||
| return scopedImport(filePath, this); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if
verifyPathisundefined?checkAllowedModulePath()expectscontainingFolderto be defined, so maybe it's easiest to letcheckAllowedModulePath()accept an undefinedcontainingFolderand throw a meaningful message?