Exemplo n.º 1
0
    def build_integration(self, state):
        install = state['installation_data']
        access_token = state['access_token']

        hostname = urlparse(install['url']).netloc
        external_id = '%s:%s' % (hostname, install['consumer_key'])
        webhook_secret = sha1_text(install['private_key']).hexdigest()

        credentials = {
            'consumer_key': install['consumer_key'],
            'private_key': install['private_key'],
            'access_token': access_token['oauth_token'],
            'access_token_secret': access_token['oauth_token_secret'],
        }
        # Create the webhook before the integration record exists
        # so that if it fails we don't persist a broken integration.
        self.create_webhook(external_id, webhook_secret, install, credentials)

        return {
            'name': install['consumer_key'],
            'provider': 'jira_server',
            'external_id': external_id,
            'metadata': {
                'base_url': install['url'],
                'domain_name': hostname,
                'verify_ssl': install['verify_ssl'],
                'webhook_secret': webhook_secret,
            },
            'user_identity': {
                'type': 'jira_server',
                'external_id': external_id,
                'scopes': (),
                'data': credentials
            }
        }
Exemplo n.º 2
0
    def build_integration(self, state):
        install = state['installation_data']
        access_token = state['access_token']

        hostname = urlparse(install['url']).netloc
        external_id = '%s:%s' % (hostname, install['consumer_key'])
        webhook_secret = sha1_text(install['private_key']).hexdigest()

        credentials = {
            'consumer_key': install['consumer_key'],
            'private_key': install['private_key'],
            'access_token': access_token['oauth_token'],
            'access_token_secret': access_token['oauth_token_secret'],
        }
        # Create the webhook before the integration record exists
        # so that if it fails we don't persist a broken integration.
        self.create_webhook(external_id, webhook_secret, install, credentials)

        return {
            'name': install['consumer_key'],
            'provider': 'jira_server',
            'external_id': external_id,
            'metadata': {
                'base_url': install['url'],
                'domain_name': hostname,
                'verify_ssl': install['verify_ssl'],
                'webhook_secret': webhook_secret,
            },
            'user_identity': {
                'type': 'jira_server',
                'external_id': external_id,
                'scopes': [],
                'data': credentials
            }
        }
Exemplo 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
Exemplo 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
Exemplo 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']

        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
Exemplo n.º 6
0
    def build_integration(self, state):
        install = state["installation_data"]
        access_token = state["access_token"]

        webhook_secret = sha1_text(install["private_key"]).hexdigest()

        hostname = urlparse(install["url"]).netloc
        external_id = "{}:{}".format(hostname, install["consumer_key"])[:64]

        credentials = {
            "consumer_key": install["consumer_key"],
            "private_key": install["private_key"],
            "access_token": access_token["oauth_token"],
            "access_token_secret": access_token["oauth_token_secret"],
        }
        # Create the webhook before the integration record exists
        # so that if it fails we don't persist a broken integration.
        self.create_webhook(external_id, webhook_secret, install, credentials)

        return {
            "name": install["consumer_key"],
            "provider": "jira_server",
            "external_id": external_id,
            "metadata": {
                "base_url": install["url"],
                "domain_name": hostname,
                "verify_ssl": install["verify_ssl"],
                "webhook_secret": webhook_secret,
            },
            "user_identity": {
                "type": "jira_server",
                "external_id": external_id,
                "scopes": [],
                "data": credentials,
            },
        }
Exemplo n.º 7
0
 def get_ident(cls, name, dist=None):
     if dist is not None:
         return sha1_text(name + "\x00\x00" + dist).hexdigest()
     return sha1_text(name).hexdigest()
Exemplo n.º 8
0
 def test_unicode(self):
     assert md5_text("ü").hexdigest() == "c03410a5204b21cd8229ff754688d743"
     assert sha1_text(
         "ü").hexdigest() == "94a759fd37735430753c7b6b80684306d80ea16e"
Exemplo n.º 9
0
 def test_simple(self):
     assert md5_text("x").hexdigest() == "9dd4e461268c8034f5c8564e155c67a6"
     assert sha1_text(
         "x").hexdigest() == "11f6ad8ec52a2984abaafd7c3b516503785c2072"
Exemplo n.º 10
0
 def get_ident(cls, name):
     return sha1_text(name).hexdigest()
Exemplo n.º 11
0
 def get_ident(cls, name):
     return sha1_text(name).hexdigest()
Exemplo n.º 12
0
 def test_simple(self):
     md5_text('x').hexdigest() == '9dd4e461268c8034f5c8564e155c67a6'
     sha1_text(
         'x').hexdigest() == '11f6ad8ec52a2984abaafd7c3b516503785c2072'
Exemplo n.º 13
0
 def test_unicode(self):
     md5_text(u'ü').hexdigest() == 'c03410a5204b21cd8229ff754688d743'
     sha1_text(
         u'ü').hexdigest() == '94a759fd37735430753c7b6b80684306d80ea16e'
Exemplo n.º 14
0
 def test_simple(self):
     md5_text('x').hexdigest() == '9dd4e461268c8034f5c8564e155c67a6'
     sha1_text('x').hexdigest() == '11f6ad8ec52a2984abaafd7c3b516503785c2072'
Exemplo n.º 15
0
 def test_unicode(self):
     md5_text(u'ü').hexdigest() == 'c03410a5204b21cd8229ff754688d743'
     sha1_text(u'ü').hexdigest() == '94a759fd37735430753c7b6b80684306d80ea16e'
Exemplo n.º 16
0
 def get_ident(cls, name, dist=None):
     if dist is not None:
         return sha1_text(name + '\x00\x00' + dist).hexdigest()
     return sha1_text(name).hexdigest()