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

feat(codegen): Allow plugins to access environment variables #2669

Merged
merged 7 commits into from
Aug 29, 2023

Conversation

kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Aug 29, 2023

Allow plugins, both process-based and WASM-based, to read environment variables from the host, configured via a per-variable allowlist. Plugins can not declare the environment variables they have access to outside of the sqlc.yaml configuration file.

version: '2'
plugins:
- name: py
  env:
  - PATH
  wasm:
    url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm
    sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2

Closes #2661

Currently untested, but environment variable access must be configured
in sqlc.yaml.
@andrewmbenton
Copy link
Collaborator

So the idea here is that the user can decide which variables go in the allow list, via sqlc.conf?

@kyleconroy
Copy link
Collaborator Author

Exactly. This is very similar to how wasmtime allows environment variables to be accessed.

version: '2'
plugins:
- name: py
  env:
  - PATH
  wasm:
    url: https://github.com/sqlc-dev/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm
    sha256: 428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2
sql:
- schema: "schema.sql"
  queries: "query.sql"
  engine: postgresql
  codegen:
  - out: src/authors
    plugin: py
    options:
      package: authors
      emit_sync_querier: true
      emit_async_querier: true
      query_parameter_limit: 5

@kyleconroy kyleconroy marked this pull request as ready for review August 29, 2023 18:44
@@ -316,6 +316,8 @@ Each mapping in the `plugins` collection has the following keys:

- `name`:
- The name of this plugin. Required
- `env`
- A list of environment variables to pass to the plugin. By default, no environment variables are passed.
Copy link
Collaborator

@andrewmbenton andrewmbenton Aug 29, 2023

Choose a reason for hiding this comment

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

There is the SQLC_VERSION var which is added (not from the actual shell environment though). That should be documented somewhere, but probably not here.

@kyleconroy kyleconroy merged commit 5e81d02 into main Aug 29, 2023
8 checks passed
@kyleconroy kyleconroy deleted the kyle/plugins-allow-env branch August 29, 2023 21:36
This pull request was closed.
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