Skip to content
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

add extra_kwargs property #179

Open
wants to merge 1 commit into
base: main
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
3 changes: 2 additions & 1 deletion mockintosh/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def build_config_async_service(self, data: dict, internal_service_id: Union[int,
actors=[],
name=data.get('name', None),
ssl=data.get('ssl', False),
internal_service_id=internal_service_id
internal_service_id=internal_service_id,
extra_kwargs=data.get('extra_kwargs', None)
)

actors = []
Expand Down
4 changes: 3 additions & 1 deletion mockintosh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,16 @@ def __init__(
actors: List[ConfigActor] = [],
name: Union[str, None] = None,
ssl: bool = False,
internal_service_id: Union[int, None] = None
internal_service_id: Union[int, None] = None,
extra_kwargs: Union[dict, None] = None
):
super().__init__(_type, name, internal_service_id)
ConfigAsyncService.services.append(self)
self.type = _type
self.address = address
self.actors = actors
self.ssl = ssl
self.extra_kwargs = extra_kwargs

def get_hint(self):
return '%s://%s' % (self.type, self.address) if self.name is None else self.name
Expand Down
3 changes: 2 additions & 1 deletion mockintosh/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ def analyze_async_service(
name=service.name,
definition=self,
_id=service.internal_service_id,
ssl=service.ssl
ssl=service.ssl,
extra_kwargs=service.extra_kwargs
)
service._impl = async_service

Expand Down
4 changes: 4 additions & 0 deletions mockintosh/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"mqtt"
]
},
"extra_kwargs": {
"type": "object",
"default": {}
},
"actors": {
"type": "array",
"items": {
Expand Down
7 changes: 5 additions & 2 deletions mockintosh/services/asynchronous/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def consume(self) -> None:
'bootstrap.servers': first_actor.service.address,
'group.id': '0',
'auto.offset.reset': 'earliest'
**first_actor.service.extra_kwargs,
}
if first_actor.service.ssl:
config['security.protocol'] = 'SSL'
Expand Down Expand Up @@ -159,7 +160,7 @@ class KafkaProducerPayloadList(AsyncProducerPayloadList):
class KafkaProducer(AsyncProducer):

def _produce(self, key: str, value: str, headers: dict, payload: AsyncProducerPayload) -> None:
config = {'bootstrap.servers': self.actor.service.address}
config = {'bootstrap.servers': self.actor.service.address, **self.actor.service.extra_kwargs}
if self.actor.service.ssl:
config['security.protocol'] = 'SSL'
producer = Producer(config)
Expand Down Expand Up @@ -190,7 +191,8 @@ def __init__(
name: Union[str, None] = None,
definition=None,
_id: Union[int, None] = None,
ssl: bool = False
ssl: bool = False,
extra_kwargs: Union[dict, None] = None
):
super().__init__(
address,
Expand All @@ -200,6 +202,7 @@ def __init__(
ssl=ssl
)
self.type = 'kafka'
self.extra_kwargs = extra_kwargs or {}


def build_single_payload_producer(
Expand Down