Пример #1
0
    def get(self, request: Request, project, rule) -> Response:
        """
        Retrieve a rule

        Return details on an individual rule.

            {method} {path}

        """

        # Serialize Rule object
        serialized_rule = serialize(
            rule, request.user,
            RuleSerializer(request.GET.getlist("expand", [])))

        errors = []
        # Prepare Rule Actions that are SentryApp components using the meta fields
        for action in serialized_rule.get("actions", []):
            if action.get("_sentry_app_installation") and action.get(
                    "_sentry_app_component"):
                installation = SentryAppInstallation(
                    **action.get("_sentry_app_installation", {}))
                component = installation.prepare_ui_component(
                    SentryAppComponent(**action.get("_sentry_app_component")),
                    project,
                    action.get("settings"),
                )
                if component is None:
                    errors.append({
                        "detail":
                        f"Could not fetch details from {installation.sentry_app.name}"
                    })
                    action["disabled"] = True
                    continue

                action["formFields"] = component.schema.get("settings", {})

                # Delete meta fields
                del action["_sentry_app_installation"]
                del action["_sentry_app_component"]

        if len(errors):
            serialized_rule["errors"] = errors

        return Response(serialized_rule)
Пример #2
0
    def get(self, request: Request, organization, alert_rule) -> Response:
        """
        Fetch an alert rule.
        ``````````````````
        :auth: required
        """
        # Serialize Alert Rule
        serialized_rule = serialize(alert_rule, request.user, DetailedAlertRuleSerializer())

        # Prepare AlertRuleTriggerActions that are SentryApp components
        errors = []
        for trigger in serialized_rule.get("triggers", []):
            for action in trigger.get("actions", []):
                if action.get("_sentry_app_installation") and action.get("_sentry_app_component"):
                    installation = SentryAppInstallation(
                        **action.get("_sentry_app_installation", {})
                    )
                    component = installation.prepare_ui_component(
                        SentryAppComponent(**action.get("_sentry_app_component")),
                        None,
                        action.get("settings"),
                    )
                    if component is None:
                        errors.append(
                            {
                                "detail": f"Could not fetch details from {installation.sentry_app.name}"
                            }
                        )
                        action["disabled"] = True
                        continue

                    action["formFields"] = component.schema.get("settings", {})

                    # Delete meta fields
                    del action["_sentry_app_installation"]
                    del action["_sentry_app_component"]

        if len(errors):
            serialized_rule["errors"] = errors

        return Response(serialized_rule)