Ejemplo n.º 1
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        user = get_user_info(data['access_token'], state['installation_data'])
        group = self.get_group_info(data['access_token'], state['installation_data'])
        scopes = sorted(GitlabIdentityProvider.oauth_scopes)
        base_url = state['installation_data']['url']

        integration = {
            'name': group['name'],
            'external_id': u'{}:{}'.format(urlparse(base_url).netloc, group['id']),
            'metadata': {
                'icon': group['avatar_url'],
                'domain_name': group['web_url'].replace('https://', ''),
                'scopes': scopes,
                'verify_ssl': state['installation_data']['verify_ssl'],
                'base_url': base_url,
            },
            'user_identity': {
                'type': 'gitlab',
                'external_id': user['id'],
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        return integration
Ejemplo n.º 2
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        user = get_user_info(data['access_token'], state['installation_data'])
        group = self.get_group_info(data['access_token'], state['installation_data'])
        scopes = sorted(GitlabIdentityProvider.oauth_scopes)
        base_url = state['installation_data']['url']

        integration = {
            'name': group['name'],
            'external_id': u'{}:{}'.format(urlparse(base_url).netloc, group['id']),
            'metadata': {
                'icon': group['avatar_url'],
                'domain_name': group['web_url'].replace('https://', ''),
                'scopes': scopes,
                'verify_ssl': state['installation_data']['verify_ssl'],
                'base_url': base_url,
            },
            'user_identity': {
                'type': 'gitlab',
                'external_id': u'{}:{}'.format(urlparse(base_url).netloc, user['id']),
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        return integration
Ejemplo n.º 3
0
    def build_integration(self, state):
        data = state["identity"]["data"]

        # Gitlab requires the client_id and client_secret for refreshing the access tokens
        oauth_config = state.get("oauth_config_information", {})
        oauth_data = {
            **get_oauth_data(data),
            "client_id": oauth_config.get("client_id"),
            "client_secret": oauth_config.get("client_secret"),
        }

        user = get_user_info(data["access_token"], state["installation_data"])
        group = self.get_group_info(data["access_token"],
                                    state["installation_data"])
        include_subgroups = state["installation_data"]["include_subgroups"]
        scopes = sorted(GitlabIdentityProvider.oauth_scopes)
        base_url = state["installation_data"]["url"]

        hostname = urlparse(base_url).netloc
        verify_ssl = state["installation_data"]["verify_ssl"]

        # Generate a hash to prevent stray hooks from being accepted
        # use a consistent hash so that reinstalls/shared integrations don't
        # rotate secrets.
        secret = sha1_text("".join(
            [hostname, state["installation_data"]["client_id"]]))

        integration = {
            "name": group["full_name"],
            # Splice the gitlab host and project together to
            # act as unique link between a gitlab instance, group + sentry.
            # This value is embedded then in the webhook token that we
            # give to gitlab to allow us to find the integration a hook came
            # from.
            "external_id": "{}:{}".format(hostname, group["id"]),
            "metadata": {
                "icon": group["avatar_url"],
                "instance": hostname,
                "domain_name": "{}/{}".format(hostname, group["full_path"]),
                "scopes": scopes,
                "verify_ssl": verify_ssl,
                "base_url": base_url,
                "webhook_secret": secret.hexdigest(),
                "group_id": group["id"],
                "include_subgroups": include_subgroups,
            },
            "user_identity": {
                "type": "gitlab",
                "external_id": "{}:{}".format(hostname, user["id"]),
                "scopes": scopes,
                "data": oauth_data,
            },
        }
        return integration
Ejemplo n.º 4
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = get_oauth_data(data)
        user = get_user_info(data['access_token'], state['installation_data'])
        group = self.get_group_info(data['access_token'],
                                    state['installation_data'])
        scopes = sorted(GitlabIdentityProvider.oauth_scopes)
        base_url = state['installation_data']['url']

        hostname = urlparse(base_url).netloc
        verify_ssl = state['installation_data']['verify_ssl']

        # Generate a hash to prevent stray hooks from being accepted
        # use a consistent hash so that reinstalls/shared integrations don't
        # rotate secrets.
        secret = sha1_text(''.join(
            [hostname, state['installation_data']['client_id']]))

        integration = {
            'name': group['full_name'],
            # Splice the gitlab host and project together to
            # act as unique link between a gitlab instance, group + sentry.
            # This value is embedded then in the webook token that we
            # give to gitlab to allow us to find the integration a hook came
            # from.
            'external_id': u'{}:{}'.format(hostname, group['full_path']),
            'metadata': {
                'icon': group['avatar_url'],
                'instance': hostname,
                'domain_name': u'{}/{}'.format(hostname, group['full_path']),
                'scopes': scopes,
                'verify_ssl': verify_ssl,
                'base_url': base_url,
                'webhook_secret': secret.hexdigest(),
                'group_id': group['id'],
            },
            'user_identity': {
                'type': 'gitlab',
                'external_id': u'{}:{}'.format(hostname, user['id']),
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        return integration
Ejemplo n.º 5
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        user = get_user_info(data['access_token'], state['installation_data'])
        group = self.get_group_info(data['access_token'],
                                    state['installation_data'])
        scopes = sorted(GitlabIdentityProvider.oauth_scopes)
        base_url = state['installation_data']['url']
        domain_name = '%s/%s' % (re.sub(r'https?://', '',
                                        base_url), group['path'])
        verify_ssl = state['installation_data']['verify_ssl']

        webhook_id, webhook_secret = self.create_webhook(
            base_url, data['access_token'], verify_ssl)

        integration = {
            'name': group['name'],
            'external_id':
            u'{}:{}'.format(urlparse(base_url).netloc, group['id']),
            'metadata': {
                'icon': group['avatar_url'],
                'domain_name': domain_name,
                'scopes': scopes,
                'verify_ssl': verify_ssl,
                'base_url': base_url,
                'webhook': {
                    'secret': webhook_secret,
                    'id': webhook_id,
                }
            },
            'user_identity': {
                'type':
                'gitlab',
                'external_id':
                u'{}:{}'.format(urlparse(base_url).netloc, user['id']),
                'scopes':
                scopes,
                'data':
                oauth_data,
            },
        }

        return integration
Ejemplo n.º 6
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        user = get_user_info(data['access_token'], state['installation_data'])
        group = self.get_group_info(data['access_token'], state['installation_data'])
        scopes = sorted(GitlabIdentityProvider.oauth_scopes)
        base_url = state['installation_data']['url']

        hostname = urlparse(base_url).netloc
        verify_ssl = state['installation_data']['verify_ssl']

        # Generate a hash to prevent stray hooks from being accepted
        # use a consistent hash so that reinstalls/shared integrations don't
        # rotate secrets.
        secret = sha1_text(''.join([hostname, state['installation_data']['client_id']]))

        integration = {
            'name': group['name'],
            # Splice the gitlab host and project together to
            # act as unique link between a gitlab instance, group + sentry.
            # This value is embedded then in the webook token that we
            # give to gitlab to allow us to find the integration a hook came
            # from.
            'external_id': u'{}:{}'.format(hostname, group['path']),
            'metadata': {
                'icon': group['avatar_url'],
                'instance': hostname,
                'domain_name': u'{}/{}'.format(hostname, group['path']),
                'scopes': scopes,
                'verify_ssl': verify_ssl,
                'base_url': base_url,
                'webhook_secret': secret.hexdigest(),
                'group_id': group['id'],
            },
            'user_identity': {
                'type': 'gitlab',
                'external_id': u'{}:{}'.format(hostname, user['id']),
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        return integration
Ejemplo n.º 7
0
    def build_integration(self, state):
        data = state['identity']['data']
        oauth_data = self.get_oauth_data(data)
        user = get_user_info(data['access_token'], state['installation_data'])
        group = self.get_group_info(data['access_token'], state['installation_data'])
        scopes = sorted(GitlabIdentityProvider.oauth_scopes)
        base_url = state['installation_data']['url']
        domain_name = '%s/%s' % (re.sub(r'https?://', '', base_url), group['path'])
        verify_ssl = state['installation_data']['verify_ssl']

        webhook_id, webhook_secret = self.create_webhook(
            base_url,
            data['access_token'],
            verify_ssl)

        integration = {
            'name': group['name'],
            'external_id': u'{}:{}'.format(urlparse(base_url).netloc, group['id']),
            'metadata': {
                'icon': group['avatar_url'],
                'domain_name': domain_name,
                'scopes': scopes,
                'verify_ssl': verify_ssl,
                'base_url': base_url,
                'webhook': {
                    'secret': webhook_secret,
                    'id': webhook_id,
                }
            },
            'user_identity': {
                'type': 'gitlab',
                'external_id': u'{}:{}'.format(urlparse(base_url).netloc, user['id']),
                'scopes': scopes,
                'data': oauth_data,
            },
        }

        return integration