Skip to content

Commit

Permalink
Merge branch 'master' into chore/update-license-info
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln authored Oct 30, 2023
2 parents 7f58087 + ba28d54 commit bf806eb
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 49 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/commands-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -42,4 +40,4 @@ jobs:
with:
token: ${{ secrets.GH_TOKEN }}
listener: ${{ secrets.CLEN_BOT }}
jira-api-key: ${{ secrets.JIRA_API_KEY }}
jira-api-key: ${{ secrets.JIRA_API_KEY }}
13 changes: 4 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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:
Expand Down
32 changes: 13 additions & 19 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion examples/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pubnub/pnconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion pubnub/pubnub_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class PubNubCore:

__metaclass__ = ABCMeta
_plugins = []
__crypto = None

def __init__(self, config):
self.config = config
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bf806eb

Please sign in to comment.