Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
name: Test

on: push
on:
push:
branches:
- '**'
tags:
- 'v*'

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- name: Extract branch name
shell: bash
run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/heads/} | tr / -)"
run: echo "tag=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_OUTPUT
id: extract_branch

- name: "Pull core image"
shell: bash
run: echo -n "##[set-output name=tag;]" && docker pull tomlegkov/marine-core:${{ steps.extract_branch.outputs.tag }} > /dev/null && echo "${{ steps.extract_branch.outputs.tag }}" || echo marine
run: |
if docker pull tomlegkov/marine-core:${{ steps.extract_branch.outputs.tag }} > /dev/null 2>&1; then
echo "tag=${{ steps.extract_branch.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "tag=marine" >> $GITHUB_OUTPUT
fi
id: detect_tag

- name: Extract version from tag
if: startsWith(github.ref, 'refs/tags/v')
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
id: extract_version

- name: "Build marine-python docker image"
run: docker build --build-arg MARINE_CORE_TAG=${{ steps.detect_tag.outputs.tag }} --pull -t marine-python .
run: docker build --build-arg MARINE_CORE_TAG=${{ steps.detect_tag.outputs.tag }} --build-arg MARINE_VERSION=${{ steps.extract_version.outputs.version || '0.0.0' }} --pull -t marine-python .

- name: "Extract wheel from docker image"
run: docker run -i --rm -v $(pwd)/dist:/io marine-python sh -c "cp /dist/marine*.whl /io/"

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v6
with:
name: wheel
path: dist/*.whl

- name: "Run marine-python tests"
run: docker run -i --rm marine-python

release:
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/download-artifact@v6
with:
name: wheel

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: '*.whl'
generate_release_notes: true
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ COPY README.md ./
COPY LICENSE ./
COPY marine ./marine

ARG MARINE_VERSION=0.0.0
ENV PY="/opt/python/cp38-cp38/bin/python"

RUN mkdir -p marine/.ws/data && \
RUN echo "__version__ = \"${MARINE_VERSION}\"" > marine/_version.py && \
mkdir -p marine/.ws/data && \
rsync -L --exclude idl2wrs --exclude 'lib*.so*' --exclude 'plugins*' --exclude 'marine_*' --exclude tshark --exclude '*.html' --exclude 'lib*.a' /build/run/* marine/.ws/data/ && \
mkdir marine/.ws/libs && \
rsync -L /build/run/libmarine.so /build/run/lib*so.0 marine/.ws/libs/ && \
rsync -L /build/run/libmarine.so /build/run/lib*so.* marine/.ws/libs/ && \
$PY -m pip install --no-cache-dir setuptools wheel && \
$PY setup.py bdist_wheel --dist-dir /tmp

WORKDIR /dist
Expand All @@ -25,15 +28,18 @@ RUN /scripts/expose_auditwheel.sh && \
$PY /scripts/modify_auditwheel_policy.py && \
/scripts/patch_auditwheel_recursive_dependency_bug.sh

RUN auditwheel repair --plat manylinux2014_x86_64 -w /dist /tmp/marine*.whl
RUN auditwheel repair --lib-sdir /.ws/libs/ --plat manylinux2014_x86_64 -w /dist /tmp/marine*.whl



FROM centos/python-38-centos7

USER root

RUN yum install -y libpcap && \
RUN sed -i 's/mirror\.centos\.org/vault.centos.org/g' /etc/yum.repos.d/CentOS-*.repo && \
sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/CentOS-*.repo && \
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/CentOS-*.repo && \
yum install -y libpcap && \
yum clean all && \
rm -rf /var/yum/cache

Expand Down
1 change: 1 addition & 0 deletions marine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
from .exceptions import *
from .marine import Marine
from . import encap_consts
from ._version import __version__
1 change: 1 addition & 0 deletions marine/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.0"
13 changes: 10 additions & 3 deletions marine/marine.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def __init__(self, epan_auto_reset_count: Optional[int] = None):
self._marine.marine_free.argtypes = [MARINE_RESULT_POINTER]
self._marine.marine_dissect_all_packet_fields.restype = MARINE_PACKET_POINTER
self._marine.marine_packet_free.argtypes = [MARINE_PACKET_POINTER]
self._marine.get_wireshark_version.restype = c_char_p

return_code = self._marine.init_marine()
if return_code < 0:
Expand Down Expand Up @@ -241,9 +242,11 @@ def filter_and_parse(
bpf,
display_filter,
tuple(encoded_fields) if fields is not None else None,
tuple(field_template_indices)
if field_template_indices is not None
else None,
(
tuple(field_template_indices)
if field_template_indices is not None
else None
),
encapsulation_type,
)
if filter_key in self._filters_cache:
Expand Down Expand Up @@ -469,3 +472,7 @@ def _detect_encap(self, fields: Optional[List[str]]) -> int:

def report_fields(self) -> None:
self._marine.marine_report_fields()

def get_wireshark_version(self) -> str:
version = self._marine.get_wireshark_version()
return version.decode("utf-8")
7 changes: 7 additions & 0 deletions marine/simple_marine.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,10 @@ def report_fields() -> None:
Dumps to stdout all of marine, similiarly to `tshark -G`
"""
return get_marine().report_fields()


def get_wireshark_version() -> str:
"""
Gets the version of wireshark used by marine.
"""
return get_marine().get_wireshark_version()
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from setuptools import setup

from marine._version import __version__

setup(
name="marine",
version="3.1.2",
version=__version__,
description="Python client for Marine",
packages=["marine"],
include_package_data=True,
Expand Down
1 change: 1 addition & 0 deletions tests/marine/benchmark/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
TODO: simulate PL in conversations
TODO: add support for real TCP conversations with ack and seq management
"""

import argparse
import os
import time
Expand Down
6 changes: 6 additions & 0 deletions tests/marine/test_marine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Note: in order to run the tests, you must put libmarine.so next to the marine_fixtures.py file
"""

import pytest
from typing import List, Union, Optional, Dict
from marine.marine import Marine, MarineFieldsValidationResult
Expand Down Expand Up @@ -1095,3 +1096,8 @@ def test_value_error_for_unknown_pref_name(marine_instance):
def test_type_error_for_invalid_pref_type(marine_instance):
with pytest.raises(TypeError):
marine_instance.prefs.set_str("amqp", "tls.port", "1234")


def test_get_wireshark_version(marine_instance: Marine):
version = marine_instance.get_wireshark_version()
assert isinstance(version, str)