Use Deno permissions in your own CLI
If I create a CLI with Deno, can I somehow reuse or pass on the permissions?
1 Reply
Yes, you can design your Deno CLI to accept permission flags and pass them on to the Deno runtime when executing scripts. The documentation mentions that Deno's permission system allows you to grant access to specific entities (like files or servers) rather than to everything, and you can use command-line flags to enable these permissions.
For example, if your CLI needs to read from the file system, you can pass the
--allow-read
flag when invoking your CLI, and then your CLI can pass this flag to the Deno runtime when it runs a Deno script. Here's a simplified example of how you might handle this in your CLI:
In your CLI's code, you would need to parse the command-line arguments and include the appropriate permission flags when using Deno.run
to execute a Deno script:
Remember that when you pass permission flags from your CLI to Deno scripts, you are effectively allowing those scripts to perform the operations permitted by those flags. It's important to handle permissions carefully to maintain the security of your application.
š¦ Always ensure that your CLI only requests the minimum permissions necessary for its operation, following the principle of least privilege.