-
-
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
Changes from all commits
15e276b
94a664b
1eb048a
3e92db0
5d7cae2
abd84b9
ec96939
afce6e3
0bc2714
959f059
da225d8
bde144f
ec0be09
17c717d
2ad3b58
4fc10d9
e8d52a3
3206278
4b9d497
105a194
0c384a5
975c216
51a1ea8
5d9fc72
99b0067
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?