s3.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:threatstack-to-s3 作者: threatstack 项目源码 文件源码
def get_alerts_by_date(start, end):
    '''
    Get alerts between given date start and end.

    both start and end are datetime objects with timezone info
    '''
    # We store webhooks by date and time so we search for those first.
    webhooks_prefix = _get_webhooks_key_prefix()
    webhook_objects = _get_bucket_objects(webhooks_prefix)

    alert_ids = []
    for obj in webhook_objects:
        key = obj.get('Key')
        # Remove webhook path prefix (and delimiter) and split string into
        # time prefix and alert ID.
        webhook_time_prefix, alert_id = key[len(webhooks_prefix) + 1:].rsplit('/', 1)
        # There are more compact ways of doing the following but I prefer to
        # show the sequence of events.
        #
        # split prefix into a list of strings.
        webhook_time_prefix_list = webhook_time_prefix.split('/')
        # use list comprehension to create a list of ints.  See also:
        # map(int, webhook_time_prefix_list)
        webhook_time_prefix_ints = [int(e) for e in webhook_time_prefix_list]
        # use *expression syntax to pass in values as a set of arguments. Also
        # supply tzinfo because the datetime objects we're supplied have them.
        webhook_time = datetime.datetime(*webhook_time_prefix_ints, tzinfo=UTC)

        if start < webhook_time < end:
            alert_ids.append(alert_id)

    alerts = []
    for alert_id in alert_ids:
        alert_data = get_alert_by_id(alert_id)
        alerts.append(alert_data)

    return alerts
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号