Skip to content

Commit

Permalink
Support python binaries that are not called "python"
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Mar 27, 2023
1 parent 97c1141 commit cb7921f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
37 changes: 19 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL := /bin/bash
PYTHON ?= python

NS ?= abhinavsingh
IMAGE_NAME ?= proxy.py
Expand Down Expand Up @@ -40,23 +41,23 @@ all: lib-test

https-certificates:
# Generate server key
python -m proxy.common.pki gen_private_key \
$(PYTHON) -m proxy.common.pki gen_private_key \
--private-key-path $(HTTPS_KEY_FILE_PATH)
python -m proxy.common.pki remove_passphrase \
$(PYTHON) -m proxy.common.pki remove_passphrase \
--private-key-path $(HTTPS_KEY_FILE_PATH)
# Generate server certificate
python -m proxy.common.pki gen_public_key \
$(PYTHON) -m proxy.common.pki gen_public_key \
--private-key-path $(HTTPS_KEY_FILE_PATH) \
--public-key-path $(HTTPS_CERT_FILE_PATH)

sign-https-certificates:
# Generate CSR request
python -m proxy.common.pki gen_csr \
$(PYTHON) -m proxy.common.pki gen_csr \
--csr-path $(HTTPS_CSR_FILE_PATH) \
--private-key-path $(HTTPS_KEY_FILE_PATH) \
--public-key-path $(HTTPS_CERT_FILE_PATH)
# Sign CSR with CA
python -m proxy.common.pki sign_csr \
$(PYTHON) -m proxy.common.pki sign_csr \
--csr-path $(HTTPS_CSR_FILE_PATH) \
--crt-path $(HTTPS_SIGNED_CERT_FILE_PATH) \
--hostname localhost \
Expand All @@ -65,23 +66,23 @@ sign-https-certificates:

ca-certificates:
# Generate CA key
python -m proxy.common.pki gen_private_key \
$(PYTHON) -m proxy.common.pki gen_private_key \
--private-key-path $(CA_KEY_FILE_PATH)
python -m proxy.common.pki remove_passphrase \
$(PYTHON) -m proxy.common.pki remove_passphrase \
--private-key-path $(CA_KEY_FILE_PATH)
# Generate CA certificate
python -m proxy.common.pki gen_public_key \
$(PYTHON) -m proxy.common.pki gen_public_key \
--private-key-path $(CA_KEY_FILE_PATH) \
--public-key-path $(CA_CERT_FILE_PATH)
# Generate key that will be used to generate domain certificates on the fly
# Generated certificates are then signed with CA certificate / key generated above
python -m proxy.common.pki gen_private_key \
$(PYTHON) -m proxy.common.pki gen_private_key \
--private-key-path $(CA_SIGNING_KEY_FILE_PATH)
python -m proxy.common.pki remove_passphrase \
$(PYTHON) -m proxy.common.pki remove_passphrase \
--private-key-path $(CA_SIGNING_KEY_FILE_PATH)

lib-check:
python check.py
$(PYTHON) check.py

lib-clean:
find . -name '*.pyc' -exec rm -f {} +
Expand All @@ -107,10 +108,10 @@ lib-dep:
pip install "setuptools>=42"

lib-pre-commit:
python -m pre_commit run --hook-stage manual --all-files -v
$(PYTHON) -m pre_commit run --hook-stage manual --all-files -v

lib-lint:
python -m tox -e lint
$(PYTHON) -m tox -e lint

lib-flake8:
tox -e lint -- flake8 --all-files
Expand All @@ -119,12 +120,12 @@ lib-mypy:
tox -e lint -- mypy --all-files

lib-pytest:
python -m tox -e python -- -v
$(PYTHON) -m tox -e python -- -v

lib-test: lib-clean lib-check lib-lint lib-pytest

lib-package: lib-clean lib-check
python -m tox -e cleanup-dists,build-dists,metadata-validation
$(PYTHON) -m tox -e cleanup-dists,build-dists,metadata-validation

lib-release-test: lib-package
twine upload --verbose --repository-url https://test.pypi.org/legacy/ dist/*
Expand All @@ -133,7 +134,7 @@ lib-release: lib-package
twine upload dist/*

lib-doc:
python -m tox -e build-docs && \
$(PYTHON) -m tox -e build-docs && \
$(OPEN) .tox/build-docs/docs_out/index.html || true

lib-coverage: lib-clean
Expand All @@ -145,7 +146,7 @@ lib-profile:
sudo py-spy record \
-o profile.svg \
-t -F -s -- \
python -m proxy \
$(PYTHON) -m proxy \
--hostname 127.0.0.1 \
--num-acceptors 1 \
--num-workers 1 \
Expand All @@ -161,7 +162,7 @@ lib-speedscope:
-o profile.speedscope.json \
-f speedscope \
-t -F -s -- \
python -m proxy \
$(PYTHON) -m proxy \
--hostname 127.0.0.1 \
--num-acceptors 1 \
--num-workers 1 \
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Test the simplest proxy use scenario for smoke.
"""
import os
import sys
import time
import tempfile
import subprocess
Expand Down Expand Up @@ -130,10 +131,12 @@ def _tls_interception_flags(ca_cert_suffix: str = '') -> str:
def _gen_https_certificates(request: Any) -> None:
check_output([
'make', 'https-certificates',
'-e', 'PYTHON="%s"' % (sys.executable,),
'-e', 'CERT_DIR=%s/' % (str(CERT_DIR)),
])
check_output([
'make', 'sign-https-certificates',
'-e', 'PYTHON="%s"' % (sys.executable,),
'-e', 'CERT_DIR=%s/' % (str(CERT_DIR)),
])

Expand All @@ -142,15 +145,18 @@ def _gen_https_certificates(request: Any) -> None:
def _gen_ca_certificates(request: Any) -> None:
check_output([
'make', 'ca-certificates',
'-e', 'PYTHON="%s"' % (sys.executable,),
'-e', 'CERT_DIR=%s/' % (str(CERT_DIR)),
])
check_output([
'make', 'ca-certificates',
'-e', 'PYTHON="%s"' % (sys.executable,),
'-e', 'CA_CERT_SUFFIX=-chunk',
'-e', 'CERT_DIR=%s/' % (str(CERT_DIR)),
])
check_output([
'make', 'ca-certificates',
'-e', 'PYTHON="%s"' % (sys.executable,),
'-e', 'CA_CERT_SUFFIX=-post',
'-e', 'CERT_DIR=%s/' % (str(CERT_DIR)),
])
Expand All @@ -175,7 +181,7 @@ def proxy_py_subprocess(request: Any) -> Generator[int, None, None]:
ca_cert_dir = TEMP_DIR / ('certificates-%s' % run_id)
os.makedirs(ca_cert_dir, exist_ok=True)
proxy_cmd = (
'python', '-m', 'proxy',
sys.executable, '-m', 'proxy',
'--hostname', '127.0.0.1',
'--port', '0',
'--port-file', str(port_file),
Expand Down

0 comments on commit cb7921f

Please sign in to comment.