forked from abhinavsingh/proxy.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (184 loc) · 6.25 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
SHELL := /bin/bash
NS ?= abhinavsingh
IMAGE_NAME ?= proxy.py
# Override to target specific versions of proxy.py
PROXYPY_CONTAINER_VERSION := latest
# Used by container build and run targets
PROXYPY_CONTAINER_TAG := $(NS)/$(IMAGE_NAME):$(PROXYPY_CONTAINER_VERSION)
CERT_DIR :=
HTTPS_KEY_FILE_PATH := $(CERT_DIR)https-key.pem
HTTPS_CERT_FILE_PATH := $(CERT_DIR)https-cert.pem
HTTPS_CSR_FILE_PATH := $(CERT_DIR)https-csr.pem
HTTPS_SIGNED_CERT_FILE_PATH := $(CERT_DIR)https-signed-cert.pem
CA_CERT_SUFFIX :=
CA_KEY_FILE_PATH := $(CERT_DIR)ca-key$(CA_CERT_SUFFIX).pem
CA_CERT_FILE_PATH := $(CERT_DIR)ca-cert$(CA_CERT_SUFFIX).pem
CA_SIGNING_KEY_FILE_PATH := $(CERT_DIR)ca-signing-key$(CA_CERT_SUFFIX).pem
# Dummy invalid hardcoded value
PROXYPY_PKG_PATH := dist/proxy.py.whl
BUILDX_TARGET_PLATFORM := linux/amd64
OPEN=$(shell which open)
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
OPEN=$(shell which xdg-open)
endif
.PHONY: all https-certificates sign-https-certificates ca-certificates
.PHONY: lib-check lib-clean lib-test lib-package lib-coverage lib-lint lib-pytest
.PHONY: lib-release-test lib-release lib-profile lib-doc lib-pre-commit
.PHONY: lib-dep lib-flake8 lib-mypy lib-speedscope container-buildx-all-platforms
.PHONY: container container-run container-release container-build container-buildx
.PHONY: devtools dashboard dashboard-clean container-without-openssl
all: lib-test
https-certificates:
# Generate server key
python -m proxy.common.pki gen_private_key \
--private-key-path $(HTTPS_KEY_FILE_PATH)
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 \
--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 \
--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 \
--csr-path $(HTTPS_CSR_FILE_PATH) \
--crt-path $(HTTPS_SIGNED_CERT_FILE_PATH) \
--hostname localhost \
--private-key-path $(CA_KEY_FILE_PATH) \
--public-key-path $(CA_CERT_FILE_PATH)
ca-certificates:
# Generate CA key
python -m proxy.common.pki gen_private_key \
--private-key-path $(CA_KEY_FILE_PATH)
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 \
--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 \
--private-key-path $(CA_SIGNING_KEY_FILE_PATH)
python -m proxy.common.pki remove_passphrase \
--private-key-path $(CA_SIGNING_KEY_FILE_PATH)
lib-check:
python check.py
lib-clean:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
rm -f .coverage
rm -rf htmlcov
rm -rf dist
rm -rf build
rm -rf proxy.py.egg-info
rm -rf .pytest_cache
rm -rf .hypothesis
# Doc RST files are cached and can cause issues
# See https://github.com/abhinavsingh/proxy.py/issues/642#issuecomment-1003444578
rm -f docs/pkg/*.rst
lib-dep:
pip install --upgrade pip && \
pip install \
-r requirements-testing.txt \
-r requirements-release.txt \
-r requirements-tunnel.txt && \
pip install "setuptools>=42"
lib-pre-commit:
python -m pre_commit run --hook-stage manual --all-files -v
lib-lint:
python -m tox -e lint
lib-flake8:
tox -e lint -- flake8 --all-files
lib-mypy:
tox -e lint -- mypy --all-files
lib-pytest:
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
lib-release-test: lib-package
twine upload --verbose --repository-url https://test.pypi.org/legacy/ dist/*
lib-release: lib-package
twine upload dist/*
lib-doc:
python -m tox -e build-docs && \
$(OPEN) .tox/build-docs/docs_out/index.html || true
lib-coverage: lib-clean
pytest --cov=proxy --cov=tests --cov-report=html tests/ && \
$(OPEN) htmlcov/index.html || true
lib-profile:
ulimit -n 65536 && \
sudo py-spy record \
-o profile.svg \
-t -F -s -- \
python -m proxy \
--hostname 127.0.0.1 \
--num-acceptors 1 \
--num-workers 1 \
--enable-web-server \
--plugin proxy.plugin.WebServerPlugin \
--backlog 65536 \
--open-file-limit 65536 \
--log-file /dev/null
lib-speedscope:
ulimit -n 65536 && \
sudo py-spy record \
-o profile.speedscope.json \
-f speedscope \
-t -F -s -- \
python -m proxy \
--hostname 127.0.0.1 \
--num-acceptors 1 \
--num-workers 1 \
--enable-web-server \
--plugin proxy.plugin.WebServerPlugin \
--backlog 65536 \
--open-file-limit 65536 \
--log-file /dev/null
lib-pyreverse:
rm -f proxy.proxy.Proxy.dot pyreverse.png
pyreverse -ASmy -c proxy.proxy.Proxy proxy
dot -Tpng proxy.proxy.Proxy.dot > pyreverse.png
open pyreverse.png
devtools:
pushd dashboard && npm install && npm run devtools && popd
dashboard:
pushd dashboard && npm install && npm run build && popd
dashboard-clean:
if [[ -d dashboard/public ]]; then rm -rf dashboard/public; fi
container: lib-package
docker build \
-t $(PROXYPY_CONTAINER_TAG) \
--build-arg PROXYPY_PKG_PATH=$$(ls dist/*.whl) .
container-without-openssl: lib-package
docker build \
-t $(PROXYPY_CONTAINER_TAG) \
--build-arg SKIP_OPENSSL=1 \
--build-arg PROXYPY_PKG_PATH=$$(ls dist/*.whl) .
# Usage:
#
# make container-buildx \
# -e PROXYPY_PKG_PATH=$(ls dist/*.whl) \
# -e BUILDX_TARGET_PLATFORM=linux/arm64 \
# -e PROXYPY_CONTAINER_VERSION=latest
container-buildx:
docker buildx build \
--load \
--platform $(BUILDX_TARGET_PLATFORM) \
-t $(PROXYPY_CONTAINER_TAG) \
--build-arg PROXYPY_PKG_PATH=$(PROXYPY_PKG_PATH) .
container-buildx-all-platforms:
docker buildx build \
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x \
-t $(PROXYPY_CONTAINER_TAG) \
--build-arg PROXYPY_PKG_PATH=$(PROXYPY_PKG_PATH) .
container-run:
docker run -it -p 8899:8899 --rm $(PROXYPY_CONTAINER_TAG)