Skip to content

Commit 3571717

Browse files
authored
Merge pull request #450 from anarkiwi/pyt2
remove gunicorn and eventlet and use bjoern #2
2 parents d11ebc0 + 07ae9ae commit 3571717

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
export DEBIAN_FRONTEND=noninteractive && \
1515
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections && \
1616
sudo apt-get update && \
17-
sudo apt-get install -yq --no-install-recommends python3.7 python3-dev python3-setuptools dialog apt-utils tshark libpcap0.8 libpcap-dev p0f tcpdump && \
17+
sudo apt-get install -yq --no-install-recommends libev-dev python3.7 python3-dev python3-setuptools dialog apt-utils tshark libpcap0.8 libpcap-dev p0f tcpdump && \
1818
pip3 install -U pip && \
1919
pip3 install codecov pytype pytest-cov && \
2020
find . -name requirements.txt -type f -exec pip3 install -r {} \; && \

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test:
2-
RESULT_PATH=/dev/null PYTHONPATH=network_tools_lib python3 -m pytest -l -s -v --cov=. --cov-report term-missing
2+
RESULT_PATH=/dev/null PYTHONPATH=network_tap/ncontrol:network_tools_lib python3 -m pytest -l -s -v --cov=. --cov-report term-missing
33
# TODO: complete pytype coverage for pcap_stats
4-
PYTHONPATH=network_tools_lib pytype -k --exclude=pcap_stats .
4+
PYTHONPATH=network_tap/ncontrol:network_tools_lib pytype -k --exclude=pcap_stats .
55
./network_tap/ncapture/test_ncapture.sh

network_tap/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM alpine:3.14
22
LABEL maintainer="Charlie Lewis <[email protected]>"
33

44
ENV PYTHONPATH=/network-tap/network_tools_lib
5+
ENV PYTHONUNBUFFERED 1
56

67
COPY network_tap/ncontrol/requirements.txt requirements.txt
78
COPY network_tap/healthcheck /healthcheck
@@ -11,6 +12,7 @@ RUN apk add --update \
1112
gcc \
1213
g++ \
1314
git \
15+
libev-dev \
1416
linux-headers \
1517
musl-dev \
1618
python3 \
@@ -38,4 +40,4 @@ WORKDIR /network-tap
3840

3941
EXPOSE 8080
4042

41-
CMD (flask run > /dev/null 2>&1) & (/network-tap/startup.sh)
43+
CMD (flask run > /dev/null 2>&1) & (python3 ncontrol/ncontrol.py)

network_tap/ncapture/send_message.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ def parse_args(parser):
5050
if __name__ == '__main__': # pragma: no cover
5151
parsed_args = parse_args(argparse.ArgumentParser())
5252
path = get_path(parsed_args.paths)
53-
uid = ''
54-
if 'id' in os.environ:
55-
uid = os.environ['id']
56-
if 'external_host' in os.environ:
57-
external_host = os.environ['external_host']
58-
else:
59-
external_host = 'messenger'
53+
uid = os.environ.get('id', '')
54+
external_host = os.environ.get('external_host', 'messenger')
6055
if os.environ.get('rabbit', False) == 'true':
6156
try:
6257
channel = connect_rabbit(host=external_host)

network_tap/ncontrol/__init__.py

Whitespace-only changes.

network_tap/ncontrol/ncontrol.py

100644100755
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
#!/usr/bin/env python3
2+
import bjoern
13
import falcon
24
from falcon_cors import CORS
35

4-
from .routes import routes
6+
import routes
57

8+
def make_api():
9+
cors = CORS(allow_all_origins=True)
10+
api = falcon.App(middleware=[cors.middleware])
11+
r = routes.routes()
12+
for route in r:
13+
api.add_route(route, r[route])
14+
return api
615

7-
cors = CORS(allow_all_origins=True)
8-
api = application = falcon.App(middleware=[cors.middleware])
916

10-
r = routes()
11-
for route in r:
12-
api.add_route(route, r[route])
17+
if __name__ == "__main__":
18+
bjoern.run(make_api(), "0.0.0.0", 8080) # nosec
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1+
bjoern==3.1.0
12
docker==5.0.0
2-
eventlet==0.30.2
33
falcon==3.0.1
44
falcon-cors==1.1.7
5-
gunicorn==20.1.0

network_tap/ncontrol/routes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
def routes():
2-
from .paths import CreateR, DeleteR, InfoR, ListR, StartR, StopR
3-
p = paths()
4-
create_r = CreateR()
5-
delete_r = DeleteR()
6-
info_r = InfoR()
7-
list_r = ListR()
8-
start_r = StartR()
9-
stop_r = StopR()
2+
import paths
3+
p = endpoints()
4+
create_r = paths.CreateR()
5+
delete_r = paths.DeleteR()
6+
info_r = paths.InfoR()
7+
list_r = paths.ListR()
8+
start_r = paths.StartR()
9+
stop_r = paths.StopR()
1010
funcs = [create_r,
1111
delete_r,
1212
info_r,
@@ -16,7 +16,7 @@ def routes():
1616
return dict(list(zip(p, funcs)))
1717

1818

19-
def paths():
19+
def endpoints():
2020
return ['/create',
2121
'/delete',
2222
'/info',

network_tap/ncontrol/test_ncontrol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import pytest
55
from falcon import testing
66

7-
from .ncontrol import api
7+
from ncontrol import make_api
88

99

1010
@pytest.fixture
1111
def client():
12-
return testing.TestClient(api)
12+
return testing.TestClient(make_api())
1313

1414

1515
def test_create_r(client):

network_tap/startup.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)