Exemplo n.º 1
0
 def get(self, request: Request, project) -> Response:
     context = serialize(
         [plugin for plugin in plugins.configurable_for_project(project, version=None)],
         request.user,
         PluginSerializer(project),
     )
     return Response(context)
Exemplo n.º 2
0
    def serialize(self, obj, attrs, user):
        from sentry.plugins.base import plugins

        def get_value_with_default(key):
            value = attrs["options"].get(key)
            if value is not None:
                return value
            return projectoptions.get_well_known_default(
                key, epoch=attrs["options"].get("sentry:option-epoch"))

        data = super(DetailedProjectSerializer,
                     self).serialize(obj, attrs, user)
        data.update({
            "latestRelease":
            attrs["latest_release"],
            "options": {
                "sentry:csp_ignored_sources_defaults":
                bool(attrs["options"].get(
                    "sentry:csp_ignored_sources_defaults", True)),
                "sentry:csp_ignored_sources":
                "\n".join(
                    attrs["options"].get("sentry:csp_ignored_sources", [])
                    or []),
                "sentry:reprocessing_active":
                bool(attrs["options"].get("sentry:reprocessing_active",
                                          False)),
                "filters:blacklisted_ips":
                "\n".join(attrs["options"].get("sentry:blacklisted_ips", [])),
                u"filters:{}".format(FilterTypes.RELEASES):
                "\n".join(attrs["options"].get(
                    u"sentry:{}".format(FilterTypes.RELEASES), [])),
                u"filters:{}".format(FilterTypes.ERROR_MESSAGES):
                "\n".join(attrs["options"].get(
                    u"sentry:{}".format(FilterTypes.ERROR_MESSAGES), [])),
                "feedback:branding":
                attrs["options"].get("feedback:branding", "1") == "1",
            },
            "digestsMinDelay":
            attrs["options"].get("digests:mail:minimum_delay",
                                 digests.minimum_delay),
            "digestsMaxDelay":
            attrs["options"].get("digests:mail:maximum_delay",
                                 digests.maximum_delay),
            "subjectPrefix":
            attrs["options"].get("mail:subject_prefix",
                                 options.get("mail.subject-prefix")),
            "allowedDomains":
            attrs["options"].get("sentry:origins", ["*"]),
            "resolveAge":
            int(attrs["options"].get("sentry:resolve_age", 0)),
            "dataScrubber":
            bool(attrs["options"].get("sentry:scrub_data", True)),
            "dataScrubberDefaults":
            bool(attrs["options"].get("sentry:scrub_defaults", True)),
            "safeFields":
            attrs["options"].get("sentry:safe_fields", []),
            "storeCrashReports":
            bool(attrs["options"].get("sentry:store_crash_reports", False)),
            "sensitiveFields":
            attrs["options"].get("sentry:sensitive_fields", []),
            "subjectTemplate":
            attrs["options"].get("mail:subject_template")
            or DEFAULT_SUBJECT_TEMPLATE.template,
            "securityToken":
            attrs["options"].get("sentry:token") or obj.get_security_token(),
            "securityTokenHeader":
            attrs["options"].get("sentry:token_header"),
            "verifySSL":
            bool(attrs["options"].get("sentry:verify_ssl", False)),
            "scrubIPAddresses":
            bool(attrs["options"].get("sentry:scrub_ip_address", False)),
            "scrapeJavaScript":
            bool(attrs["options"].get("sentry:scrape_javascript", True)),
            "groupingConfig":
            get_value_with_default("sentry:grouping_config"),
            "groupingEnhancements":
            get_value_with_default("sentry:grouping_enhancements"),
            "groupingEnhancementsBase":
            get_value_with_default("sentry:grouping_enhancements_base"),
            "fingerprintingRules":
            get_value_with_default("sentry:fingerprinting_rules"),
            "organization":
            attrs["org"],
            "plugins":
            serialize(
                [
                    plugin for plugin in plugins.configurable_for_project(
                        obj, version=None) if plugin.has_project_conf()
                ],
                user,
                PluginSerializer(obj),
            ),
            "platforms":
            attrs["platforms"],
            "processingIssues":
            attrs["processing_issues"],
            "defaultEnvironment":
            attrs["options"].get("sentry:default_environment"),
            "relayPiiConfig":
            attrs["options"].get("sentry:relay_pii_config"),
            "builtinSymbolSources":
            get_value_with_default("sentry:builtin_symbol_sources"),
            "symbolSources":
            attrs["options"].get("sentry:symbol_sources"),
        })
        return data
Exemplo n.º 3
0
    def serialize(self, obj, attrs, user):
        from sentry.plugins.base import plugins

        def get_value_with_default(key):
            value = attrs["options"].get(key)
            if value is not None:
                return value
            return projectoptions.get_well_known_default(
                key, epoch=attrs["options"].get("sentry:option-epoch")
            )

        data = super().serialize(obj, attrs, user)
        data.update(
            {
                "latestRelease": attrs["latest_release"],
                "options": {
                    "sentry:csp_ignored_sources_defaults": bool(
                        attrs["options"].get("sentry:csp_ignored_sources_defaults", True)
                    ),
                    "sentry:csp_ignored_sources": "\n".join(
                        attrs["options"].get("sentry:csp_ignored_sources", []) or []
                    ),
                    "sentry:reprocessing_active": bool(
                        attrs["options"].get("sentry:reprocessing_active", False)
                    ),
                    "filters:blacklisted_ips": "\n".join(
                        attrs["options"].get("sentry:blacklisted_ips", [])
                    ),
                    f"filters:{FilterTypes.RELEASES}": "\n".join(
                        attrs["options"].get(f"sentry:{FilterTypes.RELEASES}", [])
                    ),
                    f"filters:{FilterTypes.ERROR_MESSAGES}": "\n".join(
                        attrs["options"].get(f"sentry:{FilterTypes.ERROR_MESSAGES}", [])
                    ),
                    "feedback:branding": attrs["options"].get("feedback:branding", "1") == "1",
                },
                "digestsMinDelay": attrs["options"].get(
                    "digests:mail:minimum_delay", digests.minimum_delay
                ),
                "digestsMaxDelay": attrs["options"].get(
                    "digests:mail:maximum_delay", digests.maximum_delay
                ),
                "subjectPrefix": attrs["options"].get(
                    "mail:subject_prefix", options.get("mail.subject-prefix")
                ),
                "allowedDomains": attrs["options"].get("sentry:origins", ["*"]),
                "resolveAge": int(attrs["options"].get("sentry:resolve_age", 0)),
                "dataScrubber": bool(attrs["options"].get("sentry:scrub_data", True)),
                "dataScrubberDefaults": bool(attrs["options"].get("sentry:scrub_defaults", True)),
                "safeFields": attrs["options"].get("sentry:safe_fields", []),
                "storeCrashReports": convert_crashreport_count(
                    attrs["options"].get("sentry:store_crash_reports"), allow_none=True
                ),
                "sensitiveFields": attrs["options"].get("sentry:sensitive_fields", []),
                "subjectTemplate": attrs["options"].get("mail:subject_template")
                or DEFAULT_SUBJECT_TEMPLATE.template,
                "securityToken": attrs["options"].get("sentry:token") or obj.get_security_token(),
                "securityTokenHeader": attrs["options"].get("sentry:token_header"),
                "verifySSL": bool(attrs["options"].get("sentry:verify_ssl", False)),
                "scrubIPAddresses": bool(attrs["options"].get("sentry:scrub_ip_address", False)),
                "scrapeJavaScript": bool(attrs["options"].get("sentry:scrape_javascript", True)),
                "groupingConfig": get_value_with_default("sentry:grouping_config"),
                "groupingEnhancements": get_value_with_default("sentry:grouping_enhancements"),
                "groupingEnhancementsBase": get_value_with_default(
                    "sentry:grouping_enhancements_base"
                ),
                "secondaryGroupingExpiry": get_value_with_default(
                    "sentry:secondary_grouping_expiry"
                ),
                "secondaryGroupingConfig": get_value_with_default(
                    "sentry:secondary_grouping_config"
                ),
                "fingerprintingRules": get_value_with_default("sentry:fingerprinting_rules"),
                "organization": attrs["org"],
                "plugins": serialize(
                    [
                        plugin
                        for plugin in plugins.configurable_for_project(obj, version=None)
                        if plugin.has_project_conf()
                    ],
                    user,
                    PluginSerializer(obj),
                ),
                "platforms": attrs["platforms"],
                "processingIssues": attrs["processing_issues"],
                "defaultEnvironment": attrs["options"].get("sentry:default_environment"),
                "relayPiiConfig": attrs["options"].get("sentry:relay_pii_config"),
                "builtinSymbolSources": get_value_with_default("sentry:builtin_symbol_sources"),
                "dynamicSampling": get_value_with_default("sentry:dynamic_sampling"),
                "eventProcessing": {
                    "symbolicationDegraded": False,
                },
            }
        )
        custom_symbol_sources_json = attrs["options"].get("sentry:symbol_sources")
        try:
            sources = parse_sources(custom_symbol_sources_json, False)
        except Exception:
            # In theory sources stored on the project should be valid. If they are invalid, we don't
            # want to abort serialization just for sources, so just return an empty list instead of
            # returning sources with their secrets included.
            serialized_sources = "[]"
        else:
            redacted_sources = redact_source_secrets(sources)
            serialized_sources = json.dumps(redacted_sources)

        data.update(
            {
                "symbolSources": serialized_sources,
            }
        )

        return data
Exemplo n.º 4
0
 def plugins(self):
     return [plugins.configurable_for_project(project) for project in self.projects]
Exemplo n.º 5
0
def get_plugins_with_status(project):
    return [
        (plugin, safe_execute(plugin.is_enabled, project, _with_transaction=False))
        for plugin in plugins.configurable_for_project(project, version=None)
    ]