mik-laj commented on a change in pull request #9497:
URL: https://github.com/apache/airflow/pull/9497#discussion_r445609775



##########
File path: airflow/api_connexion/endpoints/config_endpoint.py
##########
@@ -15,12 +15,42 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# TODO(mik-laj): We have to implement it.
-#     Do you want to help? Please look at: 
https://github.com/apache/airflow/issues/8136
+from flask import Response, request
 
+from airflow.api_connexion.schemas.config_schema import Config, ConfigOption, 
ConfigSection, config_schema
+from airflow.configuration import conf
+from airflow.settings import json
 
-def get_config():
+
+def get_config() -> Response:
     """
     Get current configuration.
     """
-    raise NotImplementedError("Not implemented yet.")
+    response_types = ['text/plain', 'application/json']
+    return_type = request.accept_mimetypes.best_match(response_types)
+    conf_dict = conf.as_dict(display_source=True, display_sensitive=True)
+    config = Config(
+        sections=[
+            ConfigSection(
+                name=section,
+                options=[
+                    ConfigOption(key=key, value=value, source=source)
+                    for key, (value, source) in parameters.items()
+                ]
+            )
+            for section, parameters in conf_dict.items()
+        ]
+    )
+    if return_type == 'text/plain':
+        config_text = '\n'.join(
+            f'[{config_section.name}]\n' +
+            ''.join(f'{config_option.key} = {config_option.value}  # source: 
{config_option.source}\n'
+                    for config_option in config_section.options)
+            for config_section in config.sections
+        )

Review comment:
       I do not see the benefits of such gradation.
   
   I think we can split it in a different way.
   ```python
   text_serializer = {
       ''text/plain'': func1 ,
       ''text/plain'': func2 ,
   }
   conf_dict = conf.as_dict()
   config = conf_dict_to_config(conf_dict)
   return_type = request.accept_mimetypes.best_match(response_types)
   if return_type not in serializer:
       return Response(status=406)
   config_text = text_serializer[return_type]
   return Response(config_text, headers={'Content-Type': return_type})  
   ```




----------------------------------------------------------------
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]


Reply via email to