def _send_mail( scans: typing.Dict, threshold: int, email_recipients, routes: checkmarx.client.CheckmarxRoutes, ): body = checkmarx.util.assemble_mail_body( scans_above_threshold=scans.get(scans_above_threshold_const), scans_below_threshold=scans.get(scans_below_threshold_const), failed_components=scans.get(failed_components_const), threshold=threshold, routes=routes, ) try: # get standard cfg set for email cfg default_cfg_set_name = ci.util.current_config_set_name() cfg_factory = ci.util.ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(default_cfg_set_name) # send mail mailutil._send_mail( email_cfg=cfg_set.email(), recipients=email_recipients, mail_template=body, subject='[Action Required] checkmarx vulnerability report', mimetype='html', ) ci.util.info('sent notification emails to: ' + ','.join(email_recipients)) except Exception: traceback.print_exc() ci.util.warning('error whilst trying to send notification-mail')
def send_mail( email_recipients, routes: checkmarx.client.CheckmarxRoutes, scans: model.FinishedScans, threshold: int, ): body = checkmarx.tablefmt.assemble_mail_body( failed_artifacts=scans.failed_scans, routes=routes, scans_above_threshold=scans.scans_above_threshold, scans_below_threshold=scans.scans_below_threshold, threshold=threshold, ) try: # get standard cfg set for email cfg default_cfg_set_name = ci.util.current_config_set_name() cfg_factory = ci.util.ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(default_cfg_set_name) ci.util.info( f'sending notification emails to: {",".join(email_recipients)}') mailutil._send_mail( email_cfg=cfg_set.email(), recipients=email_recipients, mail_template=body, subject='[Action Required] checkmarx vulnerability report', mimetype='html', ) ci.util.info('sent notification emails to: ' + ','.join(email_recipients)) except Exception: traceback.print_exc() ci.util.warning('error whilst trying to send notification-mail')
def _notify_broken_definition_owners(self, failed_descriptor): definition_descriptor = failed_descriptor.definition_descriptor main_repo = definition_descriptor.main_repo github_cfg = github_cfg_for_hostname(self._cfg_set, main_repo['hostname']) github_api = _create_github_api_object(github_cfg) repo_owner, repo_name = main_repo['path'].split('/') githubrepobranch = GitHubRepoBranch( github_config=github_cfg, repo_owner=repo_owner, repo_name=repo_name, branch=main_repo['branch'], ) repo_helper = GitHubRepositoryHelper.from_githubrepobranch( githubrepobranch=githubrepobranch, ) codeowners_enumerator = CodeownersEnumerator() codeowners_resolver = CodeOwnerEntryResolver(github_api=github_api) recipients = set( codeowners_resolver.resolve_email_addresses( codeowners_enumerator.enumerate_remote_repo( github_repo_helper=repo_helper))) # in case no codeowners are available, resort to using the committer if not recipients: head_commit = repo_helper.repository.commit(main_repo['branch']) user_ids = { user_info.get('login') for user_info in (head_commit.committer, head_commit.author) if user_info.get('login') } for user_id in user_ids: user = github_api.user(user_id) if user.email: recipients.add(user.email) # if there are still no recipients available print a warning if not recipients: warning( textwrap.dedent(f""" Unable to determine recipient for pipeline '{definition_descriptor.pipeline_name}' found in branch '{main_repo['branch']}' ({main_repo['path']}). Please make sure that CODEOWNERS and committers have exposed a public e-mail address in their profile. """)) else: info( f'Sending notification e-mail to {recipients} ({main_repo["path"]})' ) email_cfg = self._cfg_set.email() _send_mail( email_cfg=email_cfg, recipients=recipients, subject='Your pipeline definition in {repo} is erroneous'. format(repo=main_repo['path'], ), mail_template= (f"The pipeline definition for pipeline '{definition_descriptor.pipeline_name}' " f" on branch '{main_repo['branch']}' contains errors.\n\n" f"Error details:\n{str(failed_descriptor.error_details)}"))
def send_vulnerability_report( notification_recipients: typing.Union[None, typing.List[str]], cve_threshold: float, product_name: str, below: typing.List[whitesource.model.WhiteSrcProject], above: typing.List[whitesource.model.WhiteSrcProject], ): # generate html reporting table for email notifications tables = generate_reporting_tables( below=below, above=above, tablefmt='html', ) body = assemble_mail_body( tables=tables, threshold=cve_threshold, ) # get standard cfg set for email cfg default_cfg_set_name = ci.util.current_config_set_name() cfg_factory = ci.util.ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(default_cfg_set_name) mailutil._send_mail( email_cfg=cfg_set.email(), recipients=notification_recipients, mail_template=body, subject= f'[Action Required] ({product_name}) WhiteSource Vulnerability Report', mimetype='html', )
def send_mail( body, recipients: list, product_name: str, ): # get standard cfg set for email cfg default_cfg_set_name = ci.util.current_config_set_name() cfg_factory = ci.util.ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(default_cfg_set_name) mailutil._send_mail( email_cfg=cfg_set.email(), recipients=recipients, mail_template=body, subject= f'[Action Required] ({product_name}) WhiteSource Vulnerability Report', mimetype='html', )
def send_mail( notification_recipients: typing.List[str], cve_threshold: float, product_name: str, projects: typing.List[whitesource.model.WhiteSrcProject], ): if len(notification_recipients) > 0: # generate html reporting table for email notifications tables = generate_reporting_tables( projects=projects, threshold=cve_threshold, tablefmt='html', ) body = assemble_mail_body( tables=tables, threshold=cve_threshold, ) logger.info('sending notification') # get standard cfg set for email cfg default_cfg_set_name = ci.util.current_config_set_name() cfg_factory = ci.util.ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(default_cfg_set_name) mailutil._send_mail( email_cfg=cfg_set.email(), recipients=notification_recipients, mail_template=body, subject= f'[Action Required] ({product_name}) WhiteSource Vulnerability Report', mimetype='html', ) else: logger.warning('No recipients defined. No emails will be sent...')
def _notify_broken_definition_owners(self, failed_descriptor): definition_descriptor = failed_descriptor.definition_descriptor main_repo = definition_descriptor.main_repo repo_owner, repo_name = main_repo['path'].split('/') repo_url = urljoin(main_repo['hostname'], repo_owner, repo_name) github_cfg = ccc.github.github_cfg_for_repo_url( repo_url, self._cfg_set) github_api = ccc.github.github_api(github_cfg) repo_helper = ccc.github.github_repo_helper( host=main_repo['hostname'], org=repo_owner, repo=repo_name, branch=main_repo['branch'], ) recipients = set( github.codeowners.resolve_email_addresses( codeowners_entries=github.codeowners. enumerate_codeowners_from_remote_repo( repo=repo_helper.repository), github_api=github_api, )) # in case no codeowners are available, resort to using the committer if not recipients: head_commit = repo_helper.repository.commit(main_repo['branch']) user_ids = { user_info.get('login') for user_info in (head_commit.committer, head_commit.author) if user_info and user_info.get('login') } for user_id in user_ids: user = github_api.user(user_id) if user.email: recipients.add(user.email) # if there are still no recipients available print a warning if not recipients: logger.warning( textwrap.dedent(f""" Unable to determine recipient for pipeline '{definition_descriptor.pipeline_name}' found in branch '{main_repo['branch']}' ({main_repo['path']}). Please make sure that CODEOWNERS and committers have exposed a public e-mail address in their profile. """)) else: logger.info( f'Sending notification e-mail to {recipients} ({main_repo["path"]})' ) email_cfg = self._cfg_set.email("ses_gardener_cloud_sap") _send_mail( email_cfg=email_cfg, recipients=recipients, subject='Your pipeline definition in {repo} is erroneous'. format(repo=main_repo['path'], ), mail_template=textwrap.dedent(f''' The pipeline definition for {definition_descriptor.pipeline_name=} on {main_repo["branch"]=} failed to be rendered. Error details: {str(failed_descriptor.error_details)} '''), )