Repository navigation
Export generate_random_key and get_default_params from ably.pubsub.server - #733
Conversation
4.0 makes ably.pubsub.server the whole public API, but its export list was carried over from 3.x's top-level ably package, which only re-exported CipherParams. 3.x users reached generate_random_key and get_default_params through ably.util.crypto, a submodule that 4.0 moves and declares internal, so 4.0 left no public way to generate a key (RSE2) or build default cipher params. Export both from ably.pubsub.server and ably.pubsub.server.sync, show the 3.x to 4.0 import in UPDATING.md, and make the missing-crypto error name the ably-pubsub-server[crypto] extra instead of the old ably[crypto].
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe asynchronous and synchronous server modules now export ChangesCrypto helper exports
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Feature Suggested reviewers: Merge Risk: ⚪ Minimal · up to
|
Exports
generate_random_keyandget_default_paramsfromably.pubsub.serverandably.pubsub.server.sync, so 4.0 has a public way to generate a channel encryption key (RSE2) and build default cipher params.Why
4.0 makes
ably.pubsub.serverthe whole public API, and the packages beneath it are internal (UPDATING.md). Its__all__was carried over from 3.x's top-levelably/__init__.py, which only re-exportedCipherParamsfrom crypto. In 3.x, users got the key generator from the submodule instead:On 4.0 that raises
ModuleNotFoundError: No module named 'ably.util'. The function still exists atably.pubsub.util.crypto, but that path is internal, so there was no supported import. Every other Pub/Sub SDK exposes RSE2 publicly (Crypto.generateRandomKey()in Java, JS, Flutter and PHP,pubsub.Crypto.GenerateRandomKey()in Go,Crypto.GenerateRandomKey()in .NET).This came up in the 4.0 docs review (https://github.com/ably/website/pull/10418#discussion_r4281476680), where the Python encryption examples currently fall back to
secrets.token_bytes(32).Changes
ably/pubsub/server/__init__.pyandably/pubsub/server/sync.py: import and export both helpers.sync.pyis hand-written (unasync excludesably/pubsub/server), so it gets the same edit.ably/pubsub/util/nocrypto.py: the missing-crypto error now namespip install 'ably-pubsub-server[crypto]'instead of the 3.xably[crypto].UPDATING.md: a 3.x → 4.0.0 import example for the encryption helpers.test/unit/pubsub_server_test.py: asserts both names are in__all__of the async and sync modules.Checks
uv run unasync, thenpytest test/unit: 115 passed.ruff check: clean.pytest test/ably/http/httpcrypto_test.py -k "Fixture or random or default"(fixtures from the test-resources submodule): 6 passed.from ably.pubsub.server import generate_random_keygives a 32-byte key, and publishing on a channel withcipher={'key': key}sendsencoding: utf-8/cipher+aes-256-cbc/base64. The syncgenerate_random_key()also gives 32 bytes.Summary by CodeRabbit
generate_random_keyandget_default_paramsavailable through both synchronous and asynchronous server modules.