def test_audits(self, create_audit_entry):
        InternalCreator.run(
            name="nulldb",
            user=self.user,
            author="Sentry",
            organization=self.org,
            scopes=("project:read",),
            webhook_url="http://example.com",
            schema={"elements": [self.create_issue_link_schema()]},
            request=MagicMock(),
        )

        call = faux(create_audit_entry)
        assert call.kwarg_equals("organization", self.org)
        assert call.kwarg_equals("target_object", self.org.id)
        assert call.kwarg_equals("event", AuditLogEntryEvent.INTERNAL_INTEGRATION_ADD)
Beispiel #2
0
    def post_install(self, integration, organization, extra=None):
        # check if we have an Vercel internal installation already
        if SentryAppInstallationForProvider.objects.filter(
                organization=organization, provider="vercel").exists():
            logger.info(
                "vercel.post_install.installation_exists",
                extra={"organization_id": organization.id},
            )
            return

        user = User.objects.get(id=extra.get("user_id"))
        data = {
            "name": "Vercel Internal Integration",
            "author": "Auto-generated by Sentry",
            "organization": organization,
            "overview": internal_integration_overview.strip(),
            "user": user,
            "scopes": ["project:releases", "project:read", "project:write"],
        }
        # create the internal integration and link it to the join table
        sentry_app = InternalCreator.run(**data)
        sentry_app_installation = SentryAppInstallation.objects.get(
            sentry_app=sentry_app)
        SentryAppInstallationForProvider.objects.create(
            sentry_app_installation=sentry_app_installation,
            organization=organization,
            provider="vercel",
        )
Beispiel #3
0
    def test_audits(self, create_audit_entry):
        InternalCreator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=MagicMock(),
        )

        call = faux(create_audit_entry)
        assert call.kwarg_equals('organization', self.org)
        assert call.kwarg_equals('target_object', self.org.id)
        assert call.kwarg_equals('event', AuditLogEntryEvent.INTERNAL_INTEGRATION_ADD)
 def run_creator(self, **kwargs):
     return InternalCreator.run(
         name="nulldb",
         user=self.user,
         organization=self.org,
         scopes=("project:read", ),
         webhook_url="http://example.com",
         schema={"elements": [self.create_issue_link_schema()]},
         **kwargs)
Beispiel #5
0
    def enable_scim(self, user):
        from sentry.mediators.sentry_apps import InternalCreator
        from sentry.models import SentryAppInstallation, SentryAppInstallationForProvider

        if (not self.get_provider().can_use_scim(self.organization, user)
                or self.flags.scim_enabled is True):
            logger.warning(
                "SCIM already enabled",
                extra={"organization_id": self.organization.id},
            )
            return

        # check if we have a scim app already

        if SentryAppInstallationForProvider.objects.filter(
                organization=self.organization, provider="okta_scim").exists():
            logger.warning(
                "SCIM installation already exists",
                extra={"organization_id": self.organization.id},
            )
            return

        data = {
            "name":
            "SCIM Internal Integration",
            "author":
            "Auto-generated by Sentry",
            "organization":
            self.organization,
            "overview":
            SCIM_INTERNAL_INTEGRATION_OVERVIEW,
            "user":
            user,
            "scopes": [
                "member:read",
                "member:write",
                "member:admin",
                "team:write",
                "team:admin",
            ],
        }
        # create the internal integration and link it to the join table
        sentry_app = InternalCreator.run(**data)
        sentry_app_installation = SentryAppInstallation.objects.get(
            sentry_app=sentry_app)
        SentryAppInstallationForProvider.objects.create(
            sentry_app_installation=sentry_app_installation,
            organization=self.organization,
            provider=f"{self.provider}_scim",
        )
        self.flags.scim_enabled = True
    def test_records_analytics(self, create_audit_entry, record):
        sentry_app = InternalCreator.run(
            name="nulldb",
            user=self.user,
            author="Sentry",
            organization=self.org,
            scopes=("project:read", ),
            webhook_url="http://example.com",
            schema={"elements": [self.create_issue_link_schema()]},
            request=MagicMock(),
        )

        assert faux(record).args_equals("internal_integration.created")
        assert faux(record).kwargs == {
            "user_id": self.user.id,
            "organization_id": self.org.id,
            "sentry_app": sentry_app.slug,
        }
Beispiel #7
0
    def test_records_analytics(self, create_audit_entry, record):
        sentry_app = InternalCreator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=MagicMock(),
        )

        assert faux(record).args_equals('internal_integration.created')
        assert faux(record).kwargs == {
            'user_id': self.user.id,
            'organization_id': self.org.id,
            'sentry_app': sentry_app.slug,
        }
Beispiel #8
0
    def post_install(self, integration, organization, extra=None):
        # add new configuration information to metadata
        configurations = integration.metadata.get("configurations") or {}
        configurations[integration.metadata["installation_id"]] = {
            "access_token": integration.metadata["access_token"],
            "webhook_id": integration.metadata["webhook_id"],
            "organization_id": organization.id,
        }
        integration.metadata["configurations"] = configurations
        integration.save()

        # check if we have an installation already
        if SentryAppInstallationForProvider.objects.filter(
                organization=organization, provider="vercel").exists():
            logger.info(
                "vercel.post_install.installation_exists",
                extra={"organization_id": organization.id},
            )
            return

        user = User.objects.get(id=extra.get("user_id"))
        data = {
            "name": "Vercel Internal Integration",
            "author": "Auto-generated by Sentry",
            "organization": organization,
            "overview": internal_integration_overview.strip(),
            "user": user,
            "scopes": ["project:releases", "project:read", "project:write"],
        }
        # create the internal integration and link it to the join table
        sentry_app = InternalCreator.run(**data)
        sentry_app_installation = SentryAppInstallation.objects.get(
            sentry_app=sentry_app)
        SentryAppInstallationForProvider.objects.create(
            sentry_app_installation=sentry_app_installation,
            organization=organization,
            provider="vercel",
        )