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
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
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