ecerulm opened a new issue #14597:
URL: https://github.com/apache/airflow/issues/14597
**Description**
Expose the connection into the jinja template context via
`conn.<connectionname>.{host,port,login,password,extra_config,etc}`
Today is possible to conveniently access [airflow's
variables](https://airflow.apache.org/docs/apache-airflow/stable/concepts.html#variables)
in jinja templates using `{{ var.value.<variable_name> }}`.
There is no equivalent (to my knowledge for
[connections](https://airflow.apache.org/docs/apache-airflow/stable/concepts.html#connections)),
I understand that most of the time connection are used programmatically in
Operators and Hooks source code, but there are use cases where the connection
info has to be pass as parameters to the operators and then it becomes
cumbersome to do it without jinja template syntax.
I seen workarounds like using [user defined macros to provide
get_login(my_conn_id)](https://stackoverflow.com/questions/65826404/use-airflow-connection-from-a-jinja-template/65873023#65873023
), but I'm after a consistent interface for accessing both variables and
connections in the same way
**Use case / motivation**
For example, passing credentials to a
[KubernetesPodOperator](https://airflow.apache.org/docs/apache-airflow-providers-cncf-kubernetes/stable/operators.html#howto-operator-kubernetespodoperator)
via
[env_vars](https://cloud.google.com/composer/docs/how-to/using/using-kubernetes-pod-operator)
today has to be done like this:
```
connection = Connection.get_connection_from_secrets('somecredentials')
k = KubernetesPodOperator(
task_id='task1',
env_vars={'MY_VALUE': '{{ var.value.my_value }}', 'PWD': conn.password,},
)
```
where I would prefer to use consistent syntax for both variables and
connections like this:
```
# not needed anymore: connection =
Connection.get_connection_from_secrets('somecredentials')
k = KubernetesPodOperator(
task_id='task1',
env_vars={'MY_VALUE': '{{ var.value.my_value }}', 'PWD': '{{
conn.somecredentials.password }}',},
)
```
The same applies to `BashOperator` where I sometimes feel the need to pass
connection information to the templated script.
**Are you willing to submit a PR?**
yes, I can write the PR.
**Related Issues**
----------------------------------------------------------------
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]