Skip to content
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/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Show python version
run: python3 --version
- name: Execute tests
run: python3 -m robot -d ./docs examples/
run: cd examples && python3 -m robot -d ../docs .
- name: Archive test log
if: ${{ always() }}
uses: actions/upload-artifact@v4
Expand Down
1 change: 0 additions & 1 deletion examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:
broker:
image: confluentinc/cp-server:7.8.0
Expand Down
46 changes: 46 additions & 0 deletions examples/oauth2_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import time
import functools
import json
from robot.libraries.BuiltIn import BuiltIn


def create_test_token():
"""Create a test OAuth2 token for unsecured testing"""
token_payload = {
"sub": "test-user",
"iss": "test-issuer",
"aud": "kafka",
"exp": int(time.time()) + 3600,
"iat": int(time.time()),
"scope": "kafka-producer kafka-consumer"
}

import base64
token_json = json.dumps(token_payload)
test_token = base64.b64encode(token_json.encode()).decode()

return test_token


def oauth_cb_test_producer(oauth_config):
BuiltIn().set_global_variable("${SEEN_RF_OAUTH_CB_PRODUCER}", True)
test_token = create_test_token()
expiry_time = time.time() + 3600
BuiltIn().log(f"Generated test token: {test_token[:50]}...")
return test_token, expiry_time


def oauth_cb_test_consumer(oauth_config):
BuiltIn().set_global_variable("${SEEN_RF_OAUTH_CB_CONSUMER}", True)
test_token = create_test_token()
expiry_time = time.time() + 3600

return test_token, expiry_time


def get_test_producer_token(oauth_config=None):
return functools.partial(oauth_cb_test_producer, oauth_config or {})


def get_test_consumer_token(oauth_config=None):
return functools.partial(oauth_cb_test_consumer, oauth_config or {})
11 changes: 0 additions & 11 deletions examples/oauth_example.py

This file was deleted.

35 changes: 19 additions & 16 deletions examples/test_oauth.robot
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
*** Settings ***
Library ConfluentKafkaLibrary
Library oauth_example
Library oauth2_test
Library Collections
Library String


*** Variables ***
${SEEN_RF_OAUTH_CB} ${False}
${SEEN_RF_OAUTH_CB_PRODUCER} ${False}
${SEEN_RF_OAUTH_CB_CONSUMER} ${False}
${KAFKA_BOOTSTRAP_SERVERS} localhost:9092
${TEST_TOPIC} oauth2-test-topic


*** Test Cases ***
Example Oauth
[Documentation] Example of how to use OAUTH with library and call functools
... via get_token function. For better handling there could be
... some global variable which can be set inside of python lib.
... Not executable right now, needs update env (issue #21).
Test OAuth2 Token Generation
${test_token}= oauth2_test.create_test_token
Should Not Be Empty ${test_token}
${producer_token_func}= oauth2_test.get_test_producer_token
${consumer_token_func}= oauth2_test.get_test_consumer_token

Skip

Test OAuth2 Library Integration
${string_serializer}= Get String Serializer
${value_serializer}= Get String Serializer

# This returns: functools.partial(<function oauth_cb at 0x7f...>, 'configuration')
${fun}= oauth_example.get_token configuration

${producer_id}= Create Producer key_serializer=${string_serializer} value_serializer=${value_serializer} legacy=${False} security.protocol=sasl_plaintext sasl.mechanisms=OAUTHBEARER oauth_cb=${fun}

#...
${oauth_func}= oauth2_test.get_test_producer_token

${status} ${error}= Run Keyword And Ignore Error
... Create Producer localhost:9092
... oauth_cb=${oauth_func}
... security.protocol=sasl_plaintext
... sasl.mechanisms=OAUTHBEARER
Should Be Equal ${status} PASS
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
requires-python = ">=3.8"
dependencies = [
"robotframework >= 3.2.1",
"confluent-kafka == 2.12.0",
"confluent-kafka == 2.12.2",
"requests >= 2.25.1",
]

Expand All @@ -36,6 +36,7 @@ avro = [
json = [
"jsonschema >= 3.2.0",
"pyrsistent >= 0.20.0",
"orjson >= 3.10",
]
protobuf = [
"protobuf >= 4.22.0",
Expand All @@ -45,8 +46,8 @@ schemaregistry = [
"httpx>=0.26",
"cachetools >= 5.5.0",
"attrs >= 24.3.0",
"certifi",
"authlib >= 1.0.0",
"orjson >= 3.10",
]
all = [
"robotframework-confluentkafkalibrary[avro]",
Expand Down
2 changes: 1 addition & 1 deletion src/ConfluentKafkaLibrary/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.12.0.post1'
VERSION = '2.12.2.post1'