Skip to content

Commit

Permalink
Add docs to redis connection (#36581)
Browse files Browse the repository at this point in the history
* Add docs for redis connection and add user-friendly connection form

* Add username for redis connection and docs
  • Loading branch information
shohamy7 authored Jan 4, 2024
1 parent fc2478e commit 9829e86
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
51 changes: 51 additions & 0 deletions airflow/providers/redis/hooks/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -104,3 +108,50 @@ def get_conn(self):
)

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),
}
64 changes: 64 additions & 0 deletions docs/apache-airflow-providers-redis/connections.rst
Original file line number Diff line number Diff line change
@@ -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``).
1 change: 1 addition & 0 deletions docs/apache-airflow-providers-redis/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
:maxdepth: 1
:caption: Guides

Connection types <connections>
Logging <logging/index>

.. toctree::
Expand Down

0 comments on commit 9829e86

Please sign in to comment.