Skip to content

feat: Add Cloudflare Environment Variable and Secret support#41

Merged
gja merged 3 commits intogja:masterfrom
brinkmanlab:secrets
Mar 25, 2020
Merged

feat: Add Cloudflare Environment Variable and Secret support#41
gja merged 3 commits intogja:masterfrom
brinkmanlab:secrets

Conversation

@innovate-invent
Copy link
Copy Markdown
Contributor

@innovate-invent innovate-invent commented Mar 18, 2020

CloudFlare Environment Variables and Secrets

Support for CloudFlare Environment Variables and Secrets is provided via a wrangler.toml file.
See the wrangler documentation for more information on the file schema.

To load the wrangler.toml, specify it on the command line:

$ cloudflare-worker-local /path/to/worker.js localhost:3000 4000 /path/to/wrangler.toml

Optionally, the desired environment specified within the wrangler.toml can be loaded:

$ cloudflare-worker-local /path/to/worker.js localhost:3000 4000 /path/to/wrangler.toml production

Secrets are specified under the 'secrets' root key in the document. See the wrangler.toml
for an example of the supported structures.

Two features are provided while loading the wrangler.toml:

  • All vars and secrets strings can contain ${} placeholders.
    A placeholder path is resolved using lodash.get and has the context of the root of the config document.
    A placeholder can not refer to a value defined later in the document that also has placeholders.
  • Any var or secret that is not a string will be automatically JSON encoded.
    This allows you to inject complex data into a script by JSON decoding the variable value.

Additionally, any 'kv-namespaces' in the wrangler.toml will be appended to the list of namespaces
provided by KV_NAMESPACES.

@innovate-invent innovate-invent changed the title Add Cloudflare Environment Variable and Secret support feat: Add Cloudflare Environment Variable and Secret support Mar 18, 2020
@innovate-invent innovate-invent force-pushed the secrets branch 2 times, most recently from 941eda9 to 5fddacf Compare March 18, 2020 23:54
Copy link
Copy Markdown
Owner

@gja gja left a comment

Choose a reason for hiding this comment

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

This is AWESOME!

Quick favor. Would you also mind updating the deploy scripts so that they happen via wrangler? I’ve had this on my todo for a long time.

Let me know, I’ll merge it in either way.

@gja
Copy link
Copy Markdown
Owner

gja commented Mar 19, 2020

Actually, I think I misunderstood this PR. It looks like you are replicating the wrangler functionality.

Ok, that’s interesting. Let me think about this.

Do you have any thoughts on doing it this way v/s just including wrangler? This project is older than wrangler, and adding wrangler for config and deploys has been on my task list

@innovate-invent
Copy link
Copy Markdown
Contributor Author

Wrangler has no means to change its target API endpoint so I don't think we can use wrangler to deploy.
Maybe I am misunderstanding what you mean by deployment. I am using this project as an alternative to hosting the worker on Cloudflare. The cloudflare-worker-local server is the final deployment destination in my mind.

Nolan Woods added 2 commits March 20, 2020 11:52
…secrets

� Conflicts:
�	README.md
�	app/__tests__/server_spec.js
�	package-lock.json
�	package.json
�	start.js
@innovate-invent
Copy link
Copy Markdown
Contributor Author

I should add, I am using the wrangler.toml file to store the environment variables and secrets because Workers users will likely already have this file written. It made more sense to just reuse the file schema rather than come up with our own way of persisting configuration of the server.

I was thinking of taking this a step further and moving all server config into the wrangler.toml file rather than having a mix of command line arguments, environment variables, and config file.

@gja
Copy link
Copy Markdown
Owner

gja commented Mar 21, 2020 via email

@innovate-invent
Copy link
Copy Markdown
Contributor Author

this commit allows you to specify the target environment on the command line. The wrangler.toml spec already specifies a way of having different environments.

@gja gja merged commit 2091bb5 into gja:master Mar 25, 2020
@innovate-invent innovate-invent deleted the secrets branch March 25, 2020 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants