winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.76k stars 187 forks source link

util.env not reading string correctly #6677

Closed springbok closed 2 weeks ago

springbok commented 2 weeks ago

I tried this:

Here is an example string in my .env:

AI_PASSWORD="$2b$fsafrrewru3DSVF12$dnZV3fssfiV4Y1D/6MdCNBthKLKSj24560uXEH2zfHK9IMEK43GkcvF9YUTWzJcGJK"

And read it using:

util.env("AI_PASSWORD")

This happened:

It returns a partial string rather than the full string:

/6MdCNBthKLKSj24560uXEH2zfHK9IMEK43GkcvF9YUTWzJcGJK

I expected this:

I expected to get the full string back:

$2b$fsafrrewru3DSVF12$dnZV3fssfiV4Y1D/6MdCNBthKLKSj24560uXEH2zfHK9IMEK43GkcvF9YUTWzJcGJK

Is there a workaround?

I've hard coded the string for now.

Anything else?

No response

Wing Version

0.74.38

Node.js Version

v20.13.0

Platform(s)

Linux

Community Notes

eladb commented 2 weeks ago

@springbok trying to reproduce this, it seems like the issue is with how the string is stored and not with how it is read by wing.

If you use single-quotes, the shell won't substitute $x:

AI_PASSWORD='$2b$fsafrrewru3DSVF12$dnZV3fssfiV4Y1D/6MdCNBthKLKSj24560uXEH2zfHK9IMEK43GkcvF9YUTWzJcGJK'

And then util.env() should show you the full value.

Perhaps related: it might be better to use cloud.Secret to read secrets:

bring cloud;

let secret = new cloud.Secret(name: "AI_PASSWORD");

test "show me the secret" {
  log(secret.value());
}

This is more portable.

When executed in sim, it will read the secret from an environment variable (you can also put these in .env) and when deployed to the cloud it will read from the default secret store (e.g. AWS Secrets Manager on AWS).

If you run wing secrets, it will prompt you to store the secrets.

eladb commented 2 weeks ago

Closing for now as this doesn't seem to be an issue.