Skip to content
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

doc: add complete docs for all dotenv functionality #3560

Merged
merged 4 commits into from
Aug 22, 2023

Conversation

cknight
Copy link
Contributor

@cknight cknight commented Aug 22, 2023

While looking at #3492 it was clear that the documentation for dotenv module was incomplete. This PR attempts to address this by including all options, capabilities and files associated with the dotenv module.

Note, for restrictEnvAccessTo, I was very unclear as to the purpose of this. No matter what I tried, this option did nothing. Either this is a bug or I'm using it incorrectly. I've copied the docs for this option verbatim but they are not clear and should be revisited.

@cknight cknight requested a review from kt3k as a code owner August 22, 2023 14:13
@CLAassistant
Copy link

CLAassistant commented Aug 22, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! LGTM

@kt3k kt3k merged commit b34c646 into denoland:main Aug 22, 2023
@kt3k
Copy link
Member

kt3k commented Aug 22, 2023

restrictEnvAccessTo restricts the env access range. Run the below 2 scripts with deno run --allow-read main.ts and there are differences in permission prompts.

import { load } from "https://deno.land/std@0.199.0/dotenv/mod.ts";
await load();
import { load } from "https://deno.land/std@0.199.0/dotenv/mod.ts";
await load({ restrictEnvAccessTo: ["FOO", "BAR"] });

@cknight
Copy link
Contributor Author

cknight commented Aug 23, 2023

Thanks @kt3k . I see the differences in the permission prompts, but not any functional differences in running it.

For example, running this code:

import { load } from "https://deno.land/std@0.199.0/dotenv/mod.ts";
const conf = await load({ restrictEnvAccessTo: ["FOO", "BAR"] });
console.log(conf);
console.log(Deno.env.get("FOO"));
console.log(Deno.env.get("BAR"));
console.log(Deno.env.get("HELLO"));

with this command:

HELLO=world FOO=this BAR=that deno run --allow-read main.ts

prompts me first for FOO and BAR then processes the first 3 console outputs, then prompts for HELLO then outputs the last console output. However, conf is empty, so other than prompting for individual env variables permissions vs all env variables, I can't see any reason why you'd use this? Nothing is actually restricted here, e.g. I can still access HELLO.

@kt3k
Copy link
Member

kt3k commented Aug 23, 2023

Then compare the below 2 scripts:

import { load } from "https://deno.land/std@0.199.0/dotenv/mod.ts";
console.log(await load());
import { load } from "https://deno.land/std@0.199.0/dotenv/mod.ts";
const conf = await load({ restrictEnvAccessTo: ["FOO", "BAR"] });

With .env file:

A=$FOO
B=$BAR
C=$HELLO

With the command FOO=1 BAR=2 HELLO=3 deno run --allow-read main.ts.

The first one should print { A: "1", B: "2", C: "3" } and the 2nd prints { A: "1", B: "2", C: "undefined" } (the access to HELLO is restricted in the 2nd example)

@cknight
Copy link
Contributor Author

cknight commented Aug 23, 2023

@kt3k Ah! I see, it restricts access to expansion in the .env file from process supplied env variables. I understand now how it works, thanks for the follow up. Still puzzled however on the use case. If you want to use the conf rather than Deno.env.get() but restrict which process env variables are allowed to be included in the conf, then just don't reference them in your .env?

@kt3k
Copy link
Member

kt3k commented Aug 24, 2023

The main point of restrictEnvAccessTo is permission consideration. If restrictEnvAccessTo is not given, the entire 'env' permission is required for using dotenv/load, which unnecessarily expose env vars that the user prefers to hide from the program.

The original issue: #2534

@kt3k
Copy link
Member

kt3k commented Aug 24, 2023

I now feel the way we read env vars in parse (and load) API has a problem.

I created an issue #3572

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants