turbaszek commented on a change in pull request #9497:
URL: https://github.com/apache/airflow/pull/9497#discussion_r445603754



##########
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:
       What would you say to use some helper methods like:
   ```python
   def _make_single_record(config_option):    
       return f'{config_option.key} = {config_option.value}  # source: 
{config_option.source}\n'
   
   def _make_single_section(config_section):    
       return f'[{config_section.name}]\n{_make_single_record(o) for o in 
config_section.options}'
   
   def _config_to_plain_text(config):
       return '\n'.join(_make_single_section(s) for s in config.sections)
   ```




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