Example #1
0
File: aws.py Project: hdknr/flier
def get_ses_regions(name=None):
    res = ses.regions()
    if name:
        res = [
            ri for ri in res
            if ri.name == name]
    return res
Example #2
0
 def __init__(self, overrides=None):
     self.overrides = overrides
     conf = aws_credentials.get_credentials()
     region = ses.regions()[0]  # Getting first region
     self.conn = boto.connect_ses(aws_access_key_id=conf[0],
       aws_secret_access_key=conf[1],
       region=region)
Example #3
0
def ses_email(config, to_address, subject, body):
    connection = SESConnection(
        aws_access_key_id=config['AWS_ACCESS_KEY_ID'],
        aws_secret_access_key=config['AWS_SECRET_ACCESS_KEY'],
        region=next(i for i in regions() if i.name == config['AWS_REGION']))
    from_address = '"SolutionNet" <{0}>'.format(config['FROM_EMAIL_ADDRESS'])

    connection.send_email(from_address, str(subject), str(body),
                          str(to_address))
Example #4
0
    def slurp(self):
        """
        :returns: item_list - list of SES Identities.
        :returns: exception_map - A dict where the keys are a tuple containing the
            location of the exception and the value is the actual exception

        """
        self.prep_for_slurp()
        from security_monkey.common.sts_connect import connect
        item_list = []
        exception_map = {}
        for account in self.accounts:
            for region in regions():

                if region.name == 'eu-central-1':
                    # as of boto 2.34.0, boto cannot connect to ses in eu-central-1
                    # TODO: Remove this if-block when boto can handle ses in eu-central-1
                    continue

                app.logger.debug("Checking {}/{}/{}".format(self.index, account, region.name))
                try:
                    ses = connect(account, 'ses', region=region.name)
                    response = self.wrap_aws_rate_limited_call(
                        ses.list_identities
                    )
                    identities = response.Identities
                    response = self.wrap_aws_rate_limited_call(
                        ses.list_verified_email_addresses
                    )
                    verified_identities = response.VerifiedEmailAddresses
                except Exception as e:
                    if region.name not in TROUBLE_REGIONS:
                        exc = BotoConnectionIssue(str(e), self.index, account, region.name)
                        self.slurp_exception((self.index, account, region.name), exc, exception_map)
                    continue
                app.logger.debug("Found {} {}. {} are verified.".format(len(identities), self.i_am_plural, len(verified_identities)))
                for identity in identities:
                    if self.check_ignore_list(identity):
                        continue
                    
                    config = {
                        'name': identity,
                        'verified': identity in verified_identities
                    }

                    item = SESItem(region=region.name, account=account, name=identity, config=dict(config))
                    item_list.append(item)

        return item_list, exception_map