kaxil commented on a change in pull request #6863: [AIRFLOW-XXX] add docs
showing usage of `Connection.get_uri`
URL: https://github.com/apache/airflow/pull/6863#discussion_r360701746
##########
File path: docs/howto/connection/index.rst
##########
@@ -81,6 +81,36 @@ in the scheme part of URI, so it must be changed to a
hyphen character
(e.g. ``google-compute-platform`` if ``conn_type`` is
``google_compute_platform``).
Query parameters are parsed to one-dimensional dict and then used to fill
extra.
+Generating a connection URI
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Building the URI for a connection can be tricky. To make it easier, the
+:py:class:`~airflow.models.connection.Connection` class has a convenience
method
+:py:meth:`~airflow.models.connection.Connection.get_uri`. It can be used like
so:
+
+.. code-block:: python
+
+ from airflow.models.connection import Connection
+
+ c = Connection(
+ conn_id='some_conn',
+ conn_type='mysql',
+ host='myhost.com',
+ login='myname',
+ password='mypassword',
+ extra=json.dumps(dict(this_param='some val', that_param='other val*')),
+ )
+ print(f"AIRFLOW_CONN_{c.conn_id.upper()}='{c.get_uri()}'")
+
Review comment:
Can you add an example output of such URI
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services