Skip to content

Commit

Permalink
secure connection to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Retch committed Aug 24, 2023
1 parent 6286349 commit f511be1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ LABEL org.opencontainers.image.source="https://github.com/retch/shareabike-omni-
ENV PYTHONUNBUFFERED 1

ENV BACKEND_HOST_URL http://127.0.0.1
ENV BACKEND_USERNAME "adapter"
ENV BACKEND_PASSWORD "password"
WORKDIR /app
COPY requirements.txt /app/
RUN pip install -r requirements.txt
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
restart: unless-stopped
environment:
- BACKEND_HOST_URL=http://example.com
- BACKEND_USERNAME=adapter
- BACKEND_PASSWORD=password
ports:
- "8079:8079"
- "9679:9679"
6 changes: 4 additions & 2 deletions src/backend_http_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import requests
from src.receive_packets import Q0Packet, W0Packet, D0Packet, H0Packet, L0Packet, L1Packet, S5Packet, S8Packet, M0Packet, U0Packet

url = os.environ.get("BACKEND_HOST_URL", "http://127.0.0.1")
url = os.environ.get("BACKEND_HOST_URL", "")
username = os.environ.get("BACKEND_USERNAME", "")
password = os.environ.get("BACKEND_PASSWORD", "")


def send_to_backend(packet):
Expand Down Expand Up @@ -57,7 +59,7 @@ def send_to_backend(packet):
data['lockSwDate'] = packet.lock_sw_date
data['lockHwRevision'] = packet.lock_hw_revision

response = requests.post(url + "/adapter/" + packet.imei + "/updatestatus", json=data)
response = requests.post(url + "/adapter/" + packet.imei + "/updatestatus", json=data, auth=(username, password))

if response.status_code == 200:
print('Package was forwarded to backend')
Expand Down

0 comments on commit f511be1

Please sign in to comment.