Looking at the plugin documentation (https://airflow.incubator.apache.org/plugins.html), it is clear how to add to new hooks and operators, but I am adding a new hook that requires connection information. This information seems to be hard-coded in airflow/models.py
. Is there a way to add my own connection type to the list without altering Airflow's source code?
Configuring the ConnectionSpecify the snowflake password. For public key authentication, the passphrase for the private key. Specify the snowflake schema to be used. Specify the extra parameters (as json dictionary) that can be used in the snowflake connection.
Configuring the ConnectionSpecify the user name to connect. Specify the password to connect. Specify the extra parameters (as json dictionary) that can be used in MySQL connection. Note that you can choose the client to connect to the database by setting the client extra field.
airflow Connection's conn_type field allows null value. so if you don't care about giving unique type name to your custom hook, then you can give a default connection value in your hook implementation.
from airflow.exceptions import AirflowException
from airflow.hooks.base_hook import BaseHook
from airflow.utils.db import provide_session
class MyHook(BaseHook):
# ... impl whatever you want.
@classmethod
@provide_session
def get_hook(cls, conn_id='myhook_default', session=None):
try:
conn = cls.get_connection(conn_id)
except AirflowException:
# create default connection. run only once.
conn = Connection(
conn_id=conn_id,
# conn_type='string500', # You can give new type string here. But no UI component's for you. Just leave it.
host='default.example.com',
port=80,
login='default_login',
password='default_pw',
extra=json.dumps({...extra_defult_you_need...}),
)
session.add(conn)
session.commit()
return MyHook(conn=conn)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With