This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 9829e86cf6 Add docs to redis connection (#36581)
9829e86cf6 is described below
commit 9829e86cf6f111814b23746e25d316f34d502466
Author: shohamy7 <[email protected]>
AuthorDate: Thu Jan 4 10:39:08 2024 +0200
Add docs to redis connection (#36581)
* Add docs for redis connection and add user-friendly connection form
* Add username for redis connection and docs
---
airflow/providers/redis/hooks/redis.py | 51 +++++++++++++++++
.../apache-airflow-providers-redis/connections.rst | 64 ++++++++++++++++++++++
docs/apache-airflow-providers-redis/index.rst | 1 +
3 files changed, 116 insertions(+)
diff --git a/airflow/providers/redis/hooks/redis.py
b/airflow/providers/redis/hooks/redis.py
index ef447c3fe1..a481dbe565 100644
--- a/airflow/providers/redis/hooks/redis.py
+++ b/airflow/providers/redis/hooks/redis.py
@@ -19,12 +19,16 @@
from __future__ import annotations
import warnings
+from typing import Any
from redis import Redis
from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.hooks.base import BaseHook
+DEFAULT_SSL_CERT_REQS = "required"
+ALLOWED_SSL_CERT_REQS = [DEFAULT_SSL_CERT_REQS, "optional", "none"]
+
class RedisHook(BaseHook):
"""
@@ -104,3 +108,50 @@ class RedisHook(BaseHook):
)
return self.redis
+
+ @classmethod
+ def get_ui_field_behaviour(cls) -> dict[str, Any]:
+ """Returns custom field behaviour."""
+ return {
+ "hidden_fields": ["schema", "extra"],
+ "relabeling": {},
+ }
+
+ @classmethod
+ def get_connection_form_widgets(cls) -> dict[str, Any]:
+ """Returns connection widgets to add to connection form."""
+ from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
+ from flask_babel import lazy_gettext
+ from wtforms import BooleanField, IntegerField, StringField
+ from wtforms.validators import Optional, any_of
+
+ return {
+ "db": IntegerField(lazy_gettext("DB"),
widget=BS3TextFieldWidget(), default=0),
+ "ssl": BooleanField(lazy_gettext("Enable SSL"), default=False),
+ "ssl_cert_reqs": StringField(
+ lazy_gettext("SSL verify mode"),
+ validators=[any_of(ALLOWED_SSL_CERT_REQS)],
+ widget=BS3TextFieldWidget(),
+ description=f"Must be one of: {',
'.join(ALLOWED_SSL_CERT_REQS)}.",
+ default=DEFAULT_SSL_CERT_REQS,
+ ),
+ "ssl_ca_certs": StringField(
+ lazy_gettext("CA certificate path"),
+ widget=BS3TextFieldWidget(),
+ validators=[Optional()],
+ default=None,
+ ),
+ "ssl_keyfile": StringField(
+ lazy_gettext("Private key path"),
+ widget=BS3TextFieldWidget(),
+ validators=[Optional()],
+ default=None,
+ ),
+ "ssl_certfile": StringField(
+ lazy_gettext("Certificate path"),
+ widget=BS3TextFieldWidget(),
+ validators=[Optional()],
+ default=None,
+ ),
+ "ssl_check_hostname": BooleanField(lazy_gettext("Enable hostname
check"), default=False),
+ }
diff --git a/docs/apache-airflow-providers-redis/connections.rst
b/docs/apache-airflow-providers-redis/connections.rst
new file mode 100644
index 0000000000..330447023f
--- /dev/null
+++ b/docs/apache-airflow-providers-redis/connections.rst
@@ -0,0 +1,64 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ .. http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+Redis Connection
+================
+
+The Redis connection type enables connection to Redis cluster.
+
+Default Connection IDs
+----------------------
+
+Redis Hook uses parameter ``redis_conn_id`` for Connection IDs and the value
of the
+parameter as ``redis_default`` by default.
+
+Configuring the Connection
+--------------------------
+Host
+ The host of the Redis cluster.
+
+Port
+ Specify the port to use for connecting the Redis cluster (Default is
``6379``).
+
+Login
+ The user that will be used for authentication against the Redis cluster
(only applicable in Redis 6.0 and above).
+
+Password
+ The password of the user that will be used for authentication against the
Redis cluster.
+
+DB
+ The DB number to use in the Redis cluster (Default is ``0``).
+
+Enable SSL
+ Whether to enable SSL connection to the Redis cluster (Default is
``False``).
+
+SSL verify mode
+ Whether to try to verify other peers' certificates and how to behave if
verification fails.
+ For more information, see: `Python SSL docs
<https://docs.python.org/3/library/ssl.html#ssl.SSLContext.verify_mode>`_.
+ Allowed values are: ``required``, ``optional``, ``none``.
+
+CA certificate path
+ The path to a file of concatenated CA certificates in PEM format (Default
is ``None``).
+
+Private key path
+ Path to an ssl private key (Default is ``None``).
+
+Certificate path
+ Path to an ssl certificate (Default is ``None``).
+
+Enable hostname check
+ If set, match the hostname during the SSL handshake (Default is ``False``).
diff --git a/docs/apache-airflow-providers-redis/index.rst
b/docs/apache-airflow-providers-redis/index.rst
index 291434e08c..e8ef81ba2f 100644
--- a/docs/apache-airflow-providers-redis/index.rst
+++ b/docs/apache-airflow-providers-redis/index.rst
@@ -34,6 +34,7 @@
:maxdepth: 1
:caption: Guides
+ Connection types <connections>
Logging <logging/index>
.. toctree::