def _make_range(begin_time, end_time): if not begin_time and not end_time: return None if not begin_time: begin_time = datetime.utcfromtimestamp(0) if not end_time: end_time = datetime.utcnow() end = parse_timestamp_to_milliseconds_precision(end_time) start = parse_timestamp_to_milliseconds_precision(begin_time) return f"{start}/{end}"
def in_range(cls, start_value, end_value): """Returns a :class:`~py42.sdk.queries.query_filter.FilterGroup` that is useful for finding results where the value with key ``self._term`` is in range between the provided ``start_value`` and ``end_value``. Args: start_value (str or int or float or datetime): The start value used to filter results. end_value (str or int or float or datetime): The end value used to filter results. Returns: :class:`~py42.sdk.queries.query_filter.FilterGroup` """ formatted_start_time = parse_timestamp_to_milliseconds_precision(start_value) formatted_end_time = parse_timestamp_to_milliseconds_precision(end_value) return create_in_range_filter_group( cls._term, formatted_start_time, formatted_end_time )
def get_events_page( self, legal_hold_uid=None, min_event_date=None, max_event_date=None, page_num=1, page_size=None, ): """Gets an individual page of Legal Hold events. `REST Documentation <https://console.us.code42.com/apidocviewer/#LegalHoldEventReport-get>`__ Args: legal_hold_uid (str, optional): Find LegalHoldEvents for the Legal Hold Matter with this unique identifier. Defaults to None. min_event_date (str or int or float or datetime, optional): Find LegalHoldEvents whose eventDate is equal to or after this time. E.g. yyyy-MM-dd HH:MM:SS. Defaults to None. max_event_date (str or int or float or datetime, optional): Find LegalHoldEvents whose eventDate is equal to or before this time. E.g. yyyy-MM-dd HH:MM:SS. Defaults to None. page_num (int): The page number to request. Defaults to 1. page_size (int, optional): The size of the page. Defaults to `py42.settings.items_per_page`. Returns: :class:`py42.response.Py42Response`: """ page_size = page_size or settings.items_per_page if min_event_date: min_event_date = parse_timestamp_to_milliseconds_precision( min_event_date) if max_event_date: max_event_date = parse_timestamp_to_milliseconds_precision( max_event_date) params = { u"legalHoldUid": legal_hold_uid, u"minEventDate": min_event_date, u"maxEventDate": max_event_date, u"pgNum": page_num, u"pgSize": page_size, } uri = u"/api/LegalHoldEventReport" return self._connection.get(uri, params=params)
def get_page(self, page_num=1, page_size=None, begin_time=None, end_time=None, event_types=None, user_ids=None, usernames=None, user_ip_addresses=None, affected_user_ids=None, affected_usernames=None, format=None, **kwargs): date_range = {} if begin_time: date_range[ "startTime"] = parse_timestamp_to_milliseconds_precision( begin_time) if end_time: date_range["endTime"] = parse_timestamp_to_milliseconds_precision( end_time) uri = u"/rpc/search/search-audit-log" page_size = page_size or settings.items_per_page params = dict( page=page_num - 1, pageSize=page_size, dateRange=date_range, eventTypes=to_list(event_types), actorIds=to_list(user_ids), actorNames=to_list(usernames), actorIpAddresses=to_list(user_ip_addresses), affectedUserIds=to_list(affected_user_ids), affectedUserNames=to_list(affected_usernames), ) params.update(**kwargs) headers = HEADER_MAP.get(format.upper()) if format else None return self._connection.post(uri, json=params, headers=headers)
def on_or_before(cls, value): """Returns a :class:`~py42.sdk.queries.query_filter.FilterGroup` that is useful for finding results where the value with key ``self._term`` is on or before the provided ``value``. Args: value (str or int or float or datetime): The value used to filter results. Returns: :class:`~py42.sdk.queries.query_filter.FilterGroup` """ formatted_timestamp = parse_timestamp_to_milliseconds_precision(value) return create_on_or_before_filter_group(cls._term, formatted_timestamp)
def test_parse_timestamp_to_milliseconds_precision_returns_expected_timestamp_with_float_time(): actual = util.parse_timestamp_to_milliseconds_precision(1599653541.001002) assert actual == "2020-09-09T12:12:21.001Z"
def test_parse_timestamp_to_milliseconds_precision_returns_expected_timestamp_with_datetime_time(): dt = datetime.strptime("2020-09-09 12:12:21", "%Y-%m-%d %H:%M:%S") actual = util.parse_timestamp_to_milliseconds_precision(dt) assert actual == "2020-09-09T12:12:21.000Z"
def test_parse_timestamp_to_milliseconds_precision_when_given_unicode_returns_expected_timestamp_with_str_format_time(): actual = util.parse_timestamp_to_milliseconds_precision("2020-09-09 12:12:21") assert actual == "2020-09-09T12:12:21.000Z"
def test_parse_timestamp_to_milliseconds_precision_returns_expected_timestamp_with_str_format_time( ): assert (util.parse_timestamp_to_milliseconds_precision( u"2020-09-09 12:12:21") == "2020-09-09T12:12:21.000Z")
def test_parse_timestamp_to_milliseconds_precision_returns_expected_timestamp_with_epoch_time( ): assert (util.parse_timestamp_to_milliseconds_precision(1599653541) == "2020-09-09T12:12:21.000Z")