-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Changed to be able to read user-scope datastore value via '{{ st2kv.user }}' notation. #4463
Changed to be able to read user-scope datastore value via '{{ st2kv.user }}' notation. #4463
Conversation
9cdccb5
to
efcde1f
Compare
…ser }}' notation.
efcde1f
to
942ae59
Compare
st2common/st2common/util/param.py
Outdated
user = action_context['user'] if 'user' in action_context else None | ||
user = action_context['api_user'] if 'api_user' in action_context else user | ||
if user: | ||
system_keyvalue_context[USER_SCOPE] = UserKeyValueLookup(scope=FULL_USER_SCOPE, user=user) |
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'm fine with this approach, but we should document this behavior (something along the lines that st2kv.user.foo
will only work for actions which have user context attached to and and are executed via the API or similar).
Also, what will happen if we are unable to read user from the context and action author references st2kv.user in a default value? I assume it will throw a template rendering error.
If that's the case, we should consider doing the following:
- Add a test case for this scenario
- Instead of generic template rendering error being thrown, we should see if we can throw a more user-friendly error
Another option is to default it to the system user (stanley
), we do this in other places.
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.
Besides that, I'm fine with this change.
Nice work 👍
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.
Thank you very much for your review. I got it. I'll do that soon!
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.
@userlocalhost Can you please also open st2docs PR which documents this behavior?
4730eab
to
6ab5372
Compare
…no user and api_user are specified for rendering parameter.
6ab5372
to
832045c
Compare
Thank you again for your review and telling me advices to brush up.
I've taken care of this problem by the idea that system user fills in for the one. |
I fixed the points that you mentioned, would you please review this patch, @Kami? |
Thanks, I will have a look later today. |
Thank you very much! |
Merged, thanks. Please also open a corresponding st2docs PR when you get a chance :) |
I think we don't have to amend st2docs because the explanation of this feature has already been described at the Datastore page in st2docs. This is an excerpt from it.
I think this description is good enough to explain how to use this and what limitations are. |
Background
The change of (#3199) and document of Datastore say StackStorm supports the I/F to get datastore value via {{ st2kv.system }} and {{ st2kv.user }}.
Related Issue
Problem
StackStorm didn't have an implementation to accept
{{ st2kv.user }}
expression.Change
This implements the processing to accept
{{ st2kv.user }}
notation and render it to user-scope value in datastore which is associated with executed user.