You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/06/25 14:20:09 UTC

[GitHub] [airflow] turbaszek commented on a change in pull request #9497: Add read-only Config endpoint

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



##########
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
+        )
+        return Response(config_text, headers={'Content-Type': return_type})

Review comment:
       What would you say to use the approach we used in config command?
   ```python
       with io.StringIO() as output:
           conf.write(output)
           code = output.getvalue()
   ```
   then the `code` looks like:
   ```
   [core]
   dags_folder = /files/dags
   hostname_callable = socket.getfqdn
   default_timezone = utc
   ...
   ```
   I think it's simpler and requires less code. Also, if we use it then the L32-43 can be moved under `elif return_type == 'application/json':`
   WDYT? 




----------------------------------------------------------------
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:
users@infra.apache.org