def __init__(self, config, session, logger): if config.get('slack_token'): config['slack_token'] = kms_decrypt(config, logger, session, 'slack_token') self.client = SlackClient(config['slack_token']) self.caching = self.cache_factory(config, config.get('cache_engine', None)) self.config = config self.logger = logger self.session = session self.email_handler = EmailDelivery(config, session, logger)
def setUp(self): self.config = { 'slack_token': SLACK_TOKEN, 'templates_folders': [ os.path.abspath(os.path.dirname(__file__)), os.path.abspath('/'), os.path.join(os.path.abspath(os.path.dirname(__file__)), "test-templates/") ] } self.session = MagicMock() self.logger = MagicMock() self.email_delivery = EmailDelivery(self.config, self.session, self.logger) self.message = copy.deepcopy(SQS_MESSAGE_5) self.resource = copy.deepcopy(RESOURCE_3) self.message['resources'] = [self.resource] self.target_channel = 'test-channel'
def run(self, dry_run=False, print_only=False): emd = EmailDelivery(self.config, self.session, logger) addrs_to_msgs = emd.get_to_addrs_email_messages_map(self.data) logger.info('Would send email to: %s', addrs_to_msgs.keys()) if print_only: mime = get_mimetext_message(self.config, logger, self.data, self.data['resources'], ['*****@*****.**']) logger.info('Send mail with subject: "%s"', mime['Subject']) print(mime.get_payload(None, True).decode('utf-8')) return if dry_run: for to_addrs, mimetext_msg in addrs_to_msgs.items(): print('-> SEND MESSAGE TO: %s' % '; '.join(to_addrs)) print(mimetext_msg.get_payload(None, True).decode('utf-8')) return # else actually send the message... for to_addrs, mimetext_msg in addrs_to_msgs.items(): logger.info('Actually sending mail to: %s', to_addrs) emd.send_c7n_email(self.data, list(to_addrs), mimetext_msg)