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 username as a parameter for redis components on 3.4.x #12835

Merged
1 change: 1 addition & 0 deletions changelog/12835.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `username` to the connection parameters for `RedisLockStore` and `RedisTrackerStore`
14 changes: 14 additions & 0 deletions data/test_endpoints/example_endpoints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,27 @@ tracker_store:
url: localhost
port: 6379
db: 0
username: username
password: password
key_prefix: conversation
record_exp: 30000
use_ssl: True
ssl_keyfile: "keyfile.key"
ssl_certfile: "certfile.crt"
ssl_ca_certs: "my-bundle.ca-bundle"
# example of redis external lock store config
lock_store:
type: redis
url: localhost
port: 6379
db: 0
username: username
password: password
key_prefix: lock
use_ssl: True
ssl_keyfile: "keyfile.key"
ssl_certfile: "certfile.crt"
ssl_ca_certs: "my-bundle.ca-bundle"
# example of mongoDB external tracker store config
#tracker_store:
#type: mongod
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/lock-stores.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ The `ConcurrentRedisLockStore` recreates the `TicketLock` from the persisted `Ti
- `key_prefix` (default: `None`): The prefix to prepend to lock store keys. Must
be alphanumeric

- `username` (default: `None`): Username used for authentication

- `password` (default: `None`): Password used for authentication
(`None` equals no authentication)

Expand Down
2 changes: 2 additions & 0 deletions docs/docs/tracker-stores.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ To set up Rasa with Redis the following steps are required:
* `key_prefix` (default: `None`): The prefix to prepend to tracker store keys. Must
be alphanumeric

* `username` (default: `None`): Username used for authentication

* `password` (default: `None`): Password used for authentication
(`None` equals no authentication)

Expand Down
4 changes: 4 additions & 0 deletions rasa/core/lock_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def __init__(
host: Text = "localhost",
port: int = 6379,
db: int = 1,
username: Optional[Text] = None,
password: Optional[Text] = None,
use_ssl: bool = False,
ssl_certfile: Optional[Text] = None,
Expand All @@ -215,6 +216,8 @@ def __init__(
port: The port of the redis server.
db: The name of the database within Redis which should be used by Rasa
Open Source.
username: The username which should be used for authentication with the
Redis database.
password: The password which should be used for authentication with the
Redis database.
use_ssl: `True` if SSL should be used for the connection to Redis.
Expand All @@ -232,6 +235,7 @@ def __init__(
host=host,
port=int(port),
db=int(db),
username=username,
password=password,
ssl=use_ssl,
ssl_certfile=ssl_certfile,
Expand Down
2 changes: 2 additions & 0 deletions rasa/core/tracker_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ def __init__(
host: Text = "localhost",
port: int = 6379,
db: int = 0,
username: Optional[Text] = None,
password: Optional[Text] = None,
event_broker: Optional[EventBroker] = None,
record_exp: Optional[float] = None,
Expand All @@ -470,6 +471,7 @@ def __init__(
host=host,
port=port,
db=db,
username=username,
password=password,
ssl=use_ssl,
ssl_keyfile=ssl_keyfile,
Expand Down
33 changes: 25 additions & 8 deletions tests/core/test_lock_store.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import asyncio
import logging
import sys
import time
from pathlib import Path
from typing import Text
from unittest.mock import Mock, patch

import numpy as np
import pytest
import time

import rasa.core.lock_store
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from unittest.mock import patch, Mock

from rasa.core.agent import Agent
from rasa.core.channels import UserMessage
from rasa.core.constants import DEFAULT_LOCK_LIFETIME
from rasa.shared.constants import INTENT_MESSAGE_PREFIX
from rasa.core.lock import TicketLock
import rasa.core.lock_store
from rasa.core.lock_store import (
DEFAULT_REDIS_LOCK_STORE_KEY_PREFIX,
InMemoryLockStore,
LockError,
LockStore,
RedisLockStore,
DEFAULT_REDIS_LOCK_STORE_KEY_PREFIX,
)
from rasa.shared.constants import INTENT_MESSAGE_PREFIX
from rasa.shared.exceptions import ConnectionException
from rasa.utils.endpoints import EndpointConfig
from rasa.utils.endpoints import EndpointConfig, read_endpoint_config


class FakeRedisLockStore(RedisLockStore):
Expand Down Expand Up @@ -384,3 +383,21 @@ async def test_redis_lock_store_with_valid_prefix(monkeypatch: MonkeyPatch):
with pytest.raises(LockError):
async with lock_store.lock("some sender"):
pass


def test_create_lock_store_from_endpoint_config(endpoints_path: Text):
store = read_endpoint_config(endpoints_path, endpoint_type="lock_store")
tracker_store = RedisLockStore(
host="localhost",
port=6379,
db=0,
username="username",
password="password",
use_ssl=True,
ssl_keyfile="keyfile.key",
ssl_certfile="certfile.crt",
ssl_ca_certs="my-bundle.ca-bundle",
key_prefix="lock",
)

assert isinstance(tracker_store, type(LockStore.create(store)))
2 changes: 2 additions & 0 deletions tests/core/test_tracker_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def test_tracker_store_endpoint_config_loading(endpoints_path: Text):
"url": "localhost",
"port": 6379,
"db": 0,
"username": "username",
"password": "password",
"timeout": 30000,
"use_ssl": True,
Expand All @@ -162,6 +163,7 @@ def test_create_tracker_store_from_endpoint_config(
host="localhost",
port=6379,
db=0,
username="username",
password="password",
record_exp=3000,
use_ssl=True,
Expand Down
Loading