diff --git a/.github/workflows/commands-handler.yml b/.github/workflows/commands-handler.yml index 79c4e8a8..0b5d4702 100644 --- a/.github/workflows/commands-handler.yml +++ b/.github/workflows/commands-handler.yml @@ -11,13 +11,11 @@ jobs: process: name: Process command if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest steps: - name: Check referred user id: user-check - env: + env: CLEN_BOT: ${{ secrets.CLEN_BOT }} run: echo "expected-user=${{ startsWith(github.event.comment.body, format('@{0} ', env.CLEN_BOT)) }}" >> $GITHUB_OUTPUT - name: Regular comment @@ -27,7 +25,7 @@ jobs: if: steps.user-check.outputs.expected-user == 'true' uses: actions/checkout@v3 with: - token: ${{ secrets.GH_TOKEN }} + token: ${{ secrets.GH_TOKEN }} - name: Checkout release actions if: steps.user-check.outputs.expected-user == 'true' uses: actions/checkout@v3 @@ -42,4 +40,4 @@ jobs: with: token: ${{ secrets.GH_TOKEN }} listener: ${{ secrets.CLEN_BOT }} - jira-api-key: ${{ secrets.JIRA_API_KEY }} \ No newline at end of file + jira-api-key: ${{ secrets.JIRA_API_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3530d7b..8160de5e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,16 +2,13 @@ name: Automated product release on: pull_request: - branches: [ master ] - types: [ closed ] - + branches: [master] + types: [closed] jobs: check-release: name: Check release required - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true outputs: release: ${{ steps.check.outputs.ready }} @@ -30,9 +27,7 @@ jobs: token: ${{ secrets.GH_TOKEN }} publish: name: Publish package - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest needs: check-release if: needs.check-release.outputs.release == 'true' steps: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a3ae797d..76e8b955 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,9 +20,7 @@ env: jobs: tests: name: Integration and Unit tests - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest strategy: fail-fast: true matrix: @@ -52,9 +50,7 @@ jobs: uses: ./.github/.release/actions/actions/utils/fast-jobs-failure acceptance-tests: name: Acceptance tests - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest steps: - name: Checkout project uses: actions/checkout@v3 @@ -68,23 +64,23 @@ jobs: - name: Setup Python 3.9 uses: actions/setup-python@v4 with: - python-version: '3.9.13' + python-version: "3.9.13" - name: Run mock server action uses: ./.github/.release/actions/actions/mock-server with: token: ${{ secrets.GH_TOKEN }} - name: Install Python dependencies and run acceptance tests run: | - cp sdk-specifications/features/access/authorization-failure-reporting.feature tests/acceptance/pam - cp sdk-specifications/features/access/grant-token.feature tests/acceptance/pam - cp sdk-specifications/features/access/revoke-token.feature tests/acceptance/pam - cp sdk-specifications/features/encryption/cryptor-module.feature tests/acceptance/encryption - mkdir tests/acceptance/encryption/assets/ - cp sdk-specifications/features/encryption/assets/* tests/acceptance/encryption/assets/ + cp sdk-specifications/features/access/authorization-failure-reporting.feature tests/acceptance/pam + cp sdk-specifications/features/access/grant-token.feature tests/acceptance/pam + cp sdk-specifications/features/access/revoke-token.feature tests/acceptance/pam + cp sdk-specifications/features/encryption/cryptor-module.feature tests/acceptance/encryption + mkdir tests/acceptance/encryption/assets/ + cp sdk-specifications/features/encryption/assets/* tests/acceptance/encryption/assets/ - sudo pip3 install -r requirements-dev.txt - behave --junit tests/acceptance/pam - behave --junit tests/acceptance/encryption/cryptor-module.feature -t=~na=python -k + sudo pip3 install -r requirements-dev.txt + behave --junit tests/acceptance/pam + behave --junit tests/acceptance/encryption/cryptor-module.feature -t=~na=python -k - name: Expose acceptance tests reports uses: actions/upload-artifact@v3 if: always() @@ -97,9 +93,7 @@ jobs: uses: ./.github/.release/actions/actions/utils/fast-jobs-failure all-tests: name: Tests - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest needs: [tests, acceptance-tests] steps: - name: Tests summary diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index a75e0e52..686b9870 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -5,28 +5,24 @@ on: [push] jobs: lint: name: Lint project - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest steps: - name: Checkout project uses: actions/checkout@v3 - name: Setup Python 3.11 uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: "3.11" - name: Install Python dependencies and run acceptance tests run: | - sudo pip3 install -r requirements-dev.txt - flake8 --exclude=scripts/,src/,.cache,.git,.idea,.tox,._trial_temp/,venv/ --ignore F811,E402 + sudo pip3 install -r requirements-dev.txt + flake8 --exclude=scripts/,src/,.cache,.git,.idea,.tox,._trial_temp/,venv/ --ignore F811,E402 - name: Cancel workflow runs for commit on error if: failure() uses: ./.github/.release/actions/actions/utils/fast-jobs-failure pubnub-yml: name: "Validate .pubnub.yml" - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest steps: - name: Checkout project uses: actions/checkout@v3 @@ -46,9 +42,7 @@ jobs: uses: ./.github/.release/actions/actions/utils/fast-jobs-failure all-validations: name: Validations - runs-on: - group: Default Larger Runners - labels: ubuntu-latest-m + runs-on: ubuntu-latest needs: [pubnub-yml, lint] steps: - name: Validations summary diff --git a/examples/crypto.py b/examples/crypto.py index be7e37f2..63f42237 100644 --- a/examples/crypto.py +++ b/examples/crypto.py @@ -2,13 +2,15 @@ from os import getenv from pubnub.pnconfiguration import PNConfiguration from pubnub.pubnub import PubNub +from pubnub.crypto import PubNubCryptoModule +from pubnub.crypto_core import PubNubAesCbcCryptor from time import sleep channel = 'cipher_algorithm_experiment' def PNFactory(cipher_mode=AES.MODE_GCM, fallback_cipher_mode=AES.MODE_CBC) -> PubNub: - config = config = PNConfiguration() + config = PNConfiguration() config.publish_key = getenv('PN_KEY_PUBLISH') config.subscribe_key = getenv('PN_KEY_SUBSCRIBE') config.secret_key = getenv('PN_KEY_SECRET') @@ -45,3 +47,15 @@ def PNFactory(cipher_mode=AES.MODE_GCM, fallback_cipher_mode=AES.MODE_CBC) -> Pu print([message.entry for message in messages.result.messages]) except UnicodeDecodeError: print('Unable to decode - Exception has been thrown') + +# partial encrypt/decrypt example +config = PNConfiguration() +config.publish_key = getenv('PN_KEY_PUBLISH') +config.subscribe_key = getenv('PN_KEY_SUBSCRIBE') +config.user_id = 'experiment' +pubnub = PubNub(config) # pubnub instance without encryption +pubnub.crypto = PubNubCryptoModule({ + PubNubAesCbcCryptor.CRYPTOR_ID: PubNubAesCbcCryptor('myCipherKey') +}, PubNubAesCbcCryptor) +encrypted = pubnub.crypto.encrypt('My Secret Text') # encrypted wih AES cryptor and `myCipherKey` cipher key +decrypted = pubnub.crypto.decrypt(encrypted) diff --git a/pubnub/pnconfiguration.py b/pubnub/pnconfiguration.py index 96fbc3bf..8ee9992a 100644 --- a/pubnub/pnconfiguration.py +++ b/pubnub/pnconfiguration.py @@ -93,7 +93,7 @@ def fallback_cipher_mode(self): @fallback_cipher_mode.setter def fallback_cipher_mode(self, fallback_cipher_mode): - if fallback_cipher_mode not in self.ALLOWED_AES_MODES: + if fallback_cipher_mode and fallback_cipher_mode not in self.ALLOWED_AES_MODES: raise PubNubException('Cipher mode not supported') if fallback_cipher_mode is not self._fallback_cipher_mode: self._fallback_cipher_mode = fallback_cipher_mode diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index 0db34f05..1a36a77e 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -93,6 +93,7 @@ class PubNubCore: __metaclass__ = ABCMeta _plugins = [] + __crypto = None def __init__(self, config): self.config = config @@ -125,7 +126,11 @@ def uuid(self): @property def crypto(self) -> PubNubCryptoModule: - return self.config.crypto_module + return self.__crypto if self.__crypto else self.config.crypto_module + + @crypto.setter + def crypto(self, crypto: PubNubCryptoModule): + self.__crypto = crypto def add_listener(self, listener): self._validate_subscribe_manager_enabled()