def _log_entry_pb_to_mapping(entry_pb): """Helper for :meth:`list_entries`, et aliae Ideally, would use a function from :mod:`protobuf.json_format`, but the right one isn't public. See: https://github.com/google/protobuf/issues/1351 """ mapping = { 'logName': entry_pb.log_name, 'resource': _mon_resource_pb_to_mapping(entry_pb.resource), 'severity': LogSeverity.Name(entry_pb.severity), 'insertId': entry_pb.insert_id, 'timestamp': _pb_timestamp_to_rfc3339(entry_pb.timestamp), 'labels': entry_pb.labels, } if entry_pb.HasField('text_payload'): mapping['textPayload'] = entry_pb.text_payload if entry_pb.HasField('json_payload'): mapping['jsonPayload'] = _struct_pb_to_mapping(entry_pb.json_payload) if entry_pb.HasField('proto_payload'): mapping['protoPayload'] = entry_pb.proto_payload if entry_pb.http_request: request = entry_pb.http_request mapping['httpRequest'] = { 'requestMethod': request.request_method, 'requestUrl': request.request_url, 'status': request.status, 'referer': request.referer, 'userAgent': request.user_agent, 'cacheHit': request.cache_hit, 'requestSize': request.request_size, 'responseSize': request.response_size, 'remoteIp': request.remote_ip, } if entry_pb.operation: operation = entry_pb.operation mapping['operation'] = { 'producer': operation.producer, 'id': operation.id, 'first': operation.first, 'last': operation.last, } return mapping
def _log_entry_pb_to_mapping(entry_pb): """Helper for :meth:`list_entries`, et aliae Performs "impedance matching" between the protobuf attrs and the keys expected in the JSON API. """ mapping = { 'logName': entry_pb.log_name, 'resource': _mon_resource_pb_to_mapping(entry_pb.resource), 'severity': LogSeverity.Name(entry_pb.severity), 'insertId': entry_pb.insert_id, 'timestamp': _pb_timestamp_to_rfc3339(entry_pb.timestamp), 'labels': entry_pb.labels, } if entry_pb.HasField('text_payload'): mapping['textPayload'] = entry_pb.text_payload if entry_pb.HasField('json_payload'): mapping['jsonPayload'] = _struct_pb_to_mapping(entry_pb.json_payload) if entry_pb.HasField('proto_payload'): mapping['protoPayload'] = entry_pb.proto_payload if entry_pb.http_request: request = entry_pb.http_request mapping['httpRequest'] = { 'requestMethod': request.request_method, 'requestUrl': request.request_url, 'status': request.status, 'referer': request.referer, 'userAgent': request.user_agent, 'cacheHit': request.cache_hit, 'requestSize': request.request_size, 'responseSize': request.response_size, 'remoteIp': request.remote_ip, } if entry_pb.operation: operation = entry_pb.operation mapping['operation'] = { 'producer': operation.producer, 'id': operation.id, 'first': operation.first, 'last': operation.last, } return mapping