Make custom filters available in Mistral; Disable Decryption-by-default in st2kv function#30
Make custom filters available in Mistral; Disable Decryption-by-default in st2kv function#30
Conversation
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
st2mistral/functions/stackstorm.py
Outdated
| config.register_opts() | ||
|
|
||
| from mistral import exceptions as exc | ||
| from st2common.jinja.filters import crypto |
There was a problem hiding this comment.
I thought we agreed to duplicate the Jinja filters in st2mistral. I'm against including st2common here as a dependency. This will complicate the deployment story for Mistral.
There was a problem hiding this comment.
Sorry, I must have missed that one, or assumed that "duplicate" meant implementing these redirections. I am okay with re-implementing them fully here, it just adds work to anyone wanting to create a new custom filter.
Funny enough, I didn't catch the deployment complications you allude to because of the fact I am using one virtualenv for both st2 and mistral in StackStorm/st2#3557 (which you pointed out should be done separately). I assume this is what you're talking about, since in any real deployment, mistral would not have access to st2common.
I'll adjust this PR's description and change the approach. Thanks for the catch!
There was a problem hiding this comment.
Yep in real deployment, st2 and mistral have different venvs and mistral currently do not have access to st2common.
There was a problem hiding this comment.
It is important during development to be conscious about how changes will impact CI, packaging, and deployment.
There was a problem hiding this comment.
Ack - keeping that in mind, will remedy my development script for Mistral to reflect that.
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
This was a lazy temporary fix to a structural issue that has since been fixed. So not needed anymore Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
…t by default in st2kv Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
|
So it turns out the issue I’ve been having with YAQL while writing itests for these changes in StackStorm/st2#3565 was indeed caused by a mismatch in the function signature, and the way the YAQL evaluator was trying to pass data into it, but it had nothing to do with args vs kwargs, it was only with functions that had string parameters. SummaryStrings as input to functions are recognized as From the look of it, the only integration tests that use any custom filters within a YAQL statement are testing SolutionThe easiest way of addressing this is to add the unicode marker before each default string parameter in each custom filter function. Certainly, since this PR is not merged yet, I can take care of this. Jinja should continue to work, and this will make the equivalent YAQL work as well: I already have a bit on my plate so I can’t do this now, but someone should try to use one of the custom filters that have one of these parameters, inside a YAQL statement in an ActionChain. My theory is that it won’t work, but I could be wrong. Just something to follow up on. In addition, I couldn’t get both YAQL and Jinja to work with the additional Anyways, I’m ignoring this for now so I can move on but it may be worth backtracking to figure this out because it doesn’t seem to make sense given the use of |
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
m4dcoder
left a comment
There was a problem hiding this comment.
LGTM overall. Please use the term function instead of filter in Mistral. Also, there are coding guidelines for Mistral if you can address.
setup.cfg
Outdated
| mistral.expression.functions = | ||
| st2kv = st2mistral.functions.stackstorm:st2kv_ | ||
|
|
||
| to_json_string = st2mistral.filters.data:to_json_string |
There was a problem hiding this comment.
Please use function instead of filter In Mistral. The term filter is specific to Jinja. In Mistral, these are called function. Please move all the implementation into the functions folder.
There was a problem hiding this comment.
Oh, and in 5291379 (updated tests accordingly)
setup.cfg
Outdated
| version_bump_patch = st2mistral.filters.version:version_bump_patch | ||
| version_strip_patch = st2mistral.filters.version:version_strip_patch | ||
| json_escape = st2mistral.filters.json_escape:json_escape | ||
| use_none = st2mistral.filters.use_none:use_none |
There was a problem hiding this comment.
Please list them by alphabetical order.
st2mistral/filters/complex_type.py
Outdated
| def to_complex(value): | ||
| result = json.dumps(value) | ||
|
|
||
| return result |
There was a problem hiding this comment.
How about just return json.dumps(value)?
There was a problem hiding this comment.
Why not move this to data.py?
There was a problem hiding this comment.
All good ideas - this was just some copypasta from the original implementation. Fixed in a164d6c
| return { | ||
| 'to_json_string': data.to_json_string, | ||
| 'to_yaml_string': data.to_yaml_string, | ||
|
|
There was a problem hiding this comment.
No reason, just copied from st2. Fixed in f49a9ff
| env = self.get_jinja_environment() | ||
| obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}} | ||
|
|
||
| template = '{{k1 | to_complex}}' |
There was a problem hiding this comment.
Why use piping to pass k1 to to_complex? I mean we can test it if we want to make sure piping is supported. But how about also testing it as to_complex(k1)?
There was a problem hiding this comment.
As discussed in StackStorm/st2#3565, we're deciding (for now) to not support the filter format due to the upstream mistral issue, and requiring that users use the function format. I added context as the first positional arg (and modified testing accordingly) in 739fa88
tox.ini
Outdated
| #Skip PEP257 violation. | ||
| [flake8] | ||
| ignore = D100,D101,D102,D103,D104,D105,D200,D203,D202,D204,D205,D208,D400,D401 | ||
| max-line-length = 100 |
There was a problem hiding this comment.
Please leave default to max line length to 79 to match w/ Mistral. As I explained in Slack, this is an extension project for Mistral and I have been following the coding guidelines for Mistral. Sorry if this doesn't make any sense.
There was a problem hiding this comment.
No problem, I reverted this in 5dd1696 (and made sure everything passed tox -epep8 again). Following the rules of the upstream project this is a "part" of makes sense to me (though it wreaks havoc on my regex patterns)!
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
|
Style fixes for me to make:
|
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
|
@m4dcoder So I made style corrections that Flake8 caught (after changing the max line length back to pep8 standard) but I had some questions about the other style rules you proposed (and I reposted above). I know only of https://docs.openstack.org/hacking/latest/user/hacking.html in terms of OpenStack style standards, and I only found references to the last rule: Also what about automated checks? The mistral repo doesn't seem to use anything beyond what's already used in this repo, and it doesn't currently seem to be checking for any of that (except line length of course). |
m4dcoder
left a comment
There was a problem hiding this comment.
Please fix the config register opts. Otherwise, changes LGTM. @lakshmi-kannan asks me not to go easy on you so I'm going to enforce the coding style loosely (except the line length of 79). Some of the Mistral coding guidelines are additions to OpenStack so there's no doc around that. These guidelines you'll just have to get used to as you contribute more to Mistral.
| from st2mistral.utils import http | ||
|
|
||
| from st2mistral import config | ||
| config.register_opts() |
There was a problem hiding this comment.
Why did you move this config section? There's a reason for the config section to be up top. It'll load config which will be used in the http module.
There was a problem hiding this comment.
This was to address the "module level import not at top of file" PEP8 violation, though I can see now that flake8 doesn't care for some reason (even though E402 is not being ignored).
Anyways, I can revert this, just part of the overall style fixes.
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
It's been a long-held constraint that the custom Jinja filters provided by StackStorm are only available in ActionChain workflows, and unavailable to Mistral workflows.
This PR aims to change that by duplicating the filter implementations from the
st2repo in this repo. This makes the same filters available in Mistral workflows without adding a dependency on thest2commonpackage.NOTE that this is a duplication of the filters in the
st2repo, so every time a filter is added or changed there, a PR must be opened here to keep things consistent. This PR only makes the existing custom filters available, not future ones.CHANGELOG for st2 was updated in StackStorm/st2@dd72546 since
st2mistraldoesn't really have one and that's probably where folks will look for the change anyways.Closes #29
BREAKING CHANGE
The
st2kvfunction here in Mistral previously decrypted keys by default. This PR adds a parameter to the underlying function that will force users to explicitly allow decryption, instead of doing it all the time. So, workflows that usest2kvto retrieve decrypted versions of ciphertext stored in datastore must now explicitly enable this decryption in the parameter, like so:Without this parameter, st2kv will not attempt decryption, and st2kv will return whatever value is stored at that key, whether or not it is ciphertext.
This change will make st2kv behavior more consistent with equivalent usage on the CLI/API and in ActionChains, where decryption is not performed by default.
Because
st2kvleverages the API, which provides decryption on its own, thedecrypt_kvfilter was not included in the list of filters moved over to Mistral in this PR.