Skip to content

Commit

Permalink
FTP_TLS in production and FTP for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ruaridhg committed Jan 19, 2024
1 parent 8d626cf commit 7856a56
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 60 deletions.
8 changes: 4 additions & 4 deletions pixl_core/src/core/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

logger = logging.getLogger(__name__)


FTP_type = FTP_TLS
# Make a DSHUploader class that takes a project slug and study pseudonymised id?


Expand Down Expand Up @@ -54,21 +54,21 @@ def upload_content(content: BinaryIO, *, remote_dir: str, remote_file: str) -> s
return f"{remote_dir}/{remote_file}"


def _connect_to_ftp() -> FTP_TLS:
def _connect_to_ftp() -> FTP_type:
# Set your FTP server details
ftp_host = os.environ["FTP_HOST"]
ftp_port = os.environ["FTP_PORT"] # FTPS usually uses port 21
ftp_user = os.environ["FTP_USER_NAME"]
ftp_password = os.environ["FTP_USER_PASS"]

# Connect to the server and login
ftp = FTP_TLS() # noqa: S321, we're required to use FTP_TLS
ftp = FTP_type() # , we're required to use FTP_TLS
ftp.connect(ftp_host, int(ftp_port))
ftp.login(ftp_user, ftp_password)
return ftp


def _create_and_set_as_cwd(ftp: FTP_TLS, project_dir: str) -> None:
def _create_and_set_as_cwd(ftp: FTP_type, project_dir: str) -> None:
try:
ftp.cwd(project_dir)
logger.info("'%s' exists on remote ftp, so moving into it", project_dir)
Expand Down
7 changes: 6 additions & 1 deletion pixl_core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import os
import subprocess
from ftplib import FTP
from pathlib import Path

import pytest
Expand All @@ -34,6 +35,11 @@
TEST_DIR = Path(__file__).parent


@pytest.fixture(autouse=True)
def _use_FTP(monkeypatch):
monkeypatch.setattr("core.upload.FTP_type", FTP)


@pytest.fixture(scope="package")
def _run_containers() -> None:
"""WIP, should be able to get this up and running from pytest"""
Expand All @@ -43,7 +49,6 @@ def _run_containers() -> None:
check=True,
cwd=TEST_DIR,
shell=True, # noqa: S602
timeout=60
)
yield
subprocess.run(b"docker compose down --volumes", check=True, cwd=TEST_DIR, shell=True) # noqa: S602
Expand Down
7 changes: 4 additions & 3 deletions pixl_core/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ services:
retries: 5
ftp-server:
container_name: test-ftp-server
image: delfer/alpine-ftp-server
build:
context: ftp-server
ports:
- "20021:21"
- "21000-21010:21000-21010"
Expand All @@ -44,8 +45,8 @@ services:
environment:
ADDRESS: "localhost"
USERS: pixl|pixl|/home/pixl
TLS_KEY: /etc/ssl/private/localhost.key
TLS_CERT: /etc/ssl/private/localhost.crt
# TLS_KEY: /etc/ssl/private/localhost.key
# TLS_CERT: /etc/ssl/private/localhost.crt
healthcheck:
test: netstat -lnt | grep ":21" || exit 1
interval: 30s
Expand Down
11 changes: 6 additions & 5 deletions pixl_core/tests/ftp-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM delfer/alpine-ftp-server


SHELL ["/bin/bash", "-c"]
RUN echo $'# Enable FTPS.\n\
ssl_enable=YES\n\
require_ssl_reuse=NO'
SHELL ["/bin/sh", "-c"]
# RUN echo $'# Enable FTPS.\n\
# ssl_enable=YES\n\
# ssl_tlsv1_1=YES\n\
# require_ssl_reuse=NO' >> /etc/vsftpd/vsftpd.conf
19 changes: 0 additions & 19 deletions pixl_core/tests/ftp-server/mounts/ssl/localhost.crt

This file was deleted.

28 changes: 0 additions & 28 deletions pixl_core/tests/ftp-server/mounts/ssl/localhost.key

This file was deleted.

0 comments on commit 7856a56

Please sign in to comment.