def get(self, request, organization):
        providers = []
        for provider in integrations.all():
            metadata = provider.metadata
            metadata = metadata and metadata._asdict() or None

            providers.append(
                {
                    'key': provider.key,
                    'name': provider.name,
                    'metadata': metadata,
                    'config': provider.get_config(),
                    'setupDialog': dict(
                        url='/organizations/{}/integrations/{}/setup/'.format(
                            organization.slug,
                            provider.key,
                        ),
                        **provider.setup_dialog_config
                    )
                }
            )

        return Response({
            'providers': providers,
        })
Exemplo n.º 2
0
    def get(self, request, group):
        has_issue_basic = features.has('organizations:integrations-issue-basic',
                                       group.organization,
                                       actor=request.user)

        has_issue_sync = features.has('organizations:integrations-issue-sync',
                                      group.organization,
                                      actor=request.user)

        if not (has_issue_basic or has_issue_sync):
            return self.respond([])

        providers = [
            i.key for i in integrations.all() if i.has_feature(IntegrationFeatures.ISSUE_BASIC) or i.has_feature(IntegrationFeatures.ISSUE_SYNC)
        ]
        return self.paginate(
            queryset=Integration.objects.filter(
                organizations=group.organization,
                provider__in=providers,
            ),
            request=request,
            order_by='name',
            on_results=lambda x: serialize(x, request.user, IntegrationIssueSerializer(group)),
            paginator_cls=OffsetPaginator,
        )
Exemplo n.º 3
0
    def get(self, request, organization):
        has_gitlab = features.has('organizations:gitlab-integration',
                                  organization,
                                  actor=request.user)
        has_jira_server = features.has('organizations:jira-server-integration',
                                       organization,
                                       actor=request.user)

        has_catchall = features.has('organizations:internal-catchall',
                                    organization,
                                    actor=request.user)
        providers = []
        for provider in integrations.all():
            if not has_gitlab and provider.key == 'gitlab':
                continue
            if not has_jira_server and provider.key == 'jira_server':
                continue
            if not has_catchall and provider.key in settings.SENTRY_INTERNAL_INTEGRATIONS:
                continue

            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers,
            organization=organization,
            serializer=IntegrationProviderSerializer(),
        )

        return Response({'providers': serialized})
    def get(self, request, organization):
        providers = []
        has_catchall = features.has('organizations:internal-catchall',
                                    organization,
                                    actor=request.user)

        for provider in integrations.all():
            metadata = provider.metadata
            metadata = metadata and metadata._asdict() or None
            if not has_catchall and provider.key in settings.SENTRY_INTERNAL_INTEGRATIONS:
                continue
            providers.append({
                'key':
                provider.key,
                'name':
                provider.name,
                'metadata':
                metadata,
                'canAdd':
                provider.can_add,
                'canAddProject':
                provider.can_add_project,
                'setupDialog':
                dict(url='/organizations/{}/integrations/{}/setup/'.format(
                    organization.slug,
                    provider.key,
                ),
                     **provider.setup_dialog_config)
            })

        return Response({
            'providers': providers,
        })
Exemplo n.º 5
0
    def get(self, request, organization):
        has_catchall = features.has('organizations:internal-catchall',
                                    organization,
                                    actor=request.user)
        has_github_apps = features.has('organizations:github-apps',
                                       organization,
                                       actor=request.user)

        providers = []
        for provider in integrations.all():
            internal_integrations = {
                i
                for i in settings.SENTRY_INTERNAL_INTEGRATIONS
                if i != 'github' or not has_github_apps
            }
            if not has_catchall and provider.key in internal_integrations:
                continue

            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers,
            organization=organization,
            serializer=IntegrationProviderSerializer(),
        )

        return Response({'providers': serialized})
    def get(self, request, organization):
        has_catchall = features.has('organizations:internal-catchall',
                                    organization,
                                    actor=request.user)
        has_github_apps = features.has('organizations:github-apps',
                                       organization,
                                       actor=request.user)

        providers = []
        for provider in integrations.all():
            internal_integrations = {
                i for i in settings.SENTRY_INTERNAL_INTEGRATIONS if i != 'github' or not has_github_apps}
            if not has_catchall and provider.key in internal_integrations:
                continue

            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers,
            organization=organization,
            serializer=IntegrationProviderSerializer(),
        )

        return Response({'providers': serialized})
    def get(self, request, organization):
        def is_provider_enabled(provider):
            if not provider.requires_feature_flag:
                return True
            feature_flag_name = "organizations:integrations-%s" % provider.key
            return features.has(feature_flag_name,
                                organization,
                                actor=request.user)

        providers = filter(is_provider_enabled, list(integrations.all()))

        providers.sort(key=lambda i: i.key)

        serialized = serialize(providers,
                               organization=organization,
                               serializer=IntegrationProviderSerializer())

        if "provider_key" in request.GET:
            serialized = [
                d for d in serialized
                if d["key"] == request.GET["provider_key"]
            ]

        if not serialized:
            return Response({"detail": "Providers do not exist"}, status=404)

        return Response({"providers": serialized})
