-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(ACI): Fix adding sentry app action to a workflow #103790
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
base: master
Are you sure you want to change the base?
Changes from all commits
3bab3af
69520e9
a790a41
5113166
22b269b
40f982d
5463d48
35b4c3d
8a19487
7dcd122
7b09cc2
32b1811
4d3c75d
25630f7
f69faf2
6fa8a91
4cb7e7e
85742c9
89b5435
0f5922d
7228774
a603836
e79e8a2
47ce60d
ea7ebbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| from sentry.rules.actions.integrations.create_ticket.form import IntegrationNotifyServiceForm | ||
| from sentry.rules.actions.notify_event_service import NotifyEventServiceForm | ||
| from sentry.rules.actions.sentry_apps.utils import validate_sentry_app_action | ||
| from sentry.sentry_apps.services.app.service import app_service | ||
| from sentry.sentry_apps.services.app import RpcSentryAppInstallation, app_service | ||
| from sentry.sentry_apps.utils.errors import SentryAppBaseError | ||
| from sentry.utils import json | ||
| from sentry.workflow_engine.models.action import Action | ||
|
|
@@ -206,31 +206,74 @@ def __init__(self, validated_data: dict[str, Any], organization: Organization) - | |
| self.validated_data = validated_data | ||
| self.organization = organization | ||
|
|
||
| def _get_sentry_app_installation( | ||
| self, sentry_app_identifier: SentryAppIdentifier, target_identifier: str | ||
| ) -> RpcSentryAppInstallation | None: | ||
| """ | ||
| Get the sentry app installation based on whether the target identifier is an installation id or sentry app id | ||
| We do not want to accept SentryAppIdentifier.SENTRY_APP_INSTALLATION_UUID long term, this is temporary until we migrate the data over | ||
| """ | ||
| installations = None | ||
| installation = None | ||
|
|
||
| if sentry_app_identifier == SentryAppIdentifier.SENTRY_APP_INSTALLATION_UUID: | ||
| installations = app_service.get_many( | ||
| filter=dict(uuids=[target_identifier], organization_id=self.organization.id) | ||
| ) | ||
| else: | ||
| installations = app_service.get_many( | ||
| filter=dict(app_ids=[int(target_identifier)], organization_id=self.organization.id) | ||
This comment was marked as outdated.
Sorry, something went wrong.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good thing it is a number
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Unhandled ValueError when converting target identifier to intWhen |
||
| ) | ||
ceorourke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if installations: | ||
| installation = installations[0] | ||
|
|
||
| return installation | ||
|
|
||
| def clean_data(self) -> dict[str, Any]: | ||
| is_sentry_app_installation = ( | ||
| SentryAppIdentifier(self.validated_data["config"]["sentry_app_identifier"]) | ||
| == SentryAppIdentifier.SENTRY_APP_INSTALLATION_UUID | ||
| sentry_app_identifier = SentryAppIdentifier( | ||
| self.validated_data["config"]["sentry_app_identifier"] | ||
| ) | ||
| target_identifier = self.validated_data["config"]["target_identifier"] | ||
| installation = self._get_sentry_app_installation(sentry_app_identifier, target_identifier) | ||
| if not installation: | ||
| raise ValidationError("Sentry app installation not found.") | ||
|
|
||
| if sentry_app_identifier == SentryAppIdentifier.SENTRY_APP_INSTALLATION_UUID: | ||
| # convert to use sentry_app_id until we can migrate all the data | ||
| self.validated_data["config"][ | ||
| "sentry_app_identifier" | ||
| ] = SentryAppIdentifier.SENTRY_APP_ID | ||
| self.validated_data["config"]["target_identifier"] = str(installation.sentry_app.id) | ||
|
|
||
| settings = self.validated_data["data"].get("settings", []) | ||
| action = { | ||
| "settings": self.validated_data["data"]["settings"], | ||
| "sentryAppInstallationUuid": ( | ||
| self.validated_data["config"]["target_identifier"] | ||
| if is_sentry_app_installation | ||
| else None | ||
| ), | ||
| "settings": settings, | ||
| "sentryAppInstallationUuid": installation.uuid, | ||
| } | ||
| try: | ||
| validate_sentry_app_action(action) | ||
|
|
||
| if not settings: | ||
| # XXX: it's only ok to not pass settings if there is no sentry app schema | ||
| # this means the app doesn't expect any settings | ||
| components = app_service.find_app_components(app_id=installation.sentry_app.id) | ||
| if any( | ||
| component.app_schema | ||
| for component in components | ||
| if component.type == "alert-rule-action" | ||
| ): | ||
| raise ValidationError("'settings' is a required property") | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| else: | ||
| # Sentry app config blob expects value to be a string | ||
| settings = self.validated_data["data"]["settings"] | ||
| for setting in settings: | ||
| if setting.get("value") is not None and not isinstance(setting["value"], str): | ||
| setting["value"] = json.dumps(setting["value"]) | ||
| try: | ||
| # Only call creator for Sentry Apps with UI Components (settings) for actions | ||
| validate_sentry_app_action(action) | ||
| except SentryAppBaseError as e: | ||
| raise ValidationError(e.message) from e | ||
|
|
||
| return self.validated_data | ||
| except SentryAppBaseError as e: | ||
| raise ValidationError(e.message) from e | ||
| return self.validated_data | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be updating the validated data here to only save sentry app actions with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have actions with the uuid saved in the db today so we don't want to block being able to update those. After we run the migration maybe part of the cleanup can be enforcing only that identifier.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If somebody is trying to update an action with a uuid we could update that action to save it with the sentry app id so we don't have any more actions being saved with uuid
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated 👍 |
||
|
|
||
|
|
||
| @action_validator_registry.register(Action.Type.WEBHOOK) | ||
|
|
||
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 typing gonna complain this needs to be
RpcSentryAppInstallation | None = None?