jedcunningham commented on code in PR #31533: URL: https://github.com/apache/airflow/pull/31533#discussion_r1210939825
########## docs/apache-airflow-providers-apprise/connections.rst: ########## @@ -0,0 +1,42 @@ + .. 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. + Review Comment: ```suggestion .. _howto/connection:apprise: ``` So we can link here... ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): Review Comment: ```suggestion def __init__(self, apprise_conn_id: str = default_conn_name) -> None: ``` ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): + super().__init__() + self.apprise_conn_id = apprise_conn_id + + def get_config_from_conn(self): + conn = self.get_connection(self.apprise_conn_id) + return json.loads(conn.extra_dejson["config"]) + + def set_config_from_conn(self, apprise_obj: apprise.Apprise): + """Set config from connection to apprise object""" + config_object = self.get_config_from_conn() + if isinstance(config_object, list): + for config in config_object: + apprise_obj.add(config["path"], tag=config.get("tag", None)) + elif isinstance(config_object, dict): + apprise_obj.add(config_object["path"], tag=config_object.get("tag", None)) + else: + raise ValueError("only dict / list[dict] type of values are expected") + + def notify( + self, + body: str, + title: str | None = None, + notify_type: NotifyType = NotifyType.INFO, + body_format: NotifyFormat = NotifyFormat.TEXT, + tag: str | Iterable[str] | None = None, + attach: str | None = None, + interpret_escapes: bool | None = None, + config: AppriseConfig | None = None, + ): + r""" + Send message to plugged-in services + + :param body: Specify the message body + :param title: Specify the message title. This field is complete optional Review Comment: ```suggestion :param title: Specify the message title. (optional) ``` ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): + super().__init__() + self.apprise_conn_id = apprise_conn_id + + def get_config_from_conn(self): + conn = self.get_connection(self.apprise_conn_id) + return json.loads(conn.extra_dejson["config"]) + + def set_config_from_conn(self, apprise_obj: apprise.Apprise): + """Set config from connection to apprise object""" + config_object = self.get_config_from_conn() + if isinstance(config_object, list): + for config in config_object: + apprise_obj.add(config["path"], tag=config.get("tag", None)) + elif isinstance(config_object, dict): + apprise_obj.add(config_object["path"], tag=config_object.get("tag", None)) + else: + raise ValueError("only dict / list[dict] type of values are expected") + + def notify( + self, + body: str, + title: str | None = None, + notify_type: NotifyType = NotifyType.INFO, + body_format: NotifyFormat = NotifyFormat.TEXT, + tag: str | Iterable[str] | None = None, + attach: str | None = None, + interpret_escapes: bool | None = None, + config: AppriseConfig | None = None, + ): + r""" + Send message to plugged-in services + + :param body: Specify the message body + :param title: Specify the message title. This field is complete optional + :param notify_type: Specify the message type (default=info). Possible values are "info", + "success", "failure", and "warning" + :param body_format: Specify the input message format (default=text). Possible values are "text", + "html", and "markdown". + :param tag: Specify one or more tags to filter which services to notify + :param attach: Specify one or more file attachment locations + :param interpret_escapes: Enable interpretation of backslash escapes. For example, this would convert + sequences such as \n and \r to their respected ascii new-line and carriage Review Comment: ```suggestion sequences such as \n and \r to their respective ascii new-line and carriage return characters ``` ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): + super().__init__() + self.apprise_conn_id = apprise_conn_id + + def get_config_from_conn(self): + conn = self.get_connection(self.apprise_conn_id) + return json.loads(conn.extra_dejson["config"]) + + def set_config_from_conn(self, apprise_obj: apprise.Apprise): + """Set config from connection to apprise object""" + config_object = self.get_config_from_conn() + if isinstance(config_object, list): + for config in config_object: + apprise_obj.add(config["path"], tag=config.get("tag", None)) + elif isinstance(config_object, dict): + apprise_obj.add(config_object["path"], tag=config_object.get("tag", None)) + else: + raise ValueError("only dict / list[dict] type of values are expected") + + def notify( + self, + body: str, + title: str | None = None, + notify_type: NotifyType = NotifyType.INFO, + body_format: NotifyFormat = NotifyFormat.TEXT, + tag: str | Iterable[str] | None = None, + attach: str | None = None, + interpret_escapes: bool | None = None, + config: AppriseConfig | None = None, + ): + r""" Review Comment: Might be better to not use a raw string and just escape the 2 slashes. ########## generated/provider_dependencies.json: ########## @@ -201,6 +201,14 @@ "cross-providers-deps": [], "excluded-python-versions": [] }, + "apprise": { + "deps": [ + "apache-airflow>=2.2.0", Review Comment: ```suggestion "apache-airflow>=2.4.0", ``` ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): + super().__init__() + self.apprise_conn_id = apprise_conn_id + + def get_config_from_conn(self): + conn = self.get_connection(self.apprise_conn_id) + return json.loads(conn.extra_dejson["config"]) + + def set_config_from_conn(self, apprise_obj: apprise.Apprise): + """Set config from connection to apprise object""" + config_object = self.get_config_from_conn() + if isinstance(config_object, list): + for config in config_object: + apprise_obj.add(config["path"], tag=config.get("tag", None)) + elif isinstance(config_object, dict): + apprise_obj.add(config_object["path"], tag=config_object.get("tag", None)) + else: + raise ValueError("only dict / list[dict] type of values are expected") + + def notify( + self, + body: str, + title: str | None = None, + notify_type: NotifyType = NotifyType.INFO, + body_format: NotifyFormat = NotifyFormat.TEXT, + tag: str | Iterable[str] | None = None, + attach: str | None = None, + interpret_escapes: bool | None = None, + config: AppriseConfig | None = None, + ): + r""" + Send message to plugged-in services + + :param body: Specify the message body + :param title: Specify the message title. This field is complete optional + :param notify_type: Specify the message type (default=info). Possible values are "info", + "success", "failure", and "warning" + :param body_format: Specify the input message format (default=text). Possible values are "text", + "html", and "markdown". + :param tag: Specify one or more tags to filter which services to notify + :param attach: Specify one or more file attachment locations + :param interpret_escapes: Enable interpretation of backslash escapes. For example, this would convert + sequences such as \n and \r to their respected ascii new-line and carriage + :param config: Specify one or more configuration + """ + title = title or "" + + apprise_obj = apprise.Apprise() + if config: + apprise_obj.add(config) Review Comment: Hmm, is this a common pattern we support, not using a connection? ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): + super().__init__() + self.apprise_conn_id = apprise_conn_id + + def get_config_from_conn(self): + conn = self.get_connection(self.apprise_conn_id) + return json.loads(conn.extra_dejson["config"]) + + def set_config_from_conn(self, apprise_obj: apprise.Apprise): + """Set config from connection to apprise object""" + config_object = self.get_config_from_conn() + if isinstance(config_object, list): + for config in config_object: + apprise_obj.add(config["path"], tag=config.get("tag", None)) + elif isinstance(config_object, dict): + apprise_obj.add(config_object["path"], tag=config_object.get("tag", None)) + else: + raise ValueError("only dict / list[dict] type of values are expected") Review Comment: ```suggestion raise ValueError(f"Only types of dict or list[dict] are expected in Apprise connections, got {type(config_object)}") ``` Let's be a little more specific. ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications Review Comment: ```suggestion Use Apprise(https://github.com/caronc/apprise) to interact with notification services. The complete list of notification services supported by Apprise can be found at: https://github.com/caronc/apprise/wiki#notification-services ``` nit, plus a better link for supported services ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): + super().__init__() + self.apprise_conn_id = apprise_conn_id + + def get_config_from_conn(self): + conn = self.get_connection(self.apprise_conn_id) + return json.loads(conn.extra_dejson["config"]) + + def set_config_from_conn(self, apprise_obj: apprise.Apprise): + """Set config from connection to apprise object""" + config_object = self.get_config_from_conn() + if isinstance(config_object, list): + for config in config_object: + apprise_obj.add(config["path"], tag=config.get("tag", None)) + elif isinstance(config_object, dict): + apprise_obj.add(config_object["path"], tag=config_object.get("tag", None)) + else: + raise ValueError("only dict / list[dict] type of values are expected") + + def notify( + self, + body: str, + title: str | None = None, + notify_type: NotifyType = NotifyType.INFO, + body_format: NotifyFormat = NotifyFormat.TEXT, + tag: str | Iterable[str] | None = None, + attach: str | None = None, + interpret_escapes: bool | None = None, + config: AppriseConfig | None = None, + ): + r""" + Send message to plugged-in services + + :param body: Specify the message body + :param title: Specify the message title. This field is complete optional + :param notify_type: Specify the message type (default=info). Possible values are "info", + "success", "failure", and "warning" + :param body_format: Specify the input message format (default=text). Possible values are "text", + "html", and "markdown". + :param tag: Specify one or more tags to filter which services to notify + :param attach: Specify one or more file attachment locations Review Comment: If this supports more than 1, is it csv? Let's say. ########## docs/apache-airflow-providers-apprise/index.rst: ########## @@ -0,0 +1,77 @@ + + .. 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. + +``apache-airflow-providers-apprise`` +====================================== + +Content +------- + +.. toctree:: + :maxdepth: 1 + :caption: Guides + + Connection types <connections> + + +.. toctree:: + :maxdepth: 1 + :caption: Commits + + Detailed list of commits <commits> + + +.. toctree:: + :maxdepth: 1 + :caption: Resources + + Python API <_api/airflow/providers/apprise/index> + PyPI Repository <https://pypi.org/project/apache-airflow-providers-apprise/> + Installing from sources <installing-providers-from-sources> + +Package apache-airflow-providers-apprise +----------------------------------------- + +`Apprise <https://github.com/caronc/apprise>`__ + + +Release: 1.0.0 + +Provider package +---------------- + +This is a provider package for ``apprise`` provider. All classes for this provider package +are in ``airflow.providers.apprise`` python package. Review Comment: ```suggestion This is a provider package for ``apprise`` notification library. All classes for this provider package are in ``airflow.providers.apprise`` python module. ``` ########## docs/apache-airflow-providers-apprise/index.rst: ########## @@ -0,0 +1,77 @@ + + .. 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. + +``apache-airflow-providers-apprise`` +====================================== + +Content +------- + +.. toctree:: + :maxdepth: 1 + :caption: Guides + + Connection types <connections> + + +.. toctree:: + :maxdepth: 1 + :caption: Commits + + Detailed list of commits <commits> + + +.. toctree:: + :maxdepth: 1 + :caption: Resources + + Python API <_api/airflow/providers/apprise/index> + PyPI Repository <https://pypi.org/project/apache-airflow-providers-apprise/> + Installing from sources <installing-providers-from-sources> + +Package apache-airflow-providers-apprise +----------------------------------------- + +`Apprise <https://github.com/caronc/apprise>`__ + + +Release: 1.0.0 + +Provider package +---------------- + +This is a provider package for ``apprise`` provider. All classes for this provider package +are in ``airflow.providers.apprise`` python package. + + +Requirements +------------ + +The minimum Apache Airflow version supported by this provider package is ``2.4.0``. + +================== ================== +PIP package Version required +================== ================== +``apache-airflow`` ``>=2.2.0`` Review Comment: ```suggestion ``apache-airflow`` ``>=2.4.0`` ``` ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ Review Comment: ```suggestion :param apprise_conn_id: :ref:`Apprise connection id <howto/connection:apprise>` that has services configured in the `config` field. """ ``` ########## airflow/providers/apprise/hooks/apprise.py: ########## @@ -0,0 +1,127 @@ +# +# 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. +from __future__ import annotations + +import json +from typing import Any, Iterable + +import apprise +from airflow.hooks.base import BaseHook +from apprise import AppriseConfig, NotifyFormat, NotifyType + + +class AppriseHook(BaseHook): + """ + Use Apprise(https://github.com/caronc/apprise) to interact with notification services, the entire list + of notification services supported by apprise can be found here + - https://github.com/caronc/apprise#productivity-based-notifications + """ + + conn_name_attr = "apprise_conn_id" + default_conn_name = "apprise_default" + conn_type = "apprise" + hook_name = "Apprise" + + def __init__(self, apprise_conn_id: str = default_conn_name): + super().__init__() + self.apprise_conn_id = apprise_conn_id + + def get_config_from_conn(self): + conn = self.get_connection(self.apprise_conn_id) + return json.loads(conn.extra_dejson["config"]) + + def set_config_from_conn(self, apprise_obj: apprise.Apprise): + """Set config from connection to apprise object""" + config_object = self.get_config_from_conn() + if isinstance(config_object, list): + for config in config_object: + apprise_obj.add(config["path"], tag=config.get("tag", None)) + elif isinstance(config_object, dict): + apprise_obj.add(config_object["path"], tag=config_object.get("tag", None)) + else: + raise ValueError("only dict / list[dict] type of values are expected") + + def notify( + self, + body: str, + title: str | None = None, + notify_type: NotifyType = NotifyType.INFO, + body_format: NotifyFormat = NotifyFormat.TEXT, + tag: str | Iterable[str] | None = None, + attach: str | None = None, + interpret_escapes: bool | None = None, + config: AppriseConfig | None = None, + ): + r""" + Send message to plugged-in services + + :param body: Specify the message body + :param title: Specify the message title. This field is complete optional + :param notify_type: Specify the message type (default=info). Possible values are "info", + "success", "failure", and "warning" + :param body_format: Specify the input message format (default=text). Possible values are "text", + "html", and "markdown". + :param tag: Specify one or more tags to filter which services to notify + :param attach: Specify one or more file attachment locations + :param interpret_escapes: Enable interpretation of backslash escapes. For example, this would convert + sequences such as \n and \r to their respected ascii new-line and carriage + :param config: Specify one or more configuration + """ + title = title or "" + + apprise_obj = apprise.Apprise() + if config: + apprise_obj.add(config) + else: + self.set_config_from_conn(apprise_obj) + apprise_obj.notify( + body=body, + title=title, + notify_type=notify_type, + body_format=body_format, + tag=tag, + attach=attach, + interpret_escapes=interpret_escapes, + ) + + def get_conn(self) -> None: + pass Review Comment: I wonder if we should raise here instead? ########## docs/apache-airflow-providers-apprise/connections.rst: ########## @@ -0,0 +1,42 @@ + .. 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. + + +Apprise Connection +======================= + +The Apprise connection type enables connection to multiple services to send notifications, the entire list of services supported can be found `here <https://github.com/caronc/apprise#supported-notifications>`_. Review Comment: ```suggestion The Apprise connection type enables connection to multiple services to send notifications. The complete list of services supported can be found on the `Apprise Wiki <https://github.com/caronc/apprise/wiki#notification-services>`_. ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
