Skip to content

fix import and support kafka ssl #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions robotframework_pykafka/kafka_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from pykafka import KafkaClient
from pykafka.common import OffsetType
from utils import *
from robotframework_pykafka.utils import *

##################################################
# Kafka helper class.
Expand All @@ -17,7 +17,7 @@ class kafka_helper:
# 1. constructor parameters if they are non-None and non-empty
# 2. environment variables KAFKA_HOST and KAFKA_BROKER_VERSION
# 3. default values (localhost and 2.3)
def __init__(self, kafkaBrokerHostname = None, kafkaBrokerVersion = None):
def __init__(self, kafkaBrokerHostname=None, kafkaBrokerVersion=None, cafile=None):

# Determine the kafka host
self._kafkaHost = ""
Expand Down Expand Up @@ -45,8 +45,22 @@ def __init__(self, kafkaBrokerHostname = None, kafkaBrokerVersion = None):
except Exception as e:
raise e

self._cafile = ""
if cafile:
self._cafile = cafile
else:
try:
self._cafile = os.environ['CAFILE']
except KeyError:
pass

# Get a kafka client
self._client = KafkaClient(hosts = self._kafkaHost, broker_version = self._kafkaBrokerVersion)
if self._cafile:
config = SslConfig(cafile=self._cafile)
self._client = KafkaClient(hosts=self._kafkaHost, broker_version=self._kafkaBrokerVersion,
ssl_config=config)
else:
self._client = KafkaClient(hosts=self._kafkaHost, broker_version=self._kafkaBrokerVersion)

self._producers = dict()

Expand Down
2 changes: 1 addition & 1 deletion robotframework_pykafka/robotframework_pykafka.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/python3

from kafka_helper import *
from robotframework_pykafka.kafka_helper import *
from robot.api import logger
from robot.api.deco import keyword

Expand Down