Exemplo n.º 8
0
    def get(self, request, group):
        has_issue_basic = features.has(
            'organizations:integrations-issue-basic',
            group.organization,
            actor=request.user)

        has_issue_sync = features.has('organizations:integrations-issue-sync',
                                      group.organization,
                                      actor=request.user)

        if not (has_issue_basic or has_issue_sync):
            return self.respond([])

        providers = [
            i.key for i in integrations.all()
            if i.has_feature(IntegrationFeatures.ISSUE_BASIC)
            or i.has_feature(IntegrationFeatures.ISSUE_SYNC)
        ]
        return self.paginate(
            queryset=Integration.objects.filter(
                organizations=group.organization,
                provider__in=providers,
            ),
            request=request,
            order_by='name',
            on_results=lambda x: serialize(x, request.user,
                                           IntegrationIssueSerializer(group)),
            paginator_cls=OffsetPaginator,
        )
    def get(self, request, organization):
        providers = list(integrations.all())
        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers, organization=organization, serializer=IntegrationProviderSerializer()
        )

        return Response({"providers": serialized})
    def get(self, request, organization):
        providers = list(integrations.all())
        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers,
            organization=organization,
            serializer=IntegrationProviderSerializer(),
        )

        return Response({'providers': serialized})
Exemplo n.º 11
0
def register_plugins(settings, test_plugins=False):
    from pkg_resources import iter_entry_points
    from sentry.plugins.base import plugins

    # entry_points={
    #    'sentry.plugins': [
    #         'phabricator = sentry_phabricator.plugins:PhabricatorPlugin'
    #     ],
    # },
    entry_points = [
        "sentry.new_plugins",
        "sentry.test_only_plugins" if test_plugins else "sentry.plugins",
    ]

    for entry_point in entry_points:
        for ep in iter_entry_points(entry_point):
            try:
                plugin = ep.load()
            except Exception:
                import traceback

                click.echo("Failed to load plugin %r:\n%s" %
                           (ep.name, traceback.format_exc()),
                           err=True)
            else:
                plugins.register(plugin)

    for plugin in plugins.all(version=None):
        init_plugin(plugin)

    from sentry import integrations
    from sentry.utils.imports import import_string

    for integration_path in settings.SENTRY_DEFAULT_INTEGRATIONS:
        try:
            integration_cls = import_string(integration_path)
        except Exception:
            import traceback

            click.echo(
                "Failed to load integration %r:\n%s" %
                (integration_path, traceback.format_exc()),
                err=True,
            )
        else:
            integrations.register(integration_cls)

    for integration in integrations.all():
        try:
            integration.setup()
        except AttributeError:
            pass
Exemplo n.º 12
0
    def get(self, request, organization):
        has_bb = features.has('organizations:bitbucket-integration',
                              organization,
                              actor=request.user)
        has_ghe = features.has('organizations:github-enterprise',
                               organization,
                               actor=request.user)
        has_catchall = features.has('organizations:internal-catchall',
                                    organization,
                                    actor=request.user)
        has_github_apps = features.has('organizations:github-apps',
                                       organization,
                                       actor=request.user)
        has_jira = features.has('organizations:jira-integration',
                                organization,
                                actor=request.user)
        has_vsts = features.has('organizations:vsts-integration',
                                organization,
                                actor=request.user)

        providers = []
        for provider in integrations.all():
            internal_integrations = {
                i
                for i in settings.SENTRY_INTERNAL_INTEGRATIONS
            }
            if has_bb:
                internal_integrations.remove('bitbucket')
            if has_ghe:
                internal_integrations.remove('github_enterprise')
            if has_github_apps:
                internal_integrations.remove('github')
            if has_jira:
                internal_integrations.remove('jira')
            if has_vsts:
                internal_integrations.remove('vsts')
            if not has_catchall and provider.key in internal_integrations:
                continue

            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers,
            organization=organization,
            serializer=IntegrationProviderSerializer(),
        )

        return Response({'providers': serialized})
