airflow.models.connection

Module Contents

Classes

Connection

Placeholder to store information about different database instances connection information.

Functions

sanitize_conn_id(conn_id[, max_length])

Sanitizes the connection id and allows only specific characters to be within.

Attributes

log

RE_SANITIZE_CONN_ID

CONN_ID_MAX_LEN

airflow.models.connection.log[source]
airflow.models.connection.RE_SANITIZE_CONN_ID[source]
airflow.models.connection.CONN_ID_MAX_LEN: int = 250[source]
airflow.models.connection.sanitize_conn_id(conn_id, max_length=CONN_ID_MAX_LEN)[source]

Sanitizes the connection id and allows only specific characters to be within.

Namely, it allows alphanumeric characters plus the symbols #,!,-,_,.,:,,/ and () from 1 and up to 250 consecutive matches. If desired, the max length can be adjusted by setting max_length.

You can try to play with the regex here: https://regex101.com/r/69033B/1

The character selection is such that it prevents the injection of javascript or executable bits to avoid any awkward behaviour in the front-end.

Parameters
  • conn_id (str | None) – The connection id to sanitize.

  • max_length – The max length of the connection ID, by default it is 250.

Returns

the sanitized string, None otherwise.

Return type

str | None

class airflow.models.connection.Connection(conn_id=None, conn_type=None, description=None, host=None, login=None, password=None, schema=None, port=None, extra=None, uri=None)[source]

Bases: airflow.models.base.Base, airflow.utils.log.logging_mixin.LoggingMixin

Placeholder to store information about different database instances connection information.

The idea here is that scripts use references to database instances (conn_id) instead of hard coding hostname, logins and passwords when using operators or hooks.

See also

For more information on how to use this class, see: Managing Connections

Parameters
  • conn_id (str | None) – The connection ID.

  • conn_type (str | None) – The connection type.

  • description (str | None) – The connection description.

  • host (str | None) – The host.

  • login (str | None) – The login.

  • password (str | None) – The password.

  • schema (str | None) – The schema.

  • port (int | None) – The port number.

  • extra (str | dict | None) – Extra metadata. Non-standard data such as private/SSH keys can be saved here. JSON encoded object.

  • uri (str | None) – URI address describing connection parameters.

property password[source]

Password. The value is decrypted/encrypted when reading/setting the value.

property extra[source]

Extra data. The value is decrypted/encrypted when reading/setting the value.

property extra_dejson: dict[source]

Returns the extra property by deserializing json.

EXTRA_KEY = '__extra__'[source]
__tablename__ = 'connection'[source]
id[source]
conn_id[source]
conn_type[source]
description[source]
host[source]
schema[source]
login[source]
port[source]
is_encrypted[source]
is_extra_encrypted[source]
on_db_load()[source]
get_uri()[source]

Return connection in URI format.

get_password()[source]

Return encrypted password.

set_password(value)[source]

Encrypt password and set in object attribute.

get_extra()[source]

Return encrypted extra-data.

set_extra(value)[source]

Encrypt extra-data and save in object attribute to object.

rotate_fernet_key()[source]

Encrypts data with a new key. See: Fernet.

get_hook(*, hook_params=None)[source]

Return hook based on conn_type.

__repr__()[source]

Return repr(self).

test_connection()[source]

Calls out get_hook method and executes test_connection method on that.

get_extra_dejson(nested=False)[source]

Deserialize extra property to JSON.

Parameters

nested (bool) – Determines whether nested structures are also deserialized into JSON (default False).

classmethod get_connection_from_secrets(conn_id)[source]

Get connection by conn_id.

Parameters

conn_id (str) – connection id

Returns

connection

Return type

Connection

classmethod from_json(value, conn_id=None)[source]
as_json()[source]

Convert Connection to JSON-string object.

Was this entry helpful?