kbendick commented on code in PR #23704: URL: https://github.com/apache/airflow/pull/23704#discussion_r874045176
########## airflow/providers/tabular/hooks/tabular.py: ########## @@ -0,0 +1,106 @@ +# 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 typing import Any, Dict, Tuple + +import requests +from requests import HTTPError + +from airflow.hooks.base import BaseHook + +DEFAULT_TABULAR_URL = "https://api.tabulardata.io/ws/v1" + +TOKENS_ENDPOINT = "warehouses/tokens" + + +class TabularHook(BaseHook): + """ + This hook acts as a base hook for tabular services. It offers the ability to generate temporary, + short-lived session tokens to use within Airflow submitted jobs. + + :param tabular_conn_id: The :ref:`Tabular connection id<howto/connection:tabular>` + which refers to the information to connect to the Tabular OAuth service. + """ + + conn_name_attr = 'tabular_conn_id' + default_conn_name = "tabular_default" + conn_type = "tabular" + hook_name = "Tabular" + + @staticmethod + def get_connection_form_widgets() -> Dict[str, Any]: + """Returns connection widgets to add to connection form""" + from flask_appbuilder.fieldwidgets import BS3TextFieldWidget + from flask_babel import lazy_gettext + from wtforms import StringField + + return { + "extra__tabular__baseUrl": StringField( + lazy_gettext("Tabular Base URL"), widget=BS3TextFieldWidget() + ), + } + + @staticmethod + def get_ui_field_behaviour() -> Dict[str, Any]: + """Returns custom field behaviour""" + return { + "hidden_fields": ["schema", "port", "host"], + "relabeling": { + "login": "Tabular Client ID", + "password": "Tabular Client Secret", + }, + "placeholders": { + "login": "client_id (token credentials auth)", + "password": "secret (token credentials auth)", + "extra__tabular__baseUrl": DEFAULT_TABULAR_URL, + }, + } + + def __init__(self, tabular_conn_id: str = default_conn_name) -> None: + super().__init__() + self.conn_id = tabular_conn_id + + def test_connection(self) -> Tuple[bool, str]: + """Test dbt Cloud connection.""" + try: + self.get_token() + return True, "Successfully fetched token from Tabular" + except HTTPError as e: + return False, f"HTTP Error: {e}" + except Exception as e: + return False, str(e) + + def get_conn(self) -> str: + """ + Obtain a warehouse token via a client_id and client_secret. + + This could also be used with an AWS managed identity in theory. Review Comment: Nit: I would leave the note about being used with an AWS managed identity off until such a time, if ever, that there's an example of that. The first sentence alone seems sufficient for that. ########## docs/apache-airflow-providers-tabular/connections.rst: ########## @@ -0,0 +1,41 @@ + .. 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. + +.. _howto/connection:tabular: + +Tabular Connection +================== + +The Tabular connection type enables connection to Tabular to request a short lived token to access the Apache Iceberg tables. This token can be injected as an environment variable, to be used with Trino, Spark, Flink or your favorite query engine that supports Apache Iceberg. + +Default Connection IDs +---------------------- + +Tabular Hook uses the parameter ``tabular_conn_id`` for Connection IDs and the value of the parameter as ``tabular_default`` by default. You can create multiple connections in case you want to switch between environments. + +Configuring the Connection +-------------------------- +Client ID + The Client ID from Tabular + +Client Secret + The Client Secret from Tabular + +Extra (optional, connection parameters) + Specify the extra parameters (as json dictionary) that can be used in Trino connection. The following parameters out of the standard python parameters are supported: Review Comment: Nit: Is this supposed to say `Trino` connection or `Tabular` connection? ########## airflow/utils/db.py: ########## @@ -593,6 +593,14 @@ def create_default_connections(session: Session = NEW_SESSION): ), session, ) + merge_conn( + Connection( + conn_id="tabular_default", + conn_type="tabular", + extra='{"extra__tabular__signerUrl": "https://api.tabulardata.io/ws/v1"}' Review Comment: In the form widgets we have `extra__tabular__baseUrl`. Is this an additional user enterable field that we should add to the form widget as well? -- 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]
