diff options
Diffstat (limited to 'python-dnstap-pb.spec')
-rw-r--r-- | python-dnstap-pb.spec | 361 |
1 files changed, 361 insertions, 0 deletions
diff --git a/python-dnstap-pb.spec b/python-dnstap-pb.spec new file mode 100644 index 0000000..678103a --- /dev/null +++ b/python-dnstap-pb.spec @@ -0,0 +1,361 @@ +%global _empty_manifest_terminate_build 0 +Name: python-dnstap-pb +Version: 0.8.0 +Release: 1 +Summary: Dnstap Protocol Buffers implementation in Python +License: MIT License +URL: https://github.com/dmachard/python-dnstap-protobuf +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/5e/6d/86af123d749a528ebc9655806d8a8f7704d7193a96a98fd759f1c4c280e8/dnstap_pb-0.8.0.tar.gz +BuildArch: noarch + +Requires: python3-protobuf + +%description +# Dnstap Protocol Buffers implementation in Python + +Dnstap Protocol Buffers implementation in Python, more informations on dnstap http://dnstap.info/. +This library is based on the following [protocol buffers schema](https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto). + +## Installation + +This module can be installed from [pypi](https://pypi.org/project/dnstap_pb) website + +```python +pip install dnstap_pb +``` + +## Decoder + +Example to use the Dnstap decoder + +```python +import dnstap_pb + +# dnstap decoder +dnstap = dnstap_pb.Dnstap() + +payload = b'\n\x08dnsdist1\x12\rdnsdist 1.5.0r[\x08\x05\x10\x01\x18\x01"\x04\n\x00' +payload += b'\x00\xd2*\x04\n\x00\x00\xd20\xe6\xae\x0385@\x8e\x8f\xc6\xff\x05M\x1cf,' +payload += b'\x15R6\xda\xba\x01 \x00\x01\x00\x00\x00\x00\x00\x01\x03www\x06google\x02' +payload += b'fr\x00\x00\x01\x00\x01\x00\x00)\x10\x00\x00\x00\x00\x00\x00\x0c\x00\n\x00' +payload += b'\x08\xe68\xe3\x8e\x7f\x01\xdexx\x01' + +dnstap.ParseFromString(payload) + +dm = dnstap.message +print(dm) +type: CLIENT_QUERY +socket_family: INET +socket_protocol: UDP +query_address: "\n\000\000\322" +response_address: "\n\000\000\322" +query_port: 60218 +response_port: 53 +query_time_sec: 1609664434 +query_time_nsec: 533617553 +query_message: "\221W\001 \000\001\000\000\000\000\000\001\003www\006google\002fr\000\000\001 +\000\001\000\000)\020\000\000\000\000\000\000\014\000\n\000\010\273\257\370\014_\001\341-" +``` + +## Encoder + +Example to use the Dnstap encoder + +```python +import dnstap_pb + +# dnstap encoder +dnstap = dnstap_pb.Dnstap() + +# clear all fields +dnstap.Clear() + +# constructs the message +dnstap.type = 1 +dnstap.version = b"0.1.0" +dnstap.identity = b"dnstap_python" + +dnstap.message.type = dnstap_pb.dnstap_pb2._MESSAGE_TYPE.values_by_name["CLIENT_QUERY"].number +dnstap.message.socket_protocol = dnstap_pb.dnstap_pb2._SOCKETPROTOCOL.values_by_name["UDP"].number +dnstap.message.socket_family = dnstap_pb.dnstap_pb2._SOCKETFAMILY.values_by_name["INET"].number + +# serialize the dnstap message to binary +payload = dnstap.SerializeToString() +``` + +# Development + +dnstap_pb2 file generation guideline + +Download dnstap.proto from https://github.com/dnstap/dnstap.pb + +``` +wget https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto +``` + +Download protoc + +``` +export VER=21.5 +wget https://github.com/protocolbuffers/protobuf/releases/download/v$VER/protoc-$VER-linux-x86_64.zip +unzip protoc-$VER-linux-x86_64.zip +``` + +Generate proto + +``` +python3 -m pip install protobuf +bin/protoc --python_out=. dnstap.proto +``` + + +%package -n python3-dnstap-pb +Summary: Dnstap Protocol Buffers implementation in Python +Provides: python-dnstap-pb +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-dnstap-pb +# Dnstap Protocol Buffers implementation in Python + +Dnstap Protocol Buffers implementation in Python, more informations on dnstap http://dnstap.info/. +This library is based on the following [protocol buffers schema](https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto). + +## Installation + +This module can be installed from [pypi](https://pypi.org/project/dnstap_pb) website + +```python +pip install dnstap_pb +``` + +## Decoder + +Example to use the Dnstap decoder + +```python +import dnstap_pb + +# dnstap decoder +dnstap = dnstap_pb.Dnstap() + +payload = b'\n\x08dnsdist1\x12\rdnsdist 1.5.0r[\x08\x05\x10\x01\x18\x01"\x04\n\x00' +payload += b'\x00\xd2*\x04\n\x00\x00\xd20\xe6\xae\x0385@\x8e\x8f\xc6\xff\x05M\x1cf,' +payload += b'\x15R6\xda\xba\x01 \x00\x01\x00\x00\x00\x00\x00\x01\x03www\x06google\x02' +payload += b'fr\x00\x00\x01\x00\x01\x00\x00)\x10\x00\x00\x00\x00\x00\x00\x0c\x00\n\x00' +payload += b'\x08\xe68\xe3\x8e\x7f\x01\xdexx\x01' + +dnstap.ParseFromString(payload) + +dm = dnstap.message +print(dm) +type: CLIENT_QUERY +socket_family: INET +socket_protocol: UDP +query_address: "\n\000\000\322" +response_address: "\n\000\000\322" +query_port: 60218 +response_port: 53 +query_time_sec: 1609664434 +query_time_nsec: 533617553 +query_message: "\221W\001 \000\001\000\000\000\000\000\001\003www\006google\002fr\000\000\001 +\000\001\000\000)\020\000\000\000\000\000\000\014\000\n\000\010\273\257\370\014_\001\341-" +``` + +## Encoder + +Example to use the Dnstap encoder + +```python +import dnstap_pb + +# dnstap encoder +dnstap = dnstap_pb.Dnstap() + +# clear all fields +dnstap.Clear() + +# constructs the message +dnstap.type = 1 +dnstap.version = b"0.1.0" +dnstap.identity = b"dnstap_python" + +dnstap.message.type = dnstap_pb.dnstap_pb2._MESSAGE_TYPE.values_by_name["CLIENT_QUERY"].number +dnstap.message.socket_protocol = dnstap_pb.dnstap_pb2._SOCKETPROTOCOL.values_by_name["UDP"].number +dnstap.message.socket_family = dnstap_pb.dnstap_pb2._SOCKETFAMILY.values_by_name["INET"].number + +# serialize the dnstap message to binary +payload = dnstap.SerializeToString() +``` + +# Development + +dnstap_pb2 file generation guideline + +Download dnstap.proto from https://github.com/dnstap/dnstap.pb + +``` +wget https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto +``` + +Download protoc + +``` +export VER=21.5 +wget https://github.com/protocolbuffers/protobuf/releases/download/v$VER/protoc-$VER-linux-x86_64.zip +unzip protoc-$VER-linux-x86_64.zip +``` + +Generate proto + +``` +python3 -m pip install protobuf +bin/protoc --python_out=. dnstap.proto +``` + + +%package help +Summary: Development documents and examples for dnstap-pb +Provides: python3-dnstap-pb-doc +%description help +# Dnstap Protocol Buffers implementation in Python + +Dnstap Protocol Buffers implementation in Python, more informations on dnstap http://dnstap.info/. +This library is based on the following [protocol buffers schema](https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto). + +## Installation + +This module can be installed from [pypi](https://pypi.org/project/dnstap_pb) website + +```python +pip install dnstap_pb +``` + +## Decoder + +Example to use the Dnstap decoder + +```python +import dnstap_pb + +# dnstap decoder +dnstap = dnstap_pb.Dnstap() + +payload = b'\n\x08dnsdist1\x12\rdnsdist 1.5.0r[\x08\x05\x10\x01\x18\x01"\x04\n\x00' +payload += b'\x00\xd2*\x04\n\x00\x00\xd20\xe6\xae\x0385@\x8e\x8f\xc6\xff\x05M\x1cf,' +payload += b'\x15R6\xda\xba\x01 \x00\x01\x00\x00\x00\x00\x00\x01\x03www\x06google\x02' +payload += b'fr\x00\x00\x01\x00\x01\x00\x00)\x10\x00\x00\x00\x00\x00\x00\x0c\x00\n\x00' +payload += b'\x08\xe68\xe3\x8e\x7f\x01\xdexx\x01' + +dnstap.ParseFromString(payload) + +dm = dnstap.message +print(dm) +type: CLIENT_QUERY +socket_family: INET +socket_protocol: UDP +query_address: "\n\000\000\322" +response_address: "\n\000\000\322" +query_port: 60218 +response_port: 53 +query_time_sec: 1609664434 +query_time_nsec: 533617553 +query_message: "\221W\001 \000\001\000\000\000\000\000\001\003www\006google\002fr\000\000\001 +\000\001\000\000)\020\000\000\000\000\000\000\014\000\n\000\010\273\257\370\014_\001\341-" +``` + +## Encoder + +Example to use the Dnstap encoder + +```python +import dnstap_pb + +# dnstap encoder +dnstap = dnstap_pb.Dnstap() + +# clear all fields +dnstap.Clear() + +# constructs the message +dnstap.type = 1 +dnstap.version = b"0.1.0" +dnstap.identity = b"dnstap_python" + +dnstap.message.type = dnstap_pb.dnstap_pb2._MESSAGE_TYPE.values_by_name["CLIENT_QUERY"].number +dnstap.message.socket_protocol = dnstap_pb.dnstap_pb2._SOCKETPROTOCOL.values_by_name["UDP"].number +dnstap.message.socket_family = dnstap_pb.dnstap_pb2._SOCKETFAMILY.values_by_name["INET"].number + +# serialize the dnstap message to binary +payload = dnstap.SerializeToString() +``` + +# Development + +dnstap_pb2 file generation guideline + +Download dnstap.proto from https://github.com/dnstap/dnstap.pb + +``` +wget https://raw.githubusercontent.com/dnstap/dnstap.pb/master/dnstap.proto +``` + +Download protoc + +``` +export VER=21.5 +wget https://github.com/protocolbuffers/protobuf/releases/download/v$VER/protoc-$VER-linux-x86_64.zip +unzip protoc-$VER-linux-x86_64.zip +``` + +Generate proto + +``` +python3 -m pip install protobuf +bin/protoc --python_out=. dnstap.proto +``` + + +%prep +%autosetup -n dnstap-pb-0.8.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-dnstap-pb -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 0.8.0-1 +- Package Spec generated |