Skip to content

Commit

Permalink
Instead of opt-out immutable config opt-in with deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Jul 31, 2024
1 parent ccf9c7d commit 64fce87
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
4 changes: 3 additions & 1 deletion pubnub/pnconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ def __init__(self):
self.cryptor = None
self.file_cryptor = None
self._crypto_module = None
self.disable_config_locking = False
self.disable_config_locking = True
self._locked = False

def validate(self):
PNConfiguration.validate_not_empty_string(self.uuid)
if self.disable_config_locking:
warnings.warn(DeprecationWarning('Mutable config will be deprecated in the future.'))

def validate_not_empty_string(value: str):
assert value and isinstance(value, str) and value.strip() != "", "UUID missing or invalid type"
Expand Down
1 change: 0 additions & 1 deletion pubnub/pubnub_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def __init__(self, config: PNConfiguration):
if not config.disable_config_locking:
config.lock()
self.config = deepcopy(config)
self.config.lock()
else:
self.config = config
self.config.validate()
Expand Down
14 changes: 0 additions & 14 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@
pnconf.subscribe_key = sub_key
pnconf.enable_subscribe = False
pnconf.uuid = uuid_mock
pnconf.disable_config_locking = True

pnconf_sub = PNConfiguration()
pnconf_sub.publish_key = pub_key
pnconf_sub.subscribe_request_timeout = 10
pnconf_sub.subscribe_key = sub_key
pnconf_sub.uuid = uuid_mock
pnconf_sub.disable_config_locking = True
pnconf_sub.enable_presence_heartbeat = True
pnconf_sub.set_presence_timeout_with_custom_interval(30, 10)

Expand All @@ -72,15 +70,13 @@
pnconf_enc.cipher_key = "testKey"
pnconf_enc.enable_subscribe = False
pnconf_enc.uuid = uuid_mock
pnconf_enc.disable_config_locking = True

pnconf_enc_sub = PNConfiguration()
pnconf_enc_sub.publish_key = pub_key
pnconf_enc_sub.subscribe_request_timeout = 10
pnconf_enc_sub.subscribe_key = sub_key
pnconf_enc_sub.cipher_key = "testKey"
pnconf_enc_sub.uuid = uuid_mock
pnconf_enc_sub.disable_config_locking = True

pnconf_pam = PNConfiguration()
pnconf_pam.publish_key = pub_key_pam
Expand All @@ -89,7 +85,6 @@
pnconf_pam.secret_key = sec_key_pam
pnconf_pam.enable_subscribe = False
pnconf_pam.uuid = uuid_mock
pnconf_pam.disable_config_locking = True


pnconf_pam_stub = PNConfiguration()
Expand All @@ -98,44 +93,38 @@
pnconf_pam_stub.subscribe_key = "sub-c-stub"
pnconf_pam_stub.secret_key = "sec-c-stub"
pnconf_pam_stub.uuid = uuid_mock
pnconf_pam_stub.disable_config_locking = True

pnconf_ssl = PNConfiguration()
pnconf_ssl.publish_key = pub_key
pnconf_ssl.subscribe_request_timeout = 10
pnconf_ssl.subscribe_key = sub_key
pnconf_ssl.ssl = True
pnconf_ssl.uuid = uuid_mock
pnconf_ssl.disable_config_locking = True

message_count_config = PNConfiguration()
message_count_config.publish_key = 'demo-36'
message_count_config.subscribe_request_timeout = 10
message_count_config.subscribe_key = 'demo-36'
message_count_config.origin = 'balancer1g.bronze.aws-pdx-1.ps.pn'
message_count_config.uuid = uuid_mock
message_count_config.disable_config_locking = True

pnconf_demo = PNConfiguration()
pnconf_demo.publish_key = 'demo'
pnconf_demo.subscribe_request_timeout = 10
pnconf_demo.subscribe_key = 'demo'
pnconf_demo.uuid = uuid_mock
pnconf_demo.disable_config_locking = True

file_upload_config = PNConfiguration()
file_upload_config.publish_key = pub_key_mock
file_upload_config.subscribe_request_timeout = 10
file_upload_config.subscribe_key = sub_key_mock
file_upload_config.uuid = uuid_mock
file_upload_config.disable_config_locking = True

mocked_config = PNConfiguration()
mocked_config.publish_key = pub_key_mock
mocked_config.subscribe_request_timeout = 10
mocked_config.subscribe_key = sub_key_mock
mocked_config.uuid = uuid_mock
mocked_config.disable_config_locking = True

hardcoded_iv_config = PNConfiguration()
hardcoded_iv_config.use_random_initialization_vector = False
Expand All @@ -148,7 +137,6 @@
pnconf_env.subscribe_key = os.environ.get('PN_KEY_SUBSCRIBE')
pnconf_env.enable_subscribe = False
pnconf_env.uuid = uuid_mock
pnconf_env.disable_config_locking = True

# configuration with keys from PN_KEY_* (enabled all except PAM, PUSH and FUNCTIONS) and encryption enabled
pnconf_enc_env = PNConfiguration()
Expand All @@ -158,7 +146,6 @@
pnconf_enc_env.cipher_key = "testKey"
pnconf_enc_env.enable_subscribe = False
pnconf_enc_env.uuid = uuid_mock
pnconf_enc_env.disable_config_locking = True

# configuration with keys from PN_KEY_PAM_* (enabled with all including PAM except PUSH and FUNCTIONS)
pnconf_pam_env = PNConfiguration()
Expand All @@ -168,7 +155,6 @@
pnconf_pam_env.secret_key = os.environ.get('PN_KEY_PAM_SECRET')
pnconf_pam_env.enable_subscribe = False
pnconf_pam_env.uuid = uuid_mock
pnconf_pam_env.disable_config_locking = True


def copy_and_update(config, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore:Mutable config will be deprecated in the future.:DeprecationWarning
4 changes: 4 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class TestPubNubConfig:
def test_config_copy_with_mutability_lock(self):
config = PNConfiguration()
config.disable_config_locking = False
config.publish_key = 'demo'
config.subscribe_key = 'demo'
config.user_id = 'demo'
Expand All @@ -30,6 +31,7 @@ def test_config_copy_with_mutability_lock_disabled(self):
def test_config_mutability_lock(self):
with pytest.warns(UserWarning):
config = PNConfiguration()
config.disable_config_locking = False
config.publish_key = 'demo'
config.subscribe_key = 'demo'
config.user_id = 'demo'
Expand All @@ -56,6 +58,7 @@ def test_config_mutability_lock_disabled(self):
@pytest.mark.asyncio
async def test_asyncio_config_copy_with_mutability_lock(self):
config = PNConfiguration()
config.disable_config_locking = False
config.publish_key = 'demo'
config.subscribe_key = 'demo'
config.user_id = 'demo'
Expand All @@ -80,6 +83,7 @@ async def test_asyncio_config_copy_with_mutability_lock_disabled(self):
async def test_asyncio_config_mutability_lock(self):
with pytest.warns(UserWarning):
config = PNConfiguration()
config.disable_config_locking = False
config.publish_key = 'demo'
config.subscribe_key = 'demo'
config.user_id = 'demo'
Expand Down

0 comments on commit 64fce87

Please sign in to comment.