Exemplo n.º 13
0
def register_plugins(settings, raise_on_plugin_load_failure=False):
    from pkg_resources import iter_entry_points

    from sentry.plugins.base import plugins

    # entry_points={
    #    'sentry.plugins': [
    #         'phabricator = sentry_phabricator.plugins:PhabricatorPlugin'
    #     ],
    # },
    for ep in iter_entry_points("sentry.plugins"):
        try:
            plugin = ep.load()
        except Exception:
            import traceback

            click.echo(
                f"Failed to load plugin {ep.name!r}:\n{traceback.format_exc()}",
                err=True)
            if raise_on_plugin_load_failure:
                raise
        else:
            plugins.register(plugin)

    for plugin in plugins.all(version=None):
        init_plugin(plugin)

    from sentry import integrations
    from sentry.utils.imports import import_string

    for integration_path in settings.SENTRY_DEFAULT_INTEGRATIONS:
        try:
            integration_cls = import_string(integration_path)
        except Exception:
            import traceback

            click.echo(
                f"Failed to load integration {integration_path!r}:\n{traceback.format_exc()}",
                err=True,
            )
        else:
            integrations.register(integration_cls)

    for integration in integrations.all():
        try:
            integration.setup()
        except AttributeError:
            pass
Exemplo n.º 14
0
def has_alert_integration(project: Project) -> bool:
    org = project.organization

    # check integrations
    providers = filter(is_alert_rule_integration, list(integrations.all()))
    provider_keys = map(lambda x: cast(str, x.key), providers)
    if Integration.objects.filter(organizations=org,
                                  provider__in=provider_keys).exists():
        return True

    # check plugins
    from sentry.plugins.base import plugins

    project_plugins = plugins.for_project(project, version=None)
    return any(plugin.get_plugin_type() == "notification"
               for plugin in project_plugins)
Exemplo n.º 15
0
 def get(self, request, group):
     providers = [
         i.key for i in integrations.all() if i.has_feature(IntegrationFeatures.ISSUE_BASIC) or i.has_feature(IntegrationFeatures.ISSUE_SYNC)
     ]
     return self.paginate(
         # TODO(jess): This should filter by integrations that
         # are configured for the group's project once that is supported
         queryset=Integration.objects.filter(
             organizations=group.organization,
             provider__in=providers,
         ),
         request=request,
         order_by='name',
         on_results=lambda x: serialize(x, request.user, IntegrationIssueSerializer(group)),
         paginator_cls=OffsetPaginator,
     )
    def get(self, request, organization):
        has_bb = features.has('organizations:bitbucket-integration',
                              organization,
                              actor=request.user)
        has_ghe = features.has('organizations:github-enterprise',
                               organization,
                               actor=request.user)
        has_catchall = features.has('organizations:internal-catchall',
                                    organization,
                                    actor=request.user)
        has_github_apps = features.has('organizations:github-apps',
                                       organization,
                                       actor=request.user)
        has_jira = features.has('organizations:jira-integration',
                                organization,
                                actor=request.user)
        has_vsts = features.has('organizations:vsts-integration',
                                organization,
                                actor=request.user)

        providers = []
        for provider in integrations.all():
            internal_integrations = {i for i in settings.SENTRY_INTERNAL_INTEGRATIONS}
            if has_bb:
                internal_integrations.remove('bitbucket')
            if has_ghe:
                internal_integrations.remove('github_enterprise')
            if has_github_apps:
                internal_integrations.remove('github')
            if has_jira:
                internal_integrations.remove('jira')
            if has_vsts:
                internal_integrations.remove('vsts')
            if not has_catchall and provider.key in internal_integrations:
                continue

            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers,
            organization=organization,
            serializer=IntegrationProviderSerializer(),
        )

        return Response({'providers': serialized})
    def get(self, request, organization):

        providers = list(integrations.all())

        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers, organization=organization, serializer=IntegrationProviderSerializer()
        )

        if "provider_key" in request.GET:
            serialized = list(filter(lambda d: d["key"] == request.GET["provider_key"], serialized))

        if not serialized:
            return Response({"detail": "Providers do not exist"}, status=404)

        return Response({"providers": serialized})
Exemplo n.º 18
0
 def get(self, request, group):
     providers = [
         i.key for i in integrations.all()
         if i.has_feature(IntegrationFeatures.ISSUE_SYNC)
     ]
     return self.paginate(
         # TODO(jess): This should filter by integrations that
         # are configured for the group's project once that is supported
         queryset=Integration.objects.filter(
             organizations=group.organization,
             provider__in=providers,
         ),
         request=request,
         order_by='name',
         on_results=lambda x: serialize(x, request.user,
                                        IntegrationIssueSerializer(group)),
         paginator_cls=OffsetPaginator,
     )
    def get(self, request, organization):
        has_pagerduty = features.has("organizations:pagerduty-v2",
                                     organization,
                                     actor=request.user)

        providers = []
        for provider in integrations.all():
            if not has_pagerduty and provider.key == "pagerduty":
                continue

            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(providers,
                               organization=organization,
                               serializer=IntegrationProviderSerializer())

        return Response({"providers": serialized})
Exemplo n.º 20
0
    def get(self, request, organization):
        has_jira_server = features.has('organizations:jira-server-integration',
                                       organization,
                                       actor=request.user)
        providers = []
        for provider in integrations.all():
            if not has_jira_server and provider.key == 'jira_server':
                continue
            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(
            providers,
            organization=organization,
            serializer=IntegrationProviderSerializer(),
        )

        return Response({'providers': serialized})
    def get(self, request, organization):
        has_catchall = features.has("organizations:internal-catchall",
                                    organization,
                                    actor=request.user)

        providers = []
        for provider in integrations.all():
            if not has_catchall and provider.key in settings.SENTRY_INTERNAL_INTEGRATIONS:
                continue

            providers.append(provider)

        providers.sort(key=lambda i: i.key)

        serialized = serialize(providers,
                               organization=organization,
                               serializer=IntegrationProviderSerializer())

        return Response({"providers": serialized})
Exemplo n.º 22
0
def register_plugins(settings):
    from pkg_resources import iter_entry_points
    from sentry.plugins import plugins
    # entry_points={
    #    'sentry.plugins': [
    #         'phabricator = sentry_phabricator.plugins:PhabricatorPlugin'
    #     ],
    # },

    for ep in iter_entry_points('sentry.plugins'):
        try:
            plugin = ep.load()
        except Exception:
            import traceback
            click.echo(
                "Failed to load plugin %r:\n%s" % (ep.name, traceback.format_exc()),
                err=True
            )
        else:
            plugins.register(plugin)

    for plugin in plugins.all(version=None):
        init_plugin(plugin)

    from sentry import integrations
    from sentry.utils.imports import import_string
    for integration_path in settings.SENTRY_DEFAULT_INTEGRATIONS:
        try:
            integration_cls = import_string(integration_path)
        except Exception:
            import traceback
            click.echo(
                "Failed to load integration %r:\n%s" % (integration_path, traceback.format_exc()),
                err=True
            )
        else:
            integrations.register(integration_cls)

    for integration in integrations.all():
        try:
            integration.setup()
        except AttributeError:
            pass
    def get(self, request, organization):
        providers = []
        for provider in integrations.all():
            providers.append({
                'id':
                provider.id,
                'name':
                provider.name,
                'config':
                provider.get_config(),
                'setupUri':
                '/organizations/{}/integrations/{}/setup/'.format(
                    organization.slug,
                    provider.id,
                )
            })

        return Response({
            'providers': providers,
        })
Exemplo n.º 24
0
    def get(self, request, organization):
        providers = []
        for provider in integrations.all():
            providers.append({
                'key':
                provider.key,
                'name':
                provider.name,
                'config':
                provider.get_config(),
                'setupDialog':
                dict(url='/organizations/{}/integrations/{}/setup/'.format(
                    organization.slug,
                    provider.key,
                ),
                     **provider.setup_dialog_config)
            })

        return Response({
            'providers': providers,
        })
    def get(self, request, organization):
        providers = []
        for provider in integrations.all():
            providers.append(
                {
                    'id': provider.id,
                    'name': provider.name,
                    'config': provider.get_config(),
                    'setupDialog': dict(
                        url='/organizations/{}/integrations/{}/setup/'.format(
                            organization.slug,
                            provider.id,
                        ),
                        **provider.setup_dialog_config
                    )
                }
            )

        return Response({
            'providers': providers,
        })
Exemplo n.º 26
0
 def test_excludes_non_visible_integrations(self):
     # The VSTSExtension is not visible
     assert all(
         not isinstance(i, VstsExtensionIntegrationProvider)
         for i in integrations.all()
     )
Exemplo n.º 27
0
 def providers(self):
     # TODO: use feature flag in the future
     providers = filter(lambda x: x.has_stacktrace_linking,
                        list(integrations.all()))
     return map(lambda x: x.key, providers)
Exemplo n.º 28
0
 def providers(self):
     providers = filter(
         lambda x: x.has_feature(IntegrationFeatures.STACKTRACE_LINK),
         list(integrations.all()))
     return map(lambda x: x.key, providers)
Exemplo n.º 29
0
 def test_excludes_non_visible_integrations(self):
     # The VSTSExtension is not visible
     assert all(not isinstance(i, VstsExtensionIntegrationProvider)
                for i in integrations.all())