def get_ltid_meta_attribute(transaction_id_schema_id, cluster_name, log_file, log_pos): """Log Transaction Id MetaAttribute is a MetaAttribute which allows us to reconstruct the order of messages in replication handler by specifying a statement's exact position in the binlog file. Its payload consists a dict of cluster name, log_file name and log_position. Args: transaction_id_schema_id (int): schema_id for transaction_id Meta Attribute cluster_name (unicode): Name of the cluster from where data was read. log_file (unicode): Binlog name. log_pos (int): Log position in the binlog. """ if not isinstance(cluster_name, unicode) or not isinstance( log_file, unicode): raise TypeError('Cluster name and log file must be unicode strings') if not isinstance(log_pos, int): raise TypeError('Log position must be an integer') return MetaAttribute(schema_id=transaction_id_schema_id, payload_data={ 'cluster_name': cluster_name, 'log_file': log_file, 'log_pos': log_pos })
def valid_meta(self, meta_attr_payload_data, registered_meta_attribute_schema): if meta_attr_payload_data is None: return None meta_attr = MetaAttribute( schema_id=registered_meta_attribute_schema.schema_id, payload_data=meta_attr_payload_data) return [meta_attr]
def test_meta_attribute_from_payload_data(self, meta_attribute_avro_schema, meta_attribute_payload_data, meta_attribute_payload): meta_attribute = MetaAttribute( schema_id=meta_attribute_avro_schema.schema_id, payload_data=meta_attribute_payload_data) expected_avro_repr = { 'schema_id': meta_attribute_avro_schema.schema_id, 'payload': meta_attribute_payload } assert meta_attribute.avro_repr == expected_avro_repr
def get_gtid_meta_attribute(transaction_id_schema_id, cluster_name, gtid): """Global Transaction Id MetaAttribute is a MetaAttribute which allows us to reconstruct the order of messages in replication handler by specifying a statement's exact position in the binlog file. Its payload consists a dict of cluster name and GTID. Args: transaction_id_schema_id (int): schema_id for transaction_id Meta Attribute cluster_name (unicode): Name of the cluster from where data was read. gtid (unicode): MySQL GTID. """ if not isinstance(cluster_name, unicode) or not isinstance(gtid, unicode): raise TypeError('Cluster name and gtid must be unicode strings') return MetaAttribute(schema_id=transaction_id_schema_id, payload_data={ 'cluster_name': cluster_name, 'gtid': gtid })
def _publish_and_assert_pii_message(self, message, producer): with capture_new_messages(message.topic) as get_messages: producer.publish(message) producer.flush() offsets_and_messages = get_messages() assert len(offsets_and_messages) == 1 dp_message = create_from_offset_and_message(offsets_and_messages[0]) assert dp_message.payload == message.payload assert dp_message.payload_data == message.payload_data assert dp_message.schema_id == message.schema_id unpacked_message = Envelope().unpack( offsets_and_messages[0].message.value) unpacked_meta_attr = unpacked_message['meta'][0] encryption_helper = EncryptionHelper( dp_message.encryption_type, MetaAttribute(unpacked_meta_attr['schema_id'], unpacked_meta_attr['payload'])) encrypted_payload = encryption_helper.encrypt_payload(message.payload) assert unpacked_message['payload'] == encrypted_payload
def _get_unpacked_meta(cls, unpacked_message): return [ MetaAttribute(schema_id=o['schema_id'], payload=o['payload']) for o in unpacked_message['meta'] ] if unpacked_message['meta'] else None
def test_create_meta_attr_fails_with_invalid_arguments( self, invalid_arguments): with pytest.raises(TypeError): MetaAttribute(**invalid_arguments)
def get_initialization_vector(schema_id, initialization_vector_array=None): if initialization_vector_array is None: initialization_vector_array = os.urandom(AES.block_size) _verify_initialization_vector_params(initialization_vector_array) return MetaAttribute(schema_id=schema_id, payload_data=initialization_vector_array)