Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ability to override --data-dir for scenarios when proxy.py is running as a user with no home directory #1389

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
- name: Set the expected dist artifact names
id: artifact-name
run: |
print('::set-output name=sdist::proxy.py-${{
print('::set-output name=sdist::proxy_py-${{
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webknjaz Apologies for tagging you again, but wanted to highlight this change as I am unsure what upstream changes might have caused this. Somehow generated .tar.gz name has suddenly changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinavsingh no need to apologize :) This update has been widely noticed across many projects lately. setuptools made updates to the sdist base name normalization code in one of the recent releases which resulted in underscores appearing in place of . or -. This would've been more stable if setuptools was pinned for the build env (I don't think I implemented this in my earlier PRs but I tend to do this in my other projects).

Here's the corresponding change log entry upstream: https://setuptools.pypa.io/en/latest/history.html#v69-3-0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinavsingh while I'm here, I also noticed the use of ::set-output GHA workflow command syntax which has been deprecated for a while. The new way is appending to a file path provided to by the ${GITHUB_OUTPUT} environment variable. For example: https://github.com/cherrypy/cheroot/blob/3591a1c/.github/workflows/ci-cd.yml#L309-L327.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webknjaz You are a charm. Thank you for providing links and insights, I'll dig into them 🙏

steps.request-check.outputs.release-requested == 'true'
&& github.event.inputs.release-version
|| steps.scm-version.outputs.dist-version
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ build

pyreverse.png
profile.svg

*-pre-push
jaxl-api-credentials*.json
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"typescript.preferences.quoteStyle": "single",
"[python]": {
"editor.wordBasedSuggestions": "matchingDocuments",
"editor.defaultFormatter": null
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.testing.unittestEnabled": false,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2357,8 +2357,9 @@ usage: -m [-h] [--tunnel-hostname TUNNEL_HOSTNAME] [--tunnel-port TUNNEL_PORT]
[--plugins PLUGINS [PLUGINS ...]] [--enable-dashboard]
[--basic-auth BASIC_AUTH] [--enable-ssh-tunnel]
[--work-klass WORK_KLASS] [--pid-file PID_FILE] [--openssl OPENSSL]
[--enable-proxy-protocol] [--enable-conn-pool] [--key-file KEY_FILE]
[--cert-file CERT_FILE] [--client-recvbuf-size CLIENT_RECVBUF_SIZE]
[--data-dir DATA_DIR] [--enable-proxy-protocol] [--enable-conn-pool]
[--key-file KEY_FILE] [--cert-file CERT_FILE]
[--client-recvbuf-size CLIENT_RECVBUF_SIZE]
[--server-recvbuf-size SERVER_RECVBUF_SIZE]
[--max-sendbuf-size MAX_SENDBUF_SIZE] [--timeout TIMEOUT]
[--disable-http-proxy] [--disable-headers DISABLE_HEADERS]
Expand All @@ -2378,7 +2379,7 @@ usage: -m [-h] [--tunnel-hostname TUNNEL_HOSTNAME] [--tunnel-port TUNNEL_PORT]
[--filtered-client-ips FILTERED_CLIENT_IPS]
[--filtered-url-regex-config FILTERED_URL_REGEX_CONFIG]

proxy.py v2.4.4rc6.dev11+gac1f05d7.d20240413
proxy.py v2.4.4rc6.dev85+g9335918b

options:
-h, --help show this help message and exit
Expand Down Expand Up @@ -2459,6 +2460,7 @@ options:
--pid-file PID_FILE Default: None. Save "parent" process ID to a file.
--openssl OPENSSL Default: openssl. Path to openssl binary. By default,
assumption is that openssl is in your PATH.
--data-dir DATA_DIR Default: ~/.proxypy. Path to proxypy data directory.
--enable-proxy-protocol
Default: False. If used, will enable proxy protocol.
Only version 1 is currently supported.
Expand Down Expand Up @@ -2501,9 +2503,9 @@ options:
Default: None. Signing certificate to use for signing
dynamically generated HTTPS certificates. If used,
must also pass --ca-key-file and --ca-signing-key-file
--ca-file CA_FILE Default: /Users/abhinavsingh/Dev/proxy.py/.venv3118/li
b/python3.11/site-packages/certifi/cacert.pem. Provide
path to custom CA bundle for peer certificate
--ca-file CA_FILE Default: /Users/abhinavsingh/Dev/proxy.py/.venv31010/l
ib/python3.10/site-packages/certifi/cacert.pem.
Provide path to custom CA bundle for peer certificate
verification
--ca-signing-key-file CA_SIGNING_KEY_FILE
Default: None. CA signing key to use for dynamic
Expand Down
2 changes: 2 additions & 0 deletions proxy/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def _env_threadless_compliant() -> bool:
DOT = b'.'
SLASH = b'/'
AT = b'@'
AND = b'&'
EQUAL = b'='
HTTP_PROTO = b'http'
HTTPS_PROTO = HTTP_PROTO + b's'
HTTP_1_0 = HTTP_PROTO.upper() + SLASH + b'1.0'
Expand Down
8 changes: 7 additions & 1 deletion proxy/common/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,13 @@ def initialize(
),
)

args.proxy_py_data_dir = DEFAULT_DATA_DIRECTORY_PATH
args.proxy_py_data_dir = cast(
str,
opts.get(
'data_dir',
args.data_dir or DEFAULT_DATA_DIRECTORY_PATH,
),
)
os.makedirs(args.proxy_py_data_dir, exist_ok=True)

ca_cert_dir = opts.get('ca_cert_dir', args.ca_cert_dir)
Expand Down
7 changes: 7 additions & 0 deletions proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@
'By default, assumption is that openssl is in your PATH.',
)

flags.add_argument(
'--data-dir',
type=str,
default=None,
help='Default: ~/.proxypy. Path to proxypy data directory.',
)


class Proxy:
"""Proxy is a context manager to control proxy.py library core.
Expand Down
6 changes: 4 additions & 2 deletions requirements-tunnel.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
paramiko==2.11.0
types-paramiko==2.11.3
paramiko==2.11.0; python_version < '3.11'
paramiko==3.4.0; python_version >= '3.11'
types-paramiko==2.11.3; python_version < '3.11'
types-paramiko==3.4.0.20240311; python_version >= '3.11'
cryptography==36.0.2; python_version <= '3.6'
7 changes: 4 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
DEFAULT_ENABLE_SSH_TUNNEL, DEFAULT_ENABLE_WEB_SERVER,
DEFAULT_DISABLE_HTTP_PROXY, PLUGIN_WEBSOCKET_TRANSPORT,
DEFAULT_CA_SIGNING_KEY_FILE, DEFAULT_CLIENT_RECVBUF_SIZE,
DEFAULT_SERVER_RECVBUF_SIZE, DEFAULT_CACHE_DIRECTORY_PATH,
DEFAULT_ENABLE_REVERSE_PROXY, DEFAULT_ENABLE_STATIC_SERVER,
_env_threadless_compliant,
DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_SERVER_RECVBUF_SIZE,
DEFAULT_CACHE_DIRECTORY_PATH, DEFAULT_ENABLE_REVERSE_PROXY,
DEFAULT_ENABLE_STATIC_SERVER, _env_threadless_compliant,
)


Expand Down Expand Up @@ -83,6 +83,7 @@ def mock_default_args(mock_args: mock.Mock) -> None:
mock_args.enable_ssh_tunnel = DEFAULT_ENABLE_SSH_TUNNEL
mock_args.enable_reverse_proxy = DEFAULT_ENABLE_REVERSE_PROXY
mock_args.unix_socket_path = None
mock_args.data_dir = DEFAULT_DATA_DIRECTORY_PATH
mock_args.cache_dir = DEFAULT_CACHE_DIRECTORY_PATH

@mock.patch('os.remove')
Expand Down
Loading