示例#1
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        account = state['account']
        instance = state['instance']
        user = get_user_info(data['access_token'])
        scopes = sorted(VSTSIdentityProvider.oauth_scopes)

        integration = {
            'name': account['AccountName'],
            'external_id': account['AccountId'],
            'metadata': {
                'domain_name': instance,
                'scopes': scopes,
            },
            'user_identity': {
                'type': 'vsts',
                'external_id': user['id'],
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        try:
            IntegrationModel.objects.get(provider='vsts',
                                         external_id=account['AccountId'])
        except IntegrationModel.DoesNotExist:
            subscription_id, subscription_secret = self.create_subscription(
                instance, account['AccountId'], oauth_data)
            integration['metadata']['subscription'] = {
                'id': subscription_id,
                'secret': subscription_secret,
            }

        return integration
示例#2
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        account = state['account']
        instance = state['instance']
        user = get_user_info(data['access_token'])
        subscription_id, subscription_secret = self.create_subscription(
            instance, account['AccountId'], oauth_data)
        scopes = sorted(VSTSIdentityProvider.oauth_scopes)

        return {
            'name': account['AccountName'],
            'external_id': account['AccountId'],
            'metadata': {
                'domain_name': instance,
                'scopes': scopes,
                'subscription_id': subscription_id,
                'subscription_secret': subscription_secret,
            },
            'user_identity': {
                'type': 'vsts',
                'external_id': user['id'],
                'scopes': scopes,
                'data': oauth_data,
            },
        }
示例#3
0
    def dispatch(self, request, pipeline):
        if 'account' in request.POST:
            account_id = request.POST.get('account')
            accounts = pipeline.fetch_state(key='accounts')
            account = self.get_account_from_id(account_id, accounts)
            if account is not None:
                state = pipeline.fetch_state(key='identity')
                access_token = state['data']['access_token']
                pipeline.bind_state('account', account)
                return pipeline.next_step()

        state = pipeline.fetch_state(key='identity')
        access_token = state['data']['access_token']
        user = get_user_info(access_token)

        accounts = self.get_accounts(access_token, user['uuid'])
        logger.info('vsts.get_accounts',
                    extra={
                        'organization_id': pipeline.organization.id,
                        'user_id': request.user.id,
                        'accounts': accounts,
                    })
        accounts = accounts['value']
        pipeline.bind_state('accounts', accounts)
        account_form = AccountForm(accounts)
        return render_to_response(
            template='sentry/integrations/vsts-config.html',
            context={
                'form': account_form,
            },
            request=request,
        )
示例#4
0
    def dispatch(self, request, pipeline):
        if 'account' in request.POST:
            account_id = request.POST.get('account')
            accounts = pipeline.fetch_state(key='accounts')
            account = self.get_account_from_id(account_id, accounts)
            if account is not None:
                state = pipeline.fetch_state(key='identity')
                access_token = state['data']['access_token']
                pipeline.bind_state('account', account)
                return pipeline.next_step()

        state = pipeline.fetch_state(key='identity')
        access_token = state['data']['access_token']
        user = get_user_info(access_token)

        accounts = self.get_accounts(access_token, user['uuid'])
        logger.info(
            'vsts.get_accounts',
            extra={
                'organization_id': pipeline.organization.id,
                'user_id': request.user.id,
                'accounts': accounts,
            }

        )
        accounts = accounts['value']
        pipeline.bind_state('accounts', accounts)
        account_form = AccountForm(accounts)
        return render_to_response(
            template='sentry/integrations/vsts-config.html',
            context={
                'form': account_form,
            },
            request=request,
        )
示例#5
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        account = state['account']
        instance = state['instance']
        user = get_user_info(data['access_token'])
        scopes = sorted(VSTSIdentityProvider.oauth_scopes)

        integration = {
            'name': account['AccountName'],
            'external_id': account['AccountId'],
            'metadata': {
                'domain_name': instance,
                'scopes': scopes,
            },
            'user_identity': {
                'type': 'vsts',
                'external_id': user['id'],
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        try:
            IntegrationModel.objects.get(provider='vsts', external_id=account['AccountId'])
        except IntegrationModel.DoesNotExist:
            subscription_id, subscription_secret = self.create_subscription(
                instance, account['AccountId'], oauth_data)
            integration['metadata']['subscription'] = {
                'id': subscription_id,
                'secret': subscription_secret,
            }

        return integration
示例#6
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        account = state['account']
        user = get_user_info(data['access_token'])
        scopes = sorted(VSTSIdentityProvider.oauth_scopes)
        base_url = self.get_base_url(data['access_token'],
                                     account['accountId'])

        integration = {
            'name': account['accountName'],
            'external_id': account['accountId'],
            'metadata': {
                'domain_name': base_url,
                'scopes': scopes,
            },
            'user_identity': {
                'type': 'vsts',
                'external_id': user['id'],
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        try:
            integration_model = IntegrationModel.objects.get(
                provider='vsts',
                external_id=account['accountId'],
                status=ObjectStatus.VISIBLE,
            )
            # preserve previously created subscription information
            integration['metadata'][
                'subscription'] = integration_model.metadata['subscription']

            assert OrganizationIntegration.objects.filter(
                integration_id=integration_model.id,
                status=ObjectStatus.VISIBLE,
            ).exists()

        except (IntegrationModel.DoesNotExist, AssertionError, KeyError):
            subscription_id, subscription_secret = self.create_subscription(
                base_url, account['accountId'], oauth_data)
            integration['metadata']['subscription'] = {
                'id': subscription_id,
                'secret': subscription_secret,
            }

        return integration
示例#7
0
    def build_integration(self, state: Mapping[str, Any]) -> Mapping[str, Any]:
        data = state["identity"]["data"]
        oauth_data = self.get_oauth_data(data)
        account = state["account"]
        user = get_user_info(data["access_token"])
        scopes = sorted(self.get_scopes())
        base_url = self.get_base_url(data["access_token"],
                                     account["accountId"])

        integration: MutableMapping[str, Any] = {
            "name": account["accountName"],
            "external_id": account["accountId"],
            "metadata": {
                "domain_name": base_url,
                "scopes": scopes
            },
            "user_identity": {
                "type": "vsts",
                "external_id": user["id"],
                "scopes": scopes,
                "data": oauth_data,
            },
        }

        try:
            integration_model = IntegrationModel.objects.get(
                provider="vsts",
                external_id=account["accountId"],
                status=ObjectStatus.VISIBLE)
            # preserve previously created subscription information
            integration["metadata"][
                "subscription"] = integration_model.metadata["subscription"]

            assert OrganizationIntegration.objects.filter(
                organization_id=self.pipeline.organization.id,
                integration_id=integration_model.id,
                status=ObjectStatus.VISIBLE,
            ).exists()

        except (IntegrationModel.DoesNotExist, AssertionError, KeyError):
            subscription_id, subscription_secret = self.create_subscription(
                base_url, oauth_data)
            integration["metadata"]["subscription"] = {
                "id": subscription_id,
                "secret": subscription_secret,
            }

        return integration
示例#8
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        account = state['account']
        user = get_user_info(data['access_token'])
        scopes = sorted(VSTSIdentityProvider.oauth_scopes)
        base_url = self.get_base_url(data['access_token'], account['accountId'])

        integration = {
            'name': account['accountName'],
            'external_id': account['accountId'],
            'metadata': {
                'domain_name': base_url,
                'scopes': scopes,
            },
            'user_identity': {
                'type': 'vsts',
                'external_id': user['id'],
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        try:
            integration_model = IntegrationModel.objects.get(
                provider='vsts',
                external_id=account['accountId'],
                status=ObjectStatus.VISIBLE,
            )
            # preserve previously created subscription information
            integration['metadata']['subscription'] = integration_model.metadata['subscription']

            assert OrganizationIntegration.objects.filter(
                integration_id=integration_model.id,
                status=ObjectStatus.VISIBLE,
            ).exists()

        except (IntegrationModel.DoesNotExist, AssertionError, KeyError):
            subscription_id, subscription_secret = self.create_subscription(
                base_url, oauth_data)
            integration['metadata']['subscription'] = {
                'id': subscription_id,
                'secret': subscription_secret,
            }

        return integration
示例#9
0
    def dispatch(self, request, pipeline):
        if "account" in request.POST:
            account_id = request.POST.get("account")
            accounts = pipeline.fetch_state(key="accounts")
            account = self.get_account_from_id(account_id, accounts)
            if account is not None:
                state = pipeline.fetch_state(key="identity")
                access_token = state["data"]["access_token"]
                pipeline.bind_state("account", account)
                return pipeline.next_step()

        state = pipeline.fetch_state(key="identity")
        access_token = state["data"]["access_token"]
        user = get_user_info(access_token)

        accounts = self.get_accounts(access_token, user["uuid"])
        logger.info(
            "vsts.get_accounts",
            extra={
                "organization_id": pipeline.organization.id,
                "user_id": request.user.id,
                "accounts": accounts,
            },
        )
        accounts = accounts["value"]
        if not len(accounts):
            return render_to_response(
                template="sentry/integrations/vsts-config.html",
                context={"no_accounts": True},
                request=request,
            )
        pipeline.bind_state("accounts", accounts)
        account_form = AccountForm(accounts)
        return render_to_response(
            template="sentry/integrations/vsts-config.html",
            context={
                "form": account_form,
                "no_accounts": False
            },
            request=request,
        )