-
Notifications
You must be signed in to change notification settings - Fork 275
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
add expansion module support to rhai #3240
Conversation
fixes: #1744 This refactors existing functionality within `Expansion` to add support for a default rhai expander and to expose a new function for environment variable access. This leverages the existing mechanism for limiting access to environment variables. This functionality is then exposed to rhai scripts as in this example code: ``` let expander = expansion::create(); try { print(`LANG: ${expansion::env(expander, "LANG")}`); } catch(err) { print(`exception: ${err}`); } ``` In the sample, we use the new expansion module to create an expander. We then use the expander to access environment variables, in this case "LANG".
This comment has been minimized.
This comment has been minimized.
CI performance tests
|
Introduce private prefix() fn to use from default() and default_rhai().
@@ -142,6 +144,18 @@ impl Expansion { | |||
} | |||
} | |||
|
|||
pub(crate) fn expand_env(&self, key: &str) -> Result<Option<String>, ConfigurationError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that the error message in here is targeted at config expansion.
The rhai expansion should have it's own error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want the Rhai
functionality to look/smell the same, so I think this message is perfect. In the future we may add more configuration/expansion capabilities into Rhai
, so deviation is probably not a good thing.
Adding the global flag to the env method resolves the object method invocation problem. also: add docs and unit tests for the new methods.
The expansion module is now exposed as the `router_env` module. The `create()` function is removed and the `env()` method is replaced by the `get()` function. Docs are updated.
This refactors existing functionality within `Expansion` to expose a new function for environment variable access. This leverages the existing mechanism for limiting access to environment variables. This functionality is then exposed to rhai scripts as in this example code: ``` try { print(`LANG: ${env::get("LANG")}`); } catch(err) { print(`exception: ${err}`); } ``` In the sample, we use the new env module to access environment variables, in this case "LANG". fixes: #1744 <!-- start metadata --> **Checklist** Complete the checklist (and note appropriate exceptions) before a final PR is raised. - [x] Changes are compatible[^1] - [x] Documentation[^2] completed - [x] Performance impact assessed and acceptable - Tests added and passing[^3] - [x] Unit Tests - [ ] Integration Tests - [ ] Manual Tests **Exceptions** *Note any exceptions here* **Notes** [^1]. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. [^2]. Configuration is an important part of many changes. Where applicable please try to document configuration examples. [^3]. Tick whichever testing boxes are applicable. If you are adding Manual Tests: - please document the manual testing (extensively) in the Exceptions. - please raise a separate issue to automate the test and label it (or ask for it to be labeled) as `manual test`
This refactors existing functionality within
Expansion
to expose a new function for environment variable access. This leverages the existing mechanism for limiting access to environment variables.This functionality is then exposed to rhai scripts as in this example code:
In the sample, we use the new env module to access environment variables, in this case "LANG".
fixes: #1744
Checklist
Complete the checklist (and note appropriate exceptions) before a final PR is raised.
Exceptions
Note any exceptions here
Notes
[^1]. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.
[^2]. Configuration is an important part of many changes. Where applicable please try to document configuration examples.
[^3]. Tick whichever testing boxes are applicable. If you are adding Manual Tests:
- please document the manual testing (extensively) in the Exceptions.
- please raise a separate issue to automate the test and label it (or ask for it to be labeled) as
manual test