-
-
Notifications
You must be signed in to change notification settings - Fork 750
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 support for immutable_parameters in ChatOps action aliases #4786
Add support for immutable_parameters in ChatOps action aliases #4786
Conversation
One small feature enhancement would be to evaluate Jinja expressions for the static variables, that way we can load from the datastore. |
Okay, I'll add the jinja evaluation. |
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.
It's overall good feature to have and great addition to existing chatops
functionality 👍
Once we agree on naming, would be good to have st2docs update for this new feature in /~https://github.com/StackStorm/st2docs/blob/master/docs/source/chatops/aliases.rst (https://docs.stackstorm.com/chatops/aliases.html)
Please include a CHANGELOG record for this feature as well.
@namachieli @hd-deman @pixelrebel, you probably want to look at code/implementation too ^^ as someone who participated in #1704. cc @blag #chatops |
Thanks for taking the initiative and putting this together! I definitely like the simplicity of this PR. One minor complaint with this approach is that st2chatops does not display the static parameters with the Example alias with static parameters: ---
name: "remote_shell_cmd"
pack: "examples"
action_ref: "core.remote"
description: "Execute a command on a remote host via SSH."
formats:
- "run {{cmd}} {{hosts}}"
action_parameters:
- sudo: false And running the
doesn't display the static parameter or its value. So it would be nice if this had a companion PR in hubot-stackstorm to include static parameters in the command descriptions/help strings, but that isn't required. I'm also not a huge fan of how the static parameters silently override any explicitly matched parameters, as this may cause some serious issues for users. Consider this alias: ---
name: "clean_server"
pack: "examples"
action_ref: "core.remote"
description: "Clean up server files."
formats:
- "cleanup server"
action_parameters:
- cmd: "rm -rf /var/log/app"
- hosts: production To a user, they would see this
Now, if the user runs A note: I would expect people to want to specify static parameters for only some alias formats but not all of them. I don't think we should support this, since our RBAC implementation only resolves aliases, not individual alias formats. This would be properly implemented as two separate aliases: one with static parameters and one without. And aliases with different sets of static parameters should be specified as...separate aliases. |
I had thought about this and the initial idea was just to get the ball rolling. I wanted to mention this drawback but forgot. I think that a more suitable approach would be to simply invert the logic: parameters passed on the Of course, this PR will be accompanied with a
Not sure if I follow, you mean different static parameters for different formats? If this is what you mean, I absolutely agree: a different set of static parameters is a new action alias. |
I think this is good that chatops doesn't display static parameters and hiding defaults. That's one of the simplicity/abstraction advantages behind this feature. Priority/overriding params is a good catch. For this feature I'd stick to initial #1704 with immutable action params and what @blag suggests, meaning something that's defined in alias can't be changed by the input in chat. We need to make sure we test these edge cases. If we go that path, I also think it may be more clear to stick with |
I'm not sure I understand this completely. How is this any different than our (mutable) optional variables with default values? I agree with @armab - the usefulness of explicitly specifying action parameters in the alias is that they are immutable to ChatOps users, so the And since immutability is the important part of this feature (IMO), I think using the
Sorry if I wasn't clear - that is exactly what I mean. TL;DR: Not showing the immutable action parameters in the We have four different ways we can implement this (the 🛑 and ✅ are my opinion):
Aliases are kind of the ChatOps "interface" to actions, which are kind of the "implementation". And I guess hiding implementation details is fine as long as the interface (and documentation via the |
It's not different indeed in the effective outcome but leads to more natural format messages while still leaving room for overriding those defined parameters. I mean, I'm throwing feedback on the opinions put here and try to conciliate the views and understand where I should lead the PR. My personal opinion is:
Regarding showing static parameters on |
Cool, that sounds like a more or less consensus in minimal implementation 👍 !help additions could be added further to that. |
I'm personally +1 for a change like that since I believe it makes it more clear and obvious what is going on and also solves the immutable default parameters use case (which doesn't require user to write a custom wrapper action to handle that and specify immutable default parameter values). I also believe that at some point we also supported some syntax similar to this one, before the large action alias refactor a couple of years ago. |
cca78f0
to
7acb124
Compare
This last point, I'm not sure if I did the right thing.I couldn't find some function that would already give me the Datastore context and so on so I basically copied the |
I have also opened a |
e5619e6
to
5da99ff
Compare
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.
Other than the changelog shenanigans, this LGTM.
…rs to be supplied on every execution and values can be Jinja expressions.
92cdb98
to
b522b3d
Compare
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.
Looks good! Thanks again for the contribution 👍
I'll double up on that gratitude. This is something our users have been requesting for awhile. |
Hi, this is an attempt to solve #1704.
Closes #1704
There's an use case that consistently comes up where a dev wants a certain action alias but keep certain action parameters static. The current workarounds are to either have some really complex regexes or to create redundant dummy actions.
This proposal solves this by adding
action_parameters
parameter to the action alias definition. Here's a very simple example:Whatever is defined in
immutable_parameters
will be passed to the action unmodified. This is a very simple PR and I'd love to get suggestions on how to improve the concept and/or the tests.