-
Notifications
You must be signed in to change notification settings - Fork 11
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
Worker: don't use yargs defaults for env var stuff #604
Comments
Hello @josephjclark , I see the problem with environment variables being exposed in the console output when running To resolve this, I've come up with a plan to separate the environment variables from the yargs defaults. We'll refactor the argument parsing so that environment variables are not directly loaded into the We'll move the logic for handling environment variables outside of the yargs configuration and apply them manually in the parseArgs function. Here's the updated implementation:
To ensure these changes are effective and robust, I have added unit tests for the parseArgs function. I have included this function in a separate file |
Hey @SatyamMattoo sounds like you're on the right track! Can you raise a PR so I can take a proper look? One point of early feedback: the setup of the args object is quite painful:
The right-hand-side is very verbose and repettive, and hard to read. Ideally it would be nice to easily understand where a value has come from. Every arg has a value from the command line, a value from the env, and sometimes a default. Could we have some kind of helper function like this?
|
Hey @josephjclark I have raised a PR with the suggested changes, you can have a look whenever possible and suggest more changes that might be needed. Best regards. |
* Fixing: #604 * added new test for statePropsToRemove * requested changes * completed: requested changes
* worker: restructure env vars * Fixing: #604 * added new test for statePropsToRemove * requested changes * completed: requested changes * changeset * worker: simplify typings * worker: adjust tests * release: worker @1.1.10 --------- Co-authored-by: Satyam Mattoo <[email protected]>
* Fixing: #604 * added new test for statePropsToRemove * runtime: adding more validation to workflow.json * removing ws-worker changes * removing ws-worker changes * runtime: added new tests to validate-plan.test.ts * log function switched to openfn/logger * completed: requested changes * moved validtion to CLI * removed @ts-ignore and changed error and test messages. * fixing workflow error message
* Fixing: #604 * added new test for statePropsToRemove * runtime: adding more validation to workflow.json * removing ws-worker changes * removing ws-worker changes * runtime: added new tests to validate-plan.test.ts * log function switched to openfn/logger * completed: requested changes * moved validtion to CLI * removed @ts-ignore and changed error and test messages. * fixing workflow error message relesae: [email protected] formatting
The worker is started with a script called
start.ts
, which uses theyargs
library to parse inputs from command-line arguments and from the environment.The way it's set up at the moment allows env vars to be leaked into console output. Here's what happens if you run
pnpm start --help
frompackages/ws-worker/
:If you look closely at the output, you'll see that options which list env vars also list the env var value.
This isn't really harmful, but it is misleading and scary.
Requirements
yargs.default
propertynode start --help
should not output values in env varsBackground
The Worker is direct peer dependency of Lightning. When users trigger Workflows in Lightning, they are "claimed" by the worker (which is a separate service running on a different IP) and processed.
While the Worker executes a workflow, it sends back events to Lightning via websocket.
See the worker readme in packages/ws-worker/README.md for a bit of an overview
The actual execution is handled by the engine (engine-multi). The Worker package often mocks out the engine in tests so that it can focus on the Lighting-Worker communication.
Implementation Notes
I'm looking for a solution which finds a nice way to pull env vars off of
process.env
and apply them to theargs
object generated byyargs
. Env vars should only be applied if an option was not explicitly provided. In other words, CLI arguments should be preferred to env vars, and env vars should be preferred to yargs defaults.If the
args
object is populated appropriately, this change should be totally invisible.Testing
There are currently no unit tests against
start.ts
. It would be nice to have some.One way of doing this would be to separate the yargs stuff from start.ts, and just have a single function which assembles options from yargs and the environment. A cli.ts and a start.ts would be reasonable. You could then unit test cli.ts and ensure that it returns the right options.
The text was updated successfully, but these errors were encountered: