jscheffl commented on code in PR #60410: URL: https://github.com/apache/airflow/pull/60410#discussion_r2784613818
########## contributing-docs/23_provider_hook_migration_to_yaml.rst: ########## @@ -0,0 +1,108 @@ +.. 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. + +Provider hook to yaml Migration Review Comment: nit ```suggestion Provider hook to YAML Migration ``` ########## contributing-docs/23_provider_hook_migration_to_yaml.rst: ########## @@ -0,0 +1,108 @@ +.. 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. + +Provider hook to yaml Migration +=============================== + +We can now, redefine connection form metadata declaratively in ``provider.yaml`` of a provider instead of Python hook code, +reducing dependencies and improving API server startup performance. + +**The outline for this document in GitHub is available at top-right corner button (with 3-dots and 3 lines).** + +Background +---------- + +Previously, connection form UI metadata was defined in hook code of a provider using: + +* ``get_connection_form_widgets()`` - Custom form fields +* ``get_ui_field_behaviour()`` - Field customizations (hidden, relabeling, placeholders) + +These methods required importing heavy dependencies ``flask_appbuilder`` and ``wtforms``, adding unnecessary dependencies +to the API server and having API server to load all the provider hook code just to display a static form. +The new yaml approach allows metadata to be loaded without importing hook classes. + + +YAML Schema Structure +--------------------- + +Connection metadata is defined under ``connection-types`` in ``provider.yaml`` of a provider: + +ui-field-behaviour +~~~~~~~~~~~~~~~~~~ + +Customizations for standard connection fields: + +.. code-block:: yaml + + ui-field-behaviour: + hidden-fields: + - schema + - extra + relabeling: + host: Registry URL + login: Username + placeholders: + port: '5432' + +conn-fields +~~~~~~~~~~~ + +Custom fields stored which will be stored within ``Connection.extra``: Review Comment: nit: Should we add a link to form definition for Dag params? Like https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/params.html#use-params-to-provide-a-trigger-ui-form - to describe the options for fields supported? ########## airflow-core/src/airflow/provider.yaml.schema.json: ########## @@ -350,6 +350,111 @@ "hook-class-name": { "description": "Hook class name that implements the connection type", "type": "string" + }, + "ui-field-behaviour": { + "description": "Customizations for standard connection form fields", + "type": "object", + "properties": { + "hidden-fields": { + "description": "List of standard fields to hide in the UI", + "type": "array", + "items": { + "type": "string", + "enum": ["description", "host", "port", "login", "password", "schema", "extra"] + }, + "default": [] + }, + "relabeling": { + "description": "Map of field names to custom labels", + "type": "object", + "additionalProperties": { + "type": "string" + }, + "default": {} + }, + "placeholders": { + "description": "Map of field names to placeholder text", + "type": "object", + "additionalProperties": { + "type": "string" + }, + "default": {} + } + }, + "additionalProperties": false + }, + "conn-fields": { + "description": "Custom connection fields stored in Connection.extra JSON", + "type": "object", + "additionalProperties": { + "type": "object", + "properties": { + "label": { + "type": "string", + "description": "Display label for the field" + }, + "description": { + "type": "string", + "description": "Help text for the field" + }, + "sensitive": { + "type": "boolean", + "default": false, + "description": "Whether to mask field value (like password fields)" + }, Review Comment: ^^^any response / opinion to this? -- 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]
