-
-
Notifications
You must be signed in to change notification settings - Fork 741
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
Refactor chatops to process input alias matching server side #2895
Merged
Merged
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
18aad27
MongoDB suffered the same fate, doesn't support chkconfig on newer ve…
tonybaloney 85e66f2
only yum was starting mongo, apt now does too.
tonybaloney e5045b9
get mongo status and start as a sudo
tonybaloney 5e17291
Update deb list for docker to use a different repo
tonybaloney 84bda92
Merge branch 'master' of https://github.com/StackStorm/st2
tonybaloney 4329758
Merge branch 'master' of https://github.com/StackStorm/st2
tonybaloney e991ae6
Merge remote-tracking branch 'me/master'
a01a5c2
add a util class for pattern matching, should not require API lib
tonybaloney af0a1b3
reset st2_deploy.sh
tonybaloney 1e1446b
massively simplify the util methods based on existing code (thanks @e…
tonybaloney 62ddf51
__all__ convention
tonybaloney dce3e12
add a chatops controller for sending chatops commands to
tonybaloney cdd294c
ipv6 binding support for the dev script
tonybaloney 88abf6e
correct command help text
tonybaloney dffd48b
Merge branch 'ipv6dev' into serversiderules
tonybaloney b6d70ec
added match custom command, added new exception type for alias matching
tonybaloney 166c2b3
moved the alias matching functions to new module name to better fit i…
tonybaloney 82fabd0
decorators in the wrong order
tonybaloney 003d220
change the rbac decorator to allow custom method names
tonybaloney 388d6a6
remove the permissions checks, I dont think they apply here
tonybaloney 7c2f07e
I didn't mean to do that
tonybaloney 3c0a989
add tests for the util module
tonybaloney bb10deb
extend tests
tonybaloney 0346b33
extend tests to checkout the matchin command logic
tonybaloney 80f04a7
debug detailed info on type error for jsexpose func wrapper
tonybaloney 5700dd9
change the alias API to call base class directly
tonybaloney de9a845
Merge branch 'serversiderules' of github.com:tonybaloney/st2 into ser…
tonybaloney 01249f2
return the options when failing on too many matches
tonybaloney 49f8e6e
return a dict instead of a list of tuples
tonybaloney c4600c1
flake it before you make it
tonybaloney 903b386
fix broken test
tonybaloney 3a77fc8
add test for api
tonybaloney 3f2cf9b
add tests for the API controller action, both pass and fail
tonybaloney a20ea84
take a stab at a new command in the client
tonybaloney d087128
Merge branch 'serversiderules' of github.com:tonybaloney/st2 into ser…
tonybaloney 8b7383b
change the way the client command is registered copying custom comman…
tonybaloney 84c83b3
lint fixes in new test and CLI command
tonybaloney a9c9798
add an alias execute command
tonybaloney d1cc1b5
use the correct resource type on execute command
tonybaloney e792d1b
remove conflicting parameters
tonybaloney 0a641e8
use mixin from action runner command, remove dep on DB methods outsid…
tonybaloney 3fc9790
set poll interval
tonybaloney 44f7244
use the print as a mixin from the action execute command
tonybaloney 6b95434
Merge branch 'serversiderules' of github.com:tonybaloney/st2 into ser…
tonybaloney 2031095
too hard to maintain 2 mixins.
tonybaloney 67d807b
Merge branch 'serversiderules' of github.com:tonybaloney/st2 into ser…
tonybaloney 164dffa
remove duplicate class properties
tonybaloney 94e988e
fix lint errors on api test
tonybaloney ac003c1
update based on comments from @kami
tonybaloney a615f99
include command in ActionAliasAmbiguityException
tonybaloney 041dc34
fix test with new logic
tonybaloney 8754931
flake fixes to new tests
tonybaloney aa43362
update the unit tests to patch out the UID generator instead of creat…
tonybaloney 3ac1ff3
pylint fixes
tonybaloney f002d3f
Merge branch 'serversiderules' of github.com:tonybaloney/st2 into ser…
tonybaloney 179f9e7
refactor the CLI client to not use the common classes and call the AP…
tonybaloney 3a519ab
use the correct base class for the command
tonybaloney 5c71fb0
add run_and_print method
tonybaloney f579dfd
mmmmm import *
tonybaloney 62ff395
move the match method to the manager not the model
tonybaloney 3096601
use a raw request method
tonybaloney 0ead24d
refactor match method to correct deserialize responses
tonybaloney e66bad4
use fields instead keys
tonybaloney f8ccbf5
parse the correct URL and format the response message
tonybaloney 23aa2a2
format the execute response with the execution ID and the chatops res…
tonybaloney 21a737a
fixed broken test with missing space in expected answer
tonybaloney File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pecan | ||
import six | ||
|
||
from mongoengine import ValidationError | ||
from st2api.controllers import resource | ||
from st2common import log as logging | ||
from st2common.exceptions.apivalidation import ValueValidationException | ||
from st2common.models.api.action import ActionAliasAPI | ||
from st2common.persistence.actionalias import ActionAlias | ||
from st2common.models.api.base import jsexpose | ||
from st2common.rbac.types import PermissionType | ||
from st2common.rbac.decorators import request_user_has_permission | ||
from st2common.rbac.decorators import request_user_has_resource_api_permission | ||
from st2common.rbac.decorators import request_user_has_resource_db_permission | ||
from st2common.util.alias_matching import (list_format_strings_from_aliases, | ||
match_command_to_alias) | ||
|
||
|
||
http_client = six.moves.http_client | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class ChatopsController(resource.ContentPackResourceController): | ||
""" | ||
Implements the RESTful interface for Chatops. | ||
A super-set of ActionAliasController | ||
""" | ||
model = ActionAliasAPI | ||
access = ActionAlias | ||
supported_filters = { | ||
'name': 'name', | ||
'pack': 'pack' | ||
} | ||
|
||
query_options = { | ||
'sort': ['pack', 'name'] | ||
} | ||
|
||
@request_user_has_permission(permission_type=PermissionType.ACTION_ALIAS_LIST) | ||
@jsexpose() | ||
def get_all(self, **kwargs): | ||
return list_format_strings_from_aliases( | ||
super(ChatopsController, self)._get_all(**kwargs)) | ||
|
||
@request_user_has_resource_db_permission(permission_type=PermissionType.ACTION_ALIAS_VIEW) | ||
@jsexpose(arg_types=[str]) | ||
def get_one(self, ref_or_id): | ||
return list_format_strings_from_aliases( | ||
super(ChatopsController, self)._get_one(ref_or_id))[0] | ||
|
||
@jsexpose(arg_types=[str], status_code=http_client.CREATED) | ||
@request_user_has_resource_api_permission(permission_type=PermissionType.ACTION_ALIAS_CREATE) | ||
def post(self, command): | ||
""" | ||
Run a chatops command | ||
|
||
Handles requests: | ||
POST /chatops/ | ||
""" | ||
try: | ||
# 1. Get aliases | ||
aliases = self.get_all() | ||
# 2. Match alias(es) to command | ||
match = match_command_to_alias(command, aliases) | ||
if len(match) > 1: | ||
raise AmbiguityError("Too much choice, not enough action (alias).") | ||
# 3. Check user's ability to execute action? | ||
# 4. Run action. | ||
# action_execution = whatever_the_api_is() | ||
except (ValidationError, ValueError, ValueValidationException) as e: | ||
# TODO : error on unmatched alias | ||
LOG.exception('Validation failed for action alias data=%s.', action_alias) | ||
pecan.abort(http_client.BAD_REQUEST, str(e)) | ||
return | ||
|
||
# extra = {'action_alias_db': action_alias_db} | ||
# LOG.audit('Action alias created. ActionAlias.id=%s' % (action_alias_db.id), extra=extra) | ||
|
||
return action_execution |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
opinions here?
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.
Is it possible to keep those methods / operations on the alias controller?
The reason is that right now StackStorm concept is called action alias and the code doesn't use "ChatOps" term anywhere else (afaik) so it might be a bit confusing to call it ChatOps